ctl_v3_make_mirror_test.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 TestCtlV3MakeMirrorModifyDestPrefix(t *testing.T) { testCtl(t, makeMirrorModifyDestPrefixTest) }
  22. func TestCtlV3MakeMirrorNoDestPrefix(t *testing.T) { testCtl(t, makeMirrorNoDestPrefixTest) }
  23. func makeMirrorTest(cx ctlCtx) {
  24. // set up another cluster to mirror with
  25. cfg := configAutoTLS
  26. cfg.clusterSize = 1
  27. cfg.basePort = 10000
  28. cx2 := ctlCtx{
  29. t: cx.t,
  30. cfg: cfg,
  31. dialTimeout: 7 * time.Second,
  32. }
  33. epc, err := newEtcdProcessCluster(&cx2.cfg)
  34. if err != nil {
  35. cx.t.Fatalf("could not start etcd process cluster (%v)", err)
  36. }
  37. cx2.epc = epc
  38. defer func() {
  39. if err = cx2.epc.Close(); err != nil {
  40. cx.t.Fatalf("error closing etcd processes (%v)", err)
  41. }
  42. }()
  43. cmdArgs := append(cx.PrefixArgs(), "make-mirror", fmt.Sprintf("localhost:%d", cfg.basePort))
  44. proc, err := spawnCmd(cmdArgs)
  45. if err != nil {
  46. cx.t.Fatal(err)
  47. }
  48. defer func() {
  49. err = proc.Stop()
  50. if err != nil {
  51. cx.t.Fatal(err)
  52. }
  53. }()
  54. var kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
  55. for i := range kvs {
  56. if err = ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  57. cx.t.Fatal(err)
  58. }
  59. }
  60. if err = ctlV3Get(cx, []string{"key", "--prefix"}, kvs...); err != nil {
  61. cx.t.Fatal(err)
  62. }
  63. if err = ctlV3Watch(cx2, []string{"key", "--rev", "1", "--prefix"}, kvs...); err != nil {
  64. cx.t.Fatal(err)
  65. }
  66. }
  67. func makeMirrorModifyDestPrefixTest(cx ctlCtx) {
  68. // set up another cluster to mirror with
  69. mirrorcfg := configAutoTLS
  70. mirrorcfg.clusterSize = 1
  71. mirrorcfg.basePort = 10000
  72. mirrorctx := ctlCtx{
  73. t: cx.t,
  74. cfg: mirrorcfg,
  75. dialTimeout: 7 * time.Second,
  76. }
  77. mirrorepc, err := newEtcdProcessCluster(&mirrorctx.cfg)
  78. if err != nil {
  79. cx.t.Fatalf("could not start etcd process cluster (%v)", err)
  80. }
  81. mirrorctx.epc = mirrorepc
  82. defer func() {
  83. if err = mirrorctx.epc.Close(); err != nil {
  84. cx.t.Fatalf("error closing etcd processes (%v)", err)
  85. }
  86. }()
  87. cmdArgs := append(cx.PrefixArgs(), "make-mirror", "--prefix", "o_", "--dest-prefix", "d_", fmt.Sprintf("localhost:%d", mirrorcfg.basePort))
  88. proc, err := spawnCmd(cmdArgs)
  89. if err != nil {
  90. cx.t.Fatal(err)
  91. }
  92. defer func() {
  93. err = proc.Stop()
  94. if err != nil {
  95. cx.t.Fatal(err)
  96. }
  97. }()
  98. var kvs = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
  99. for i := range kvs {
  100. if err = ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  101. cx.t.Fatal(err)
  102. }
  103. }
  104. if err = ctlV3Get(cx, []string{"o_", "--prefix"}, kvs...); err != nil {
  105. cx.t.Fatal(err)
  106. }
  107. var kvs2 = []kv{{"d_key1", "val1"}, {"d_key2", "val2"}, {"d_key3", "val3"}}
  108. if err = ctlV3Watch(mirrorctx, []string{"d_", "--rev", "1", "--prefix"}, kvs2...); err != nil {
  109. cx.t.Fatal(err)
  110. }
  111. }
  112. func makeMirrorNoDestPrefixTest(cx ctlCtx) {
  113. // set up another cluster to mirror with
  114. mirrorcfg := configAutoTLS
  115. mirrorcfg.clusterSize = 1
  116. mirrorcfg.basePort = 10000
  117. mirrorctx := ctlCtx{
  118. t: cx.t,
  119. cfg: mirrorcfg,
  120. dialTimeout: 7 * time.Second,
  121. }
  122. mirrorepc, err := newEtcdProcessCluster(&mirrorctx.cfg)
  123. if err != nil {
  124. cx.t.Fatalf("could not start etcd process cluster (%v)", err)
  125. }
  126. mirrorctx.epc = mirrorepc
  127. defer func() {
  128. if err = mirrorctx.epc.Close(); err != nil {
  129. cx.t.Fatalf("error closing etcd processes (%v)", err)
  130. }
  131. }()
  132. cmdArgs := append(cx.PrefixArgs(), "make-mirror", "--prefix", "o_", "--no-dest-prefix", fmt.Sprintf("localhost:%d", mirrorcfg.basePort))
  133. proc, err := spawnCmd(cmdArgs)
  134. if err != nil {
  135. cx.t.Fatal(err)
  136. }
  137. defer func() {
  138. err = proc.Stop()
  139. if err != nil {
  140. cx.t.Fatal(err)
  141. }
  142. }()
  143. var kvs = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
  144. for i := range kvs {
  145. if err = ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
  146. cx.t.Fatal(err)
  147. }
  148. }
  149. if err = ctlV3Get(cx, []string{"o_", "--prefix"}, kvs...); err != nil {
  150. cx.t.Fatal(err)
  151. }
  152. var kvs2 = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
  153. if err = ctlV3Watch(mirrorctx, []string{"key", "--rev", "1", "--prefix"}, kvs2...); err != nil {
  154. cx.t.Fatal(err)
  155. }
  156. }