Skip to content

Commit

Permalink
clientv3/integration: add TestV3PutLargeRequests to integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fanminshi committed May 24, 2017
1 parent 6fc5fde commit b4e1def
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"github.com/coreos/etcd/client"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/embed"
"github.com/coreos/etcd/etcdserver"
"github.com/coreos/etcd/etcdserver/api/v2http"
"github.com/coreos/etcd/etcdserver/api/v3client"
Expand All @@ -60,6 +61,8 @@ const (
basePort = 21000
UrlScheme = "unix"
UrlSchemeTLS = "unixs"

defaultMaxRequestSize
)

var (
Expand Down Expand Up @@ -93,6 +96,7 @@ type ClusterConfig struct {
DiscoveryURL string
UseGRPC bool
QuotaBackendBytes int64
MaxRequestBytes uint
}

type cluster struct {
Expand Down Expand Up @@ -224,6 +228,7 @@ func (c *cluster) mustNewMember(t *testing.T) *member {
peerTLS: c.cfg.PeerTLS,
clientTLS: c.cfg.ClientTLS,
quotaBackendBytes: c.cfg.QuotaBackendBytes,
maxRequestBytes: c.cfg.MaxRequestBytes,
})
m.DiscoveryURL = c.cfg.DiscoveryURL
if c.cfg.UseGRPC {
Expand Down Expand Up @@ -490,6 +495,7 @@ type memberConfig struct {
peerTLS *transport.TLSInfo
clientTLS *transport.TLSInfo
quotaBackendBytes int64
maxRequestBytes uint
}

// mustNewMember return an inited member with the given name. If peerTLS is
Expand Down Expand Up @@ -537,6 +543,10 @@ func mustNewMember(t *testing.T, mcfg memberConfig) *member {
m.ElectionTicks = electionTicks
m.TickMs = uint(tickDuration / time.Millisecond)
m.QuotaBackendBytes = mcfg.quotaBackendBytes
m.MaxRequestBytes = mcfg.maxRequestBytes
if m.MaxRequestBytes == 0 {
m.MaxRequestBytes = embed.DefaultMaxRequestBytes
}
m.AuthToken = "simple" // for the purpose of integration testing, simple token is enough
return m
}
Expand Down
28 changes: 28 additions & 0 deletions integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,34 @@ func TestGRPCStreamRequireLeader(t *testing.T) {
}
}

// TestV3PutLargeRequests ensures that configurable MaxRequestBytes works as intended.
func TestV3PutLargeRequests(t *testing.T) {
defer testutil.AfterTest(t)
tests := []struct {
key string
maxRequestBytes uint
valueSize int
expectError bool
}{
// don't set to 0. use 0 as the default.
{"foo", 1, 1024, true},
{"foo", 10 * 1024 * 1024, 9 * 1024 * 1024, false},
{"foo", 10 * 1024 * 1024, 10 * 1024 * 1024, true},
{"foo", 10 * 1024 * 1024, 11 * 1024 * 1024, true},
}
for _, test := range tests {
clus := NewClusterV3(t, &ClusterConfig{Size: 1, MaxRequestBytes: test.maxRequestBytes})
kvcli := toGRPC(clus.Client(0)).KV
reqput := &pb.PutRequest{Key: []byte(test.key), Value: make([]byte, test.valueSize)}
_, err := kvcli.Put(context.TODO(), reqput)
hasError := (err != nil)
if hasError != test.expectError {
t.Fatalf("expected error? %v, but got %v case:[%+v] \n", test.expectError, hasError, test)
}
clus.Terminate(t)
}
}

func eqErrGRPC(err1 error, err2 error) bool {
return !(err1 == nil && err2 != nil) || err1.Error() == err2.Error()
}
Expand Down

0 comments on commit b4e1def

Please sign in to comment.