forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
zkctl_local.go
28 lines (22 loc) · 848 Bytes
/
zkctl_local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package zkctl
import (
"fmt"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/netutil"
)
// StartLocalZk is a helper method to create a local ZK process. Used
// in tests, mostly. It will log.Fatal out if there is an error. Each
// call should use different serverID / ports, so tests don't
// interfere with eachother. Use the testfiles package to achieve this.
func StartLocalZk(id, port int) (*Zkd, string) {
// Build the config parameters.
hostname := netutil.FullyQualifiedHostnameOrPanic()
zkCfg := fmt.Sprintf("%v@%v:%v:%v:%v", id, hostname, port, port+1, port+2)
zkConfig := MakeZkConfigFromString(zkCfg, uint32(id))
zkd := NewZkd(zkConfig)
// Init & start zk.
if err := zkd.Init(); err != nil {
log.Fatalf("zkd.Init(%d, %d) failed: %v", id, port, err)
}
return zkd, fmt.Sprintf("%v:%v", hostname, port+2)
}