curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject [1/2] curator git commit: Curator-224: Fixed the requeuing problem with DistributedIdQueue.
Date Mon, 22 Jun 2015 23:58:33 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-224 [created] 19bb4d1c4


Curator-224: Fixed the requeuing problem with DistributedIdQueue.


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

Branch: refs/heads/CURATOR-224
Commit: 83e1a855a15e17a37ec02d441d6c75e7f08a2617
Parents: 20e92a5
Author: Zhihong Zhang <zhangz@pixia.com>
Authored: Mon Jun 22 14:59:02 2015 -0400
Committer: Zhihong Zhang <zhangz@pixia.com>
Committed: Mon Jun 22 14:59:02 2015 -0400

----------------------------------------------------------------------
 .../recipes/queue/DistributedQueue.java         |  2 +-
 .../recipes/queue/TestDistributedIdQueue.java   | 47 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/83e1a855/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
index 9dd2217..a183adf 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/queue/DistributedQueue.java
@@ -756,7 +756,7 @@ public class DistributedQueue<T> implements QueueBase<T>
                 client.inTransaction()
                     .delete().forPath(itemPath)
                     .and()
-                    .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(makeItemPath(),
bytes)
+                    .create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(itemPath,
bytes)
                     .and()
                     .commit();
             }

http://git-wip-us.apache.org/repos/asf/curator/blob/83e1a855/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
index 30e552f..858086b 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedIdQueue.java
@@ -124,4 +124,51 @@ public class TestDistributedIdQueue extends BaseClassForTests
             CloseableUtils.closeQuietly(client);
         }
     }
+
+    @Test
+    public void testRequeuingWithLock() throws Exception
+    {
+        DistributedIdQueue<TestQueueItem>  queue = null;
+        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryOneTime(1));
+        client.start();
+        try
+        {
+            final CountDownLatch        consumingLatch = new CountDownLatch(1);
+
+            QueueConsumer<TestQueueItem> consumer = new QueueConsumer<TestQueueItem>()
+            {
+                @Override
+                public void consumeMessage(TestQueueItem message) throws Exception
+                {
+                    consumingLatch.countDown();
+                    // Throw an exception so requeuing occurs
+                    throw new Exception("Consumer failed");
+                }
+
+                @Override
+                public void stateChanged(CuratorFramework client, ConnectionState newState)
+                {
+                }
+            };
+
+            queue = QueueBuilder.builder(client, consumer, serializer, QUEUE_PATH).lockPath("/locks").buildIdQueue();
+            queue.start();
+
+            queue.put(new TestQueueItem("test"), "id");
+
+            Assert.assertTrue(consumingLatch.await(10, TimeUnit.SECONDS));  // wait until
consumer has it
+
+            // Sleep one more second
+
+            Thread.sleep(1000);
+
+            Assert.assertEquals(queue.remove("id"), 1);
+
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(queue);
+            CloseableUtils.closeQuietly(client);
+        }
+    }
 }


Mime
View raw message