@Test public void testNoOrphanedNodes() throws Exception { final Timing timing = new Timing(); final ExecutorService executor = Executors.newFixedThreadPool(1); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); client.start(); try { final InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(client, "/test", 1); Lease lease = semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS); Assert.assertNotNull(lease); final List<String> childNodes = client.getChildren().forPath("/test/leases"); Assert.assertEquals(childNodes.size(), 1); final CountDownLatch nodeCreatedLatch = new CountDownLatch(1); client.getChildren().usingWatcher(new CuratorWatcher() { @Override public void process(WatchedEvent event) throws Exception { if ( event.getType() == Watcher.Event.EventType.NodeCreated ) { nodeCreatedLatch.countDown(); } } }).forPath("/test/leases"); final Future<Lease> leaseFuture = executor.submit(new Callable<Lease>() { @Override public Lease call() throws Exception { return semaphore.acquire(timing.forWaiting().multiple(2).seconds(), TimeUnit.SECONDS); } }); timing.awaitLatch(nodeCreatedLatch); String newNode = null; for ( String c : client.getChildren().forPath("/test/leases") ) { if ( !childNodes.contains(c) ) { newNode = c; } } Assert.assertNotNull(newNode); client.delete().forPath("/test/leases/" + newNode); lease.close(); lease = leaseFuture.get(); Assert.assertNotNull(lease); lease.close(); Assert.assertEquals(client.getChildren().forPath("/test/leases").size(), 0); Assert.assertNotNull(semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS)); } finally { executor.shutdownNow(); TestCleanState.closeAndTestClean(client); } }
public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); void returnAll(Collection<Lease> leases); void returnLease(Lease lease); Lease acquire(); Collection<Lease> acquire(int qty); Lease acquire(long time, TimeUnit unit); Collection<Lease> acquire(int qty, long time, TimeUnit unit); }
InterProcessSemaphore { public Lease acquire() throws Exception { String path = internals.attemptLock(-1, null, null); return makeLease(path); } InterProcessSemaphore(CuratorFramework client, String path, int maxLeases);  InterProcessSemaphore(CuratorFramework client, String path, SharedCountReader count); private  InterProcessSemaphore(CuratorFramework client, String path, int maxLeases, SharedCountReader count); void returnAll(Collection<Lease> leases); void returnLease(Lease lease); Lease acquire(); Collection<Lease> acquire(int qty); Lease acquire(long time, TimeUnit unit); Collection<Lease> acquire(int qty, long time, TimeUnit unit);  }