* Shutdown the Curator client while there are still background operations running.
*/
@Test
public void testShutdown() throws Exception
{
Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory
.builder()
.connectString(server.getConnectString())
.sessionTimeoutMs(timing.session())
.connectionTimeoutMs(timing.connection()).retryPolicy(new RetryOneTime(1))
.maxCloseWaitMs(timing.forWaiting().milliseconds())
.build();
try
{
final AtomicBoolean hadIllegalStateException = new AtomicBoolean(false);
((CuratorFrameworkImpl)client).debugUnhandledErrorListener = new UnhandledErrorListener()
{
@Override
public void unhandledError(String message, Throwable e)
{
if ( e instanceof IllegalStateException )
{
hadIllegalStateException.set(true);
}
}
};
client.start();
final CountDownLatch operationReadyLatch = new CountDownLatch(1);
((CuratorFrameworkImpl)client).debugListener = new CuratorFrameworkImpl.DebugBackgroundListener()
{
@Override
public void listen(OperationAndData<?> data)
{
try
{
operationReadyLatch.await();
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt();
}
}
};
// queue a background operation that will block due to the debugListener
client.create().inBackground().forPath("/hey");
timing.sleepABit();
// close the client while the background is still blocked
client.close();
// unblock the background
operationReadyLatch.countDown();
timing.sleepABit();
// should not generate an exception
Assert.assertFalse(hadIllegalStateException.get());
}
finally