@Test
public void testResetFromWatcher() throws Exception
{

    Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();
        final WatcherRemovalFacade removerClient = (WatcherRemovalFacade)client.newWatcherRemoveCuratorFramework();
        final CountDownLatch createdLatch = new CountDownLatch(1);
        final CountDownLatch deletedLatch = new CountDownLatch(1);
        Watcher watcher = new Watcher()
        {
            @Override
            public void process(WatchedEvent event)
            {
                if ( event.getType() == Event.EventType.NodeCreated )
                {
                    try
                    {
                        removerClient.checkExists().usingWatcher(this).forPath("/yo");
                    }
                    catch ( Exception e )
                    {
                        e.printStackTrace();
                    }
                    createdLatch.countDown();
                }
                else if ( event.getType() == Event.EventType.NodeDeleted )
                {
                    deletedLatch.countDown();
                }
            }
        };
        removerClient.checkExists().usingWatcher(watcher).forPath("/yo");
        Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 1);
        removerClient.create().forPath("/yo");
        Assert.assertTrue(timing.awaitLatch(createdLatch));
        Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 1);
        removerClient.delete().forPath("/yo");
        Assert.assertTrue(timing.awaitLatch(deletedLatch));
        Assert.assertEquals(removerClient.getRemovalManager().getEntries().size(), 0);
    }
    finally
    {
        TestCleanState.closeAndTestClean(client);
    }
}