### Question:
LeaderSelector implements Closeable { public void autoRequeue() { autoRequeue.set(true); } LeaderSelector(CuratorFramework client, String leaderPath, LeaderSelectorListener listener); @SuppressWarnings("UnusedParameters") @Deprecated  LeaderSelector(CuratorFramework client, String leaderPath, ThreadFactory threadFactory, Executor executor, LeaderSelectorListener listener);  LeaderSelector(CuratorFramework client, String leaderPath, ExecutorService executorService, LeaderSelectorListener listener);  LeaderSelector(CuratorFramework client, String leaderPath, CloseableExecutorService executorService, LeaderSelectorListener listener); void autoRequeue(); void setId(String id); String getId(); void start(); boolean requeue(); synchronized void close(); Collection<Participant> getParticipants(); Participant getLeader(); boolean hasLeadership(); synchronized void interruptLeadership();  }### Answer:
@Test public void testAutoRequeue() throws Exception { Timing timing = new Timing(); LeaderSelector selector = null; CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).sessionTimeoutMs(timing.session()).build(); try { client.start(); final Semaphore semaphore = new Semaphore(0); LeaderSelectorListener listener = new LeaderSelectorListener() { @Override public void takeLeadership(CuratorFramework client) throws Exception { Thread.sleep(10); semaphore.release(); } @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { } }; selector = new LeaderSelector(client, "/leader", listener); selector.autoRequeue(); selector.start(); Assert.assertTrue(timing.acquireSemaphore(semaphore, 2)); } finally { CloseableUtils.closeQuietly(selector); CloseableUtils.closeQuietly(client); } }