@Test
  public void test() throws Exception {
    Timing timing = new Timing();
    LeaderSelector leaderSelector = null;
    CuratorFramework client =
        CuratorFrameworkFactory.builder()
            .retryPolicy(new ExponentialBackoffRetry(100, 3))
            .connectString(server.getConnectString())
            .sessionTimeoutMs(timing.session())
            .connectionTimeoutMs(timing.connection())
            .build();
    try {
      client.start();

      MyLeaderSelectorListener listener = new MyLeaderSelectorListener();
      ExecutorService executorPool = Executors.newFixedThreadPool(20);
      leaderSelector = new LeaderSelector(client, "/test", threadFactory, executorPool, listener);

      leaderSelector.autoRequeue();
      leaderSelector.start();

      timing.sleepABit();

      Assert.assertEquals(listener.getLeaderCount(), 1);
    } finally {
      CloseableUtils.closeQuietly(leaderSelector);
      CloseableUtils.closeQuietly(client);
    }
  }
Пример #2
0
 void sleepABit() throws InterruptedException {
   timing.sleepABit();
 }