// StartClusterTest builds and starts a zookeeper test cluster. Stdout and stderr are redirected // to the test logging, which means they are available when -v is specified. func StartClusterTest(t *testing.T, nodeCount int) *ClusterTest { testCluster, err := zk.StartTestCluster(nodeCount, os.Stdout, os.Stderr) if err != nil { t.Fatalf("Could not start test cluster: %v", err) } return &ClusterTest{t, testCluster} }
func withZookeeper(t *testing.T, zookeeperWork func(zkServer *zk.TestServer)) { testCluster, err := zk.StartTestCluster(1, nil, logWriter{t: t, p: "[ZKERR] "}) if err != nil { t.Fatal(err) } defer testCluster.Stop() zookeeperWork(&testCluster.Servers[0]) }
func TestMain(m *testing.M) { t, err := zk.StartTestCluster(1, nil, nil) helpers.PanicError(err) defer t.Stop() servers = make([]string, 1) servers[0] = fmt.Sprintf("localhost:%d", t.Servers[0].Port) createExistingNode("/existing") createExistingNode("/historic") r := m.Run() os.Exit(r) }
func getTestCluster(t *testing.T) *zk.TestCluster { zkCluster, err := zk.StartTestCluster(1, os.Stdout, os.Stderr) if err != nil { t.Fatal("cannot start testing zk cluster: ", err) } _, err = zkCluster.Connect(0) if err != nil { t.Fatal("cannot connect to test cluster:", err) } log.Println("zk running at: ", zkCluster.Servers[0].Port) return zkCluster }
func TestMain(m *testing.M) { flag.Parse() fmt.Println("Starting ZooKeeper server...") ts, err := stdzk.StartTestCluster(1, nil, nil) if err != nil { fmt.Printf("ZooKeeper server error: %v\n", err) os.Exit(1) } host = []string{fmt.Sprintf("localhost:%d", ts.Servers[0].Port)} code := m.Run() ts.Stop() os.Exit(code) }