Exemplo n.º 1
0
// This error will be delivered via C errno, since ZK unfortunately
// only provides the handler back from zookeeper_init().
func (s *S) TestInitErrorThroughErrno(c *C) {
	zk, watch, err := gozk.Init("bad-domain-without-port", 5e9)
	if zk != nil {
		zk.Close()
	}
	if watch != nil {
		go func() {
			for {
				_, ok := <-watch
				if !ok {
					break
				}
			}
		}()
	}
	c.Assert(zk, IsNil)
	c.Assert(watch, IsNil)
	c.Assert(err, Matches, "invalid argument")
}
Exemplo n.º 2
0
func (s *S) TestRecvTimeoutInitParameter(c *C) {
	zk, watch, err := gozk.Init(s.zkAddr, 0)
	c.Assert(err, IsNil)
	defer zk.Close()

	select {
	case <-watch:
		c.Fatal("Watch fired")
	default:
	}

	for i := 0; i != 1000; i++ {
		_, _, err := zk.Get("/zookeeper")
		if err != nil {
			c.Assert(err, Matches, "operation timeout")
			c.SucceedNow()
		}
	}

	c.Fatal("Operation didn't timeout")
}
Exemplo n.º 3
0
func (s *S) init(c *C) (*gozk.ZooKeeper, chan gozk.Event) {
	zk, watch, err := gozk.Init(s.zkAddr, 5e9)
	c.Assert(err, IsNil)

	s.handles = append(s.handles, zk)

	event := <-watch

	c.Assert(event.Type, Equals, gozk.EVENT_SESSION)
	c.Assert(event.State, Equals, gozk.STATE_CONNECTED)

	bufferedWatch := make(chan gozk.Event, 256)
	bufferedWatch <- event

	s.liveWatches += 1
	go func() {
	loop:
		for {
			select {
			case event, ok := <-watch:
				if !ok {
					close(bufferedWatch)
					break loop
				}
				select {
				case bufferedWatch <- event:
				default:
					panic("Too many events in buffered watch!")
				}
			}
		}
		s.deadWatches <- true
	}()

	return zk, bufferedWatch
}