mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge branch '0.2' of https://github.com/coreos/etcd into migration-test
This commit is contained in:
88
tests/functional/simple_snapshot_test.go
Normal file
88
tests/functional/simple_snapshot_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
)
|
||||
|
||||
// This test creates a single node and then set a value to it to trigger snapshot
|
||||
func TestSimpleSnapshot(t *testing.T) {
|
||||
procAttr := new(os.ProcAttr)
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
args := []string{"etcd", "-n=node1", "-d=/tmp/node1", "-snapshot=true", "-snapshotCount=500"}
|
||||
|
||||
process, err := os.StartProcess(EtcdBinPath, append(args, "-f"), procAttr)
|
||||
if err != nil {
|
||||
t.Fatal("start process failed:" + err.Error())
|
||||
}
|
||||
defer process.Kill()
|
||||
|
||||
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)
|
||||
|
||||
if err != nil || result.Key != "/foo" || result.Value != "bar" || result.TTL < 95 {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Fatalf("Set failed with %s %s %v", result.Key, result.Value, result.TTL)
|
||||
}
|
||||
}
|
||||
|
||||
// wait for a snapshot interval
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
snapshots, err := ioutil.ReadDir("/tmp/node1/snapshot")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("list snapshot failed:" + err.Error())
|
||||
}
|
||||
|
||||
if len(snapshots) != 1 {
|
||||
t.Fatal("wrong number of snapshot :[1/", len(snapshots), "]")
|
||||
}
|
||||
|
||||
if snapshots[0].Name() != "0_503.ss" {
|
||||
t.Fatal("wrong name of snapshot :[0_503.ss/", snapshots[0].Name(), "]")
|
||||
}
|
||||
|
||||
// issue second 501 commands
|
||||
for i := 0; i < 501; i++ {
|
||||
result, err := c.Set("foo", "bar", 100)
|
||||
|
||||
if err != nil || result.Key != "/foo" || result.Value != "bar" || result.TTL < 95 {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Fatalf("Set failed with %s %s %v", result.Key, result.Value, result.TTL)
|
||||
}
|
||||
}
|
||||
|
||||
// wait for a snapshot interval
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
snapshots, err = ioutil.ReadDir("/tmp/node1/snapshot")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("list snapshot failed:" + err.Error())
|
||||
}
|
||||
|
||||
if len(snapshots) != 1 {
|
||||
t.Fatal("wrong number of snapshot :[1/", len(snapshots), "]")
|
||||
}
|
||||
|
||||
if snapshots[0].Name() != "0_1004.ss" {
|
||||
t.Fatal("wrong name of snapshot :[0_1004.ss/", snapshots[0].Name(), "]")
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
Copyright 2013 CoreOS Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
|
||||
@@ -13,6 +13,7 @@ const (
|
||||
testName = "ETCDTEST"
|
||||
testClientURL = "localhost:4401"
|
||||
testRaftURL = "localhost:7701"
|
||||
testSnapCount = 10000
|
||||
)
|
||||
|
||||
// Starts a server in a temporary directory.
|
||||
@@ -22,7 +23,7 @@ func RunServer(f func(*server.Server)) {
|
||||
|
||||
store := store.New()
|
||||
registry := server.NewRegistry(store)
|
||||
ps := server.NewPeerServer(testName, path, testRaftURL, testRaftURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, registry, store)
|
||||
ps := server.NewPeerServer(testName, path, testRaftURL, testRaftURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, registry, store, testSnapCount)
|
||||
s := server.New(testName, testClientURL, testClientURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, ps, registry, store)
|
||||
ps.SetServer(s)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user