|
@@ -444,6 +444,110 @@ func TestKillRandom(t *testing.T) {
|
|
|
stop <- true
|
|
stop <- true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// remove the node and node rejoin with previous log
|
|
|
|
|
+func TestRemoveNode(t *testing.T) {
|
|
|
|
|
+ procAttr := new(os.ProcAttr)
|
|
|
|
|
+ procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
|
|
|
|
+
|
|
|
|
|
+ clusterSize := 3
|
|
|
|
|
+ argGroup, etcds, _ := test.CreateCluster(clusterSize, procAttr, false)
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+
|
|
|
|
|
+ c := etcd.NewClient()
|
|
|
|
|
+
|
|
|
|
|
+ c.SyncCluster()
|
|
|
|
|
+
|
|
|
|
|
+ rmReq, _ := http.NewRequest("DELETE", "http://127.0.0.1:7001/remove/node3", nil)
|
|
|
|
|
+
|
|
|
|
|
+ client := &http.Client{}
|
|
|
|
|
+ for i := 0; i < 2; i++ {
|
|
|
|
|
+ for i := 0; i < 2; i++ {
|
|
|
|
|
+ client.Do(rmReq)
|
|
|
|
|
+
|
|
|
|
|
+ etcds[2].Wait()
|
|
|
|
|
+
|
|
|
|
|
+ resp, err := c.Get("_etcd/machines")
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(resp) != 2 {
|
|
|
|
|
+ t.Fatal("cannot remove machine")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if i == 1 {
|
|
|
|
|
+ // rejoin with log
|
|
|
|
|
+ etcds[2], err = os.StartProcess("etcd", argGroup[2], procAttr)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // rejoin without log
|
|
|
|
|
+ etcds[2], err = os.StartProcess("etcd", append(argGroup[2], "-f"), procAttr)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+
|
|
|
|
|
+ resp, err = c.Get("_etcd/machines")
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(resp) != 3 {
|
|
|
|
|
+ t.Fatal("add machine fails")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // first kill the node, then remove it, then add it back
|
|
|
|
|
+ for i := 0; i < 2; i++ {
|
|
|
|
|
+ etcds[2].Kill()
|
|
|
|
|
+ etcds[2].Wait()
|
|
|
|
|
+
|
|
|
|
|
+ client.Do(rmReq)
|
|
|
|
|
+
|
|
|
|
|
+ resp, err := c.Get("_etcd/machines")
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(resp) != 2 {
|
|
|
|
|
+ t.Fatal("cannot remove machine")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if i == 1 {
|
|
|
|
|
+ // rejoin with log
|
|
|
|
|
+ etcds[2], err = os.StartProcess("etcd", append(argGroup[2]), procAttr)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // rejoin without log
|
|
|
|
|
+ etcds[2], err = os.StartProcess("etcd", append(argGroup[2], "-f"), procAttr)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+
|
|
|
|
|
+ resp, err = c.Get("_etcd/machines")
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(resp) != 3 {
|
|
|
|
|
+ t.Fatal("add machine fails")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ test.DestroyCluster(etcds)
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func templateBenchmarkEtcdDirectCall(b *testing.B, tls bool) {
|
|
func templateBenchmarkEtcdDirectCall(b *testing.B, tls bool) {
|
|
|
procAttr := new(os.ProcAttr)
|
|
procAttr := new(os.ProcAttr)
|
|
|
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
|
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|