@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
 private void setupServerAndCurator() throws Exception {
   server = new TestingServer();
   timing = new Timing();
   curator =
       CuratorFrameworkFactory.builder()
           .connectString(server.getConnectString())
           .sessionTimeoutMs(timing.session())
           .connectionTimeoutMs(timing.connection())
           .retryPolicy(new RetryOneTime(1))
           .compressionProvider(new PotentiallyGzippedCompressionProvider(true))
           .build();
 }
예제 #3
0
 void sleepABit() throws InterruptedException {
   timing.sleepABit();
 }