Beispiel #1
0
  public DistributedMap(SolrZkClient zookeeper, String dir) {
    this.dir = dir;

    ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zookeeper.getZkClientTimeout());
    try {
      cmdExecutor.ensureExists(dir, zookeeper);
    } catch (KeeperException e) {
      throw new SolrException(ErrorCode.SERVER_ERROR, e);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new SolrException(ErrorCode.SERVER_ERROR, e);
    }

    this.zookeeper = zookeeper;
  }
Beispiel #2
0
  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();
      }
    }
  }