ctl_v3_defrag_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import "testing"
  16. func TestCtlV3Defrag(t *testing.T) { testCtl(t, defragTest) }
  17. func defragTest(cx ctlCtx) {
  18. var kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}}
  19. for i := range kvs {
  20. if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  21. cx.t.Fatal(err)
  22. }
  23. }
  24. if err := ctlV3Compact(cx, 4, cx.compactPhysical); err != nil {
  25. cx.t.Fatal(err)
  26. }
  27. if err := ctlV3Defrag(cx); err != nil {
  28. cx.t.Fatalf("defragTest ctlV3Defrag error (%v)", err)
  29. }
  30. }
  31. func ctlV3Defrag(cx ctlCtx) error {
  32. cmdArgs := append(cx.PrefixArgs(), "defrag")
  33. lines := make([]string, cx.epc.cfg.clusterSize)
  34. for i := range lines {
  35. lines[i] = "Finished defragmenting etcd member"
  36. }
  37. return spawnWithExpects(cmdArgs, lines...)
  38. }