You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Adam Silberstein <ad...@trifacta.com> on 2012/12/14 01:56:35 UTC

question about server startup time in testing env

Hi,
I've written a test helper class that starts up ZK in-process and tears it down when done.  Here's a code snippet:

 static NIOServerCnxnFactory _standaloneServerFactory;
 public static int _clientPort = 21818;
 static ZooKeeperServer _server;
  
 _server = new ZooKeeperServer(dir, dir, tickTime);
 _standaloneServerFactory = new NIOServerCnxnFactory();
 _standaloneServerFactory.configure(new InetSocketAddress(_clientPort), numConnections);
 _standaloneServerFactory.startup(_server);

One thing I've noticed is that the final line appears to be synchronous in nature, whenever I attempt to connect to ZK immediately, my client fails.  Currently, I just retry a few times.  Is there a programmatic way to check when the server is read for connections?  I tried a few method calls on ZooKeeperServer but nothing was helpful there.

Thanks,
Adam 

Re: question about server startup time in testing env

Posted by kishore g <g....@gmail.com>.
The server is started before it returns from
_standaloneServerFactory.startup(_server),
 ZooKeeperServer has a isRunning method if you really want to check if it
is running.

My guess is the problem is with the client usage, you are probably trying
to use the client before its connected. You need wait for synconnected
event before you can invoke other api's on zookeeper.

To test this hypothesis, sleep for few seconds after the client is created
before using it.

thanks,
Kishore G


On Thu, Dec 13, 2012 at 4:56 PM, Adam Silberstein <ad...@trifacta.com> wrote:

> Hi,
> I've written a test helper class that starts up ZK in-process and tears it
> down when done.  Here's a code snippet:
>
>  static NIOServerCnxnFactory _standaloneServerFactory;
>  public static int _clientPort = 21818;
>  static ZooKeeperServer _server;
>
>  _server = new ZooKeeperServer(dir, dir, tickTime);
>  _standaloneServerFactory = new NIOServerCnxnFactory();
>  _standaloneServerFactory.configure(new InetSocketAddress(_clientPort),
> numConnections);
>  _standaloneServerFactory.startup(_server);
>
> One thing I've noticed is that the final line appears to be synchronous in
> nature, whenever I attempt to connect to ZK immediately, my client fails.
>  Currently, I just retry a few times.  Is there a programmatic way to check
> when the server is read for connections?  I tried a few method calls on
> ZooKeeperServer but nothing was helpful there.
>
> Thanks,
> Adam