Skip to content

Commit

Permalink
clientv3/integration: test custom MaxRequestBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
fanminshi committed May 23, 2017
1 parent 43da079 commit 1e16937
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions clientv3/integration/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,30 @@ func TestKVGetResetLoneEndpoint(t *testing.T) {
case <-donec:
}
}

// TestKVPutLargeRequests ensures that custom MaxRequestBytes works as intended.
func TestKVPutLargeRequests(t *testing.T) {
defer testutil.AfterTest(t)
tests := []struct {
key string
MaxRequestBytes uint
valueSize int
expectError bool
}{
{"foo", 0, 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 := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1, MaxRequestBytes: test.MaxRequestBytes})
cli := clus.Client(0)
valueBytes := make([]byte, test.valueSize)
_, err := cli.Put(context.TODO(), test.key, string(valueBytes))
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)
}
}
4 changes: 4 additions & 0 deletions integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type ClusterConfig struct {
DiscoveryURL string
UseGRPC bool
QuotaBackendBytes int64
MaxRequestBytes uint
}

type cluster struct {
Expand Down Expand Up @@ -224,6 +225,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 +492,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 +540,7 @@ 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
m.AuthToken = "simple" // for the purpose of integration testing, simple token is enough
return m
}
Expand Down

0 comments on commit 1e16937

Please sign in to comment.