github.com/jpetazzo/etcd@v0.2.1-0.20140113055439-97f1363afac5/tests/functional/v1_migration_test.go (about) 1 package test 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 "os" 8 "os/exec" 9 "path/filepath" 10 "testing" 11 "time" 12 13 "github.com/coreos/etcd/tests" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 // Ensure that we can start a v2 node from the log of a v1 node. 18 func TestV1SoloMigration(t *testing.T) { 19 path, _ := ioutil.TempDir("", "etcd-") 20 os.MkdirAll(path, 0777) 21 defer os.RemoveAll(path) 22 23 nodepath := filepath.Join(path, "node0") 24 fixturepath, _ := filepath.Abs("../fixtures/v1.solo/node0") 25 fmt.Println("DATA_DIR =", nodepath) 26 27 // Copy over fixture files. 28 c := exec.Command("cp", "-rf", fixturepath, nodepath) 29 if out, err := c.CombinedOutput(); err != nil { 30 fmt.Println(">>>>>>\n", string(out), "<<<<<<") 31 panic("Fixture initialization error:" + err.Error()) 32 } 33 34 procAttr := new(os.ProcAttr) 35 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 36 37 args := []string{"etcd", fmt.Sprintf("-data-dir=%s", nodepath)} 38 args = append(args, "-addr", "127.0.0.1:4001") 39 args = append(args, "-peer-addr", "127.0.0.1:7001") 40 process, err := os.StartProcess(EtcdBinPath, args, procAttr) 41 if err != nil { 42 t.Fatal("start process failed:" + err.Error()) 43 return 44 } 45 defer process.Kill() 46 time.Sleep(time.Second) 47 48 // Ensure deleted message is removed. 49 resp, err := tests.Get("http://localhost:4001/v2/keys/message") 50 tests.ReadBody(resp) 51 assert.Nil(t, err, "") 52 assert.Equal(t, resp.StatusCode, 200, "") 53 } 54 55 // Ensure that we can start a v2 cluster from the logs of a v1 cluster. 56 func TestV1ClusterMigration(t *testing.T) { 57 path, _ := ioutil.TempDir("", "etcd-") 58 os.RemoveAll(path) 59 defer os.RemoveAll(path) 60 61 nodes := []string{"node0", "node2"} 62 for i, node := range nodes { 63 nodepath := filepath.Join(path, node) 64 fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1.cluster/", node)) 65 fmt.Println("FIXPATH =", fixturepath) 66 fmt.Println("NODEPATH =", nodepath) 67 os.MkdirAll(filepath.Dir(nodepath), 0777) 68 69 // Copy over fixture files. 70 c := exec.Command("cp", "-rf", fixturepath, nodepath) 71 if out, err := c.CombinedOutput(); err != nil { 72 fmt.Println(">>>>>>\n", string(out), "<<<<<<") 73 panic("Fixture initialization error:" + err.Error()) 74 } 75 76 procAttr := new(os.ProcAttr) 77 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 78 79 args := []string{"etcd", fmt.Sprintf("-data-dir=%s", nodepath)} 80 args = append(args, "-addr", fmt.Sprintf("127.0.0.1:%d", 4001+i)) 81 args = append(args, "-peer-addr", fmt.Sprintf("127.0.0.1:%d", 7001+i)) 82 process, err := os.StartProcess(EtcdBinPath, args, procAttr) 83 if err != nil { 84 t.Fatal("start process failed:" + err.Error()) 85 return 86 } 87 defer process.Kill() 88 time.Sleep(time.Second) 89 } 90 91 // Ensure deleted message is removed. 92 resp, err := tests.Get("http://localhost:4001/v2/keys/message") 93 body := tests.ReadBody(resp) 94 assert.Nil(t, err, "") 95 assert.Equal(t, resp.StatusCode, http.StatusNotFound) 96 assert.Equal(t, string(body), `{"errorCode":100,"message":"Key not found","cause":"/message","index":11}`+"\n") 97 98 // Ensure TTL'd message is removed. 99 resp, err = tests.Get("http://localhost:4001/v2/keys/foo") 100 body = tests.ReadBody(resp) 101 assert.Nil(t, err, "") 102 assert.Equal(t, resp.StatusCode, 200, "") 103 assert.Equal(t, string(body), `{"action":"get","node":{"key":"/foo","value":"one","modifiedIndex":9,"createdIndex":9}}`) 104 }