Browse Source

Migration test.

Ben Johnson 12 năm trước cách đây
mục cha
commit
02abbb6a6c

+ 2 - 0
release_version.go

@@ -0,0 +1,2 @@
+package main
+const releaseVersion = "v0.1.2-33-g1a2a9d6"

+ 14 - 0
tests/fixtures/v1/README

@@ -0,0 +1,14 @@
+README
+
+The scripts in this directory should be run from the project root:
+
+$ cd $GOPATH/src/github.com/coreos/etcd
+$ tests/fixtures/v1/complete.1.sh
+
+Scripts with numbers should be run in separate terminal windows (in order):
+
+$ tests/fixtures/v1/complete.1.sh
+$ tests/fixtures/v1/complete.2.sh
+$ tests/fixtures/v1/complete.3.sh
+
+The resulting server state data can be found in tmp/node0.

+ 4 - 0
tests/fixtures/v1/complete.1.sh

@@ -0,0 +1,4 @@
+#!/bin/sh
+
+./build
+./etcd -d tmp/node0 -n node0

+ 3 - 0
tests/fixtures/v1/complete.2.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+./etcd -s 127.0.0.1:7002 -c 127.0.0.1:4002 -C 127.0.0.1:7001 -d tmp/node2 -n node2

+ 3 - 0
tests/fixtures/v1/complete.3.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+./etcd -s 127.0.0.1:7003 -c 127.0.0.1:4003 -C 127.0.0.1:7001 -d tmp/node3 -n node3

+ 12 - 0
tests/fixtures/v1/complete.4.sh

@@ -0,0 +1,12 @@
+#!/bin/sh
+
+curl -L http://127.0.0.1:4001/v1/keys/message -d value="Hello world"
+curl -L http://127.0.0.1:4001/v1/keys/message -d value="Hello etcd"
+curl -L http://127.0.0.1:4001/v1/keys/message -X DELETE
+curl -L http://127.0.0.1:4001/v1/keys/foo -d value=bar -d ttl=5
+curl -L http://127.0.0.1:4001/v1/keys/foo -d value=one
+curl -L http://127.0.0.1:4001/v1/keys/foo -d prevValue=two -d value=three
+curl -L http://127.0.0.1:4001/v1/keys/foo -d prevValue=one -d value=two
+curl -L http://127.0.0.1:4001/v1/keys/bar -d prevValue= -d value=four
+curl -L http://127.0.0.1:4001/v1/keys/bar -d prevValue= -d value=five
+curl -X DELETE http://127.0.0.1:4001/v1/keys/_etcd/machines

+ 1 - 0
tests/fixtures/v1/complete/conf

@@ -0,0 +1 @@
+{"commitIndex":13,"peers":[]}

+ 18 - 0
tests/fixtures/v1/complete/info

@@ -0,0 +1,18 @@
+{
+ "name": "node0",
+ "raftURL": "http://127.0.0.1:7001",
+ "etcdURL": "http://127.0.0.1:4001",
+ "webURL": "",
+ "raftListenHost": "127.0.0.1:7001",
+ "etcdListenHost": "127.0.0.1:4001",
+ "raftTLS": {
+  "CertFile": "",
+  "KeyFile": "",
+  "CAFile": ""
+ },
+ "etcdTLS": {
+  "CertFile": "",
+  "KeyFile": "",
+  "CAFile": ""
+ }
+}

BIN
tests/fixtures/v1/complete/log


+ 51 - 0
tests/functional/v1_migration_test.go

@@ -0,0 +1,51 @@
+package test
+
+import (
+	"fmt"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"testing"
+	"time"
+
+	"github.com/coreos/etcd/tests"
+	"github.com/stretchr/testify/assert"
+)
+
+// Ensure that we can start a v2 node from the log of a v1 node.
+func TestV1Migration(t *testing.T) {
+	path, _ := ioutil.TempDir("", "etcd-")
+	os.RemoveAll(path)
+	defer os.RemoveAll(path)
+
+	// Copy over fixture files.
+	if err := exec.Command("cp", "-r", "../fixtures/v1/complete", path).Run(); err != nil {
+		panic("Fixture initialization error")
+	}
+
+	procAttr := new(os.ProcAttr)
+	procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
+	args := []string{"etcd", fmt.Sprintf("-d=%s", path)}
+
+	process, err := os.StartProcess(EtcdBinPath, args, procAttr)
+	if err != nil {
+		t.Fatal("start process failed:" + err.Error())
+		return
+	}
+	defer process.Kill()
+	time.Sleep(time.Second)
+
+
+	// Ensure deleted message is removed.
+	resp, err := tests.Get("http://localhost:4001/v2/keys/message")
+	tests.ReadBody(resp)
+	assert.Nil(t, err, "")
+	assert.Equal(t, resp.StatusCode, 404, "")
+
+	// Ensure TTL'd message is removed.
+	resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
+	tests.ReadBody(resp)
+	assert.Nil(t, err, "")
+	assert.Equal(t, resp.StatusCode, 404, "")
+}
+