You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/02/03 22:14:30 UTC

git commit: CURATOR-75 InterProcessSemaphoreV2 with a SharedCountReader wasn't notifying if shared count was changed

Updated Branches:
  refs/heads/CURATOR-75 [created] 09f04e9c9


CURATOR-75 InterProcessSemaphoreV2 with a SharedCountReader wasn't notifying if shared count was changed


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/09f04e9c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/09f04e9c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/09f04e9c

Branch: refs/heads/CURATOR-75
Commit: 09f04e9c9cab8062e31e2a0d658f04f3a26fbe65
Parents: 863eaee
Author: randgalt <ra...@apache.org>
Authored: Mon Feb 3 16:14:09 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon Feb 3 16:14:09 2014 -0500

----------------------------------------------------------------------
 .../framework/recipes/locks/InterProcessSemaphoreV2.java |  1 +
 .../recipes/locks/TestInterProcessSemaphore.java         | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/09f04e9c/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessSemaphoreV2.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessSemaphoreV2.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessSemaphoreV2.java
index 52be756..fd27cbb 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessSemaphoreV2.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessSemaphoreV2.java
@@ -133,6 +133,7 @@ public class InterProcessSemaphoreV2
                         public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception
                         {
                             InterProcessSemaphoreV2.this.maxLeases = newCount;
+                            notifyFromWatcher();
                         }
 
                         @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/09f04e9c/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessSemaphore.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessSemaphore.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessSemaphore.java
index 2109417..e3e75a1 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessSemaphore.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessSemaphore.java
@@ -61,7 +61,8 @@ public class TestInterProcessSemaphore extends BaseClassForTests
 
             ExecutorService service = Executors.newCachedThreadPool();
 
-            final CountDownLatch latch = new CountDownLatch(1);
+            final CountDownLatch latch1 = new CountDownLatch(1);
+            final CountDownLatch latch2 = new CountDownLatch(1);
             Future<Object> future1 = service.submit
                 (
                     new Callable<Object>()
@@ -71,9 +72,10 @@ public class TestInterProcessSemaphore extends BaseClassForTests
                         {
                             Lease lease = semaphore.acquire(timing.seconds(), TimeUnit.SECONDS);
                             Assert.assertNotNull(lease);
-                            latch.countDown();
+                            latch1.countDown();
                             lease = semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS);
                             Assert.assertNotNull(lease);
+                            latch2.countDown();
                             return null;
                         }
                     }
@@ -85,9 +87,12 @@ public class TestInterProcessSemaphore extends BaseClassForTests
                         @Override
                         public Object call() throws Exception
                         {
-                            Assert.assertTrue(latch.await(timing.forWaiting().seconds(), TimeUnit.SECONDS));
+                            Assert.assertTrue(latch1.await(timing.forWaiting().seconds(), TimeUnit.SECONDS));
                             timing.sleepABit(); // make sure second acquire is waiting
                             Assert.assertTrue(count.trySetCount(2));
+                            //Make sure second acquire takes less than full waiting time:
+                            timing.sleepABit();
+                            Assert.assertTrue(latch2.await(0, TimeUnit.SECONDS));
                             return null;
                         }
                     }