ctl_v3_defrag_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 maintenanceInitKeys(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. }
  25. func defragTest(cx ctlCtx) {
  26. maintenanceInitKeys(cx)
  27. if err := ctlV3Compact(cx, 4, cx.compactPhysical); err != nil {
  28. cx.t.Fatal(err)
  29. }
  30. if err := ctlV3Defrag(cx); err != nil {
  31. cx.t.Fatalf("defragTest ctlV3Defrag error (%v)", err)
  32. }
  33. }
  34. func ctlV3Defrag(cx ctlCtx) error {
  35. cmdArgs := append(cx.PrefixArgs(), "defrag")
  36. lines := make([]string, cx.epc.cfg.clusterSize)
  37. for i := range lines {
  38. lines[i] = "Finished defragmenting etcd member"
  39. }
  40. return spawnWithExpects(cmdArgs, lines...)
  41. }