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 15package e2e 16 17import "testing" 18 19func TestCtlV3Defrag(t *testing.T) { testCtl(t, defragTest) } 20 21func maintenanceInitKeys(cx ctlCtx) { 22 var kvs = []kv{{"key", "val1"}, {"key", "val2"}, {"key", "val3"}} 23 for i := range kvs { 24 if err := ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil { 25 cx.t.Fatal(err) 26 } 27 } 28} 29 30func defragTest(cx ctlCtx) { 31 maintenanceInitKeys(cx) 32 33 if err := ctlV3Compact(cx, 4, cx.compactPhysical); err != nil { 34 cx.t.Fatal(err) 35 } 36 37 if err := ctlV3Defrag(cx); err != nil { 38 cx.t.Fatalf("defragTest ctlV3Defrag error (%v)", err) 39 } 40} 41 42func ctlV3Defrag(cx ctlCtx) error { 43 cmdArgs := append(cx.PrefixArgs(), "defrag") 44 lines := make([]string, cx.epc.cfg.clusterSize) 45 for i := range lines { 46 lines[i] = "Finished defragmenting etcd member" 47 } 48 return spawnWithExpects(cmdArgs, lines...) 49} 50