1 Star 2 Fork 0

bison-fork/etcd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server_utils.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Cong Ding 提交于 2013-12-12 14:53 . gofmt
package tests
import (
"io/ioutil"
"os"
"time"
"github.com/coreos/etcd/server"
"github.com/coreos/etcd/store"
)
const (
testName = "ETCDTEST"
testClientURL = "localhost:4401"
testRaftURL = "localhost:7701"
testSnapshotCount = 10000
testHeartbeatTimeout = 50
testElectionTimeout = 200
)
// Starts a server in a temporary directory.
func RunServer(f func(*server.Server)) {
path, _ := ioutil.TempDir("", "etcd-")
defer os.RemoveAll(path)
store := store.New()
registry := server.NewRegistry(store)
ps := server.NewPeerServer(testName, path, "http://"+testRaftURL, testRaftURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, registry, store, testSnapshotCount)
ps.MaxClusterSize = 9
ps.ElectionTimeout = testElectionTimeout
ps.HeartbeatTimeout = testHeartbeatTimeout
s := server.New(testName, "http://"+testClientURL, testClientURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, ps, registry, store)
ps.SetServer(s)
// Start up peer server.
c := make(chan bool)
go func() {
c <- true
ps.ListenAndServe(false, []string{})
}()
<-c
// Start up etcd server.
go func() {
c <- true
s.ListenAndServe()
}()
<-c
// Wait to make sure servers have started.
time.Sleep(50 * time.Millisecond)
// Execute the function passed in.
f(s)
// Clean up servers.
ps.Close()
s.Close()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bison-fork/etcd.git
git@gitee.com:bison-fork/etcd.git
bison-fork
etcd
etcd
v0.2.0-rc4

搜索帮助