Search in sources :

Example 1 with ZkOperation

use of org.apache.solr.common.cloud.ZkOperation in project lucene-solr by apache.

the class ZkSolrClientTest method testZkCmdExectutor.

public void testZkCmdExectutor() throws Exception {
    String zkDir = createTempDir("zkData").toFile().getAbsolutePath();
    ZkTestServer server = null;
    try {
        server = new ZkTestServer(zkDir);
        server.run();
        AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
        AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
        final int timeout = random().nextInt(10000) + 5000;
        ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(timeout);
        final long start = System.nanoTime();
        try {
            zkCmdExecutor.retryOperation(new ZkOperation() {

                @Override
                public String execute() throws KeeperException, InterruptedException {
                    if (System.nanoTime() - start > TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS)) {
                        throw new KeeperException.SessionExpiredException();
                    }
                    throw new KeeperException.ConnectionLossException();
                }
            });
        } catch (KeeperException.SessionExpiredException e) {
        } catch (Exception e) {
            fail("Expected " + KeeperException.SessionExpiredException.class.getSimpleName() + " but got " + e.getClass().getSimpleName());
        }
    } finally {
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : KeeperException(org.apache.zookeeper.KeeperException) ZkCmdExecutor(org.apache.solr.common.cloud.ZkCmdExecutor) ZkOperation(org.apache.solr.common.cloud.ZkOperation) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ZkCmdExecutor (org.apache.solr.common.cloud.ZkCmdExecutor)1 ZkOperation (org.apache.solr.common.cloud.ZkOperation)1 KeeperException (org.apache.zookeeper.KeeperException)1