|
|
@@ -11,7 +11,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// This test creates a single node and then set a value to it to trigger snapshot
|
|
|
-func TestSimpleSnapshot(t *testing.T) {
|
|
|
+func TestSnapshot(t *testing.T) {
|
|
|
procAttr := new(os.ProcAttr)
|
|
|
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
|
|
args := []string{"etcd", "-name=node1", "-data-dir=/tmp/node1", "-snapshot=true", "-snapshot-count=500"}
|
|
|
@@ -93,3 +93,57 @@ func TestSimpleSnapshot(t *testing.T) {
|
|
|
t.Fatal("wrong name of snapshot :", snapshots[0].Name())
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// TestSnapshotRestart tests etcd restarts with snapshot file
|
|
|
+func TestSnapshotRestart(t *testing.T) {
|
|
|
+ procAttr := new(os.ProcAttr)
|
|
|
+ procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
|
|
+ args := []string{"etcd", "-name=node1", "-data-dir=/tmp/node1", "-snapshot=true", "-snapshot-count=500"}
|
|
|
+
|
|
|
+ process, err := os.StartProcess(EtcdBinPath, append(args, "-f"), procAttr)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal("start process failed:" + err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ time.Sleep(time.Second)
|
|
|
+
|
|
|
+ c := etcd.NewClient(nil)
|
|
|
+
|
|
|
+ c.SyncCluster()
|
|
|
+ // issue first 501 commands
|
|
|
+ for i := 0; i < 501; i++ {
|
|
|
+ result, err := c.Set("foo", "bar", 100)
|
|
|
+ node := result.Node
|
|
|
+
|
|
|
+ if err != nil || node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 {
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ t.Fatalf("Set failed with %s %s %v", node.Key, node.Value, node.TTL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // wait for a snapshot interval
|
|
|
+ time.Sleep(3 * time.Second)
|
|
|
+
|
|
|
+ _, err = ioutil.ReadDir("/tmp/node1/snapshot")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal("list snapshot failed:" + err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ process.Kill()
|
|
|
+
|
|
|
+ process, err = os.StartProcess(EtcdBinPath, args, procAttr)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal("start process failed:" + err.Error())
|
|
|
+ }
|
|
|
+ defer process.Kill()
|
|
|
+
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+
|
|
|
+ _, err = c.Set("foo", "bar", 100)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|