Example #1
0
func (s *S) TestCreateServer(c *C) {
	dir := c.MkDir()

	zkdir := dir + "/zk"
	// Check that it creates the new directory.
	srv, err := zk.CreateServer(9999, zkdir, "")
	c.Assert(err, IsNil)
	c.Assert(srv, NotNil)

	info, err := os.Stat(zkdir)
	c.Assert(err, IsNil)
	c.Assert(info.IsDir(), Equals, true)

	addr, err := srv.Addr()
	c.Assert(err, IsNil)
	c.Assert(addr, Equals, "127.0.0.1:9999")

	// Check that it fails when called again on the non-empty directory.
	_, err = zk.CreateServer(9999, zkdir, "")
	c.Assert(err, ErrorMatches, `server directory .* is not empty`)

	// Check that Destroy removes the directory.
	err = srv.Destroy()
	c.Assert(err, IsNil)

	_, err = os.Stat(zkdir)
	if !os.IsNotExist(err) {
		c.Errorf("expected not-exists error, got %v", err)
	}

	// Check that we can call CreateServer on the empty directory
	srv, err = zk.CreateServer(8888, dir, "")
	c.Assert(err, IsNil)
	c.Assert(srv, NotNil)

	addr, err = srv.Addr()
	c.Assert(err, IsNil)
	c.Assert(addr, Equals, "127.0.0.1:8888")

	err = srv.Destroy()
	c.Assert(err, IsNil)
}
Example #2
0
// We use the suite set up and tear down to manage a custom ZooKeeper
//
func (s *S) SetUpSuite(c *C) {
	var err error
	s.deadWatches = make(chan bool)

	// N.B. We need to create a subdirectory because zk.CreateServer
	// insists on creating its own directory.

	s.zkTestRoot = c.MkDir() + "/zk"
	port := 21812
	s.zkAddr = fmt.Sprint("localhost:", port)

	s.zkServer, err = zk.CreateServer(port, s.zkTestRoot, "")
	if err != nil {
		c.Fatal("Cannot set up server environment: ", err)
	}
	err = s.zkServer.Start()
	if err != nil {
		c.Fatal("Cannot start ZooKeeper server: ", err)
	}
}