ctl_v3_make_mirror_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 (
  16. "fmt"
  17. "testing"
  18. "time"
  19. )
  20. func TestCtlV3MakeMirror(t *testing.T) { testCtl(t, makeMirrorTest) }
  21. func makeMirrorTest(cx ctlCtx) {
  22. // set up another cluster to mirror with
  23. cfg := configAutoTLS
  24. cfg.clusterSize = 1
  25. cfg.basePort = 10000
  26. cx2 := ctlCtx{
  27. t: cx.t,
  28. cfg: cfg,
  29. dialTimeout: 7 * time.Second,
  30. }
  31. epc, err := newEtcdProcessCluster(&cx2.cfg)
  32. if err != nil {
  33. cx.t.Fatalf("could not start etcd process cluster (%v)", err)
  34. }
  35. cx2.epc = epc
  36. defer func() {
  37. if err = cx2.epc.Close(); err != nil {
  38. cx.t.Fatalf("error closing etcd processes (%v)", err)
  39. }
  40. }()
  41. cmdArgs := append(cx.PrefixArgs(), "make-mirror", fmt.Sprintf("localhost:%d", cfg.basePort))
  42. proc, err := spawnCmd(cmdArgs)
  43. if err != nil {
  44. cx.t.Fatal(err)
  45. }
  46. defer func() {
  47. err = proc.Stop()
  48. if err != nil {
  49. cx.t.Fatal(err)
  50. }
  51. }()
  52. var kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
  53. for i := range kvs {
  54. if err = ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  55. cx.t.Fatal(err)
  56. }
  57. }
  58. if err = ctlV3Get(cx, []string{"key", "--prefix"}, kvs...); err != nil {
  59. cx.t.Fatal(err)
  60. }
  61. if err = ctlV3Watch(cx2, []string{"key", "--rev", "1", "--prefix"}, kvs...); err != nil {
  62. cx.t.Fatal(err)
  63. }
  64. }