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 2017/05/08 12:23:51 UTC

[1/2] curator git commit: Added a method to Timing to take from a queue with timeouts and applied it to tests that needed it

Repository: curator
Updated Branches:
  refs/heads/CURATOR-411 [created] 5407746c3


Added a method to Timing to take from a queue with timeouts and applied it to tests that needed it


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

Branch: refs/heads/CURATOR-411
Commit: 872bfb0285dc4807d873b9ee2707b0f6044747f6
Parents: f898959
Author: randgalt <ra...@apache.org>
Authored: Mon May 8 06:01:45 2017 +0200
Committer: randgalt <ra...@apache.org>
Committed: Mon May 8 06:01:45 2017 +0200

----------------------------------------------------------------------
 .../curator/framework/imps/TestFramework.java   |  2 +-
 .../framework/imps/TestFrameworkEdges.java      |  8 +++---
 .../recipes/cache/TestEventOrdering.java        |  2 +-
 .../recipes/leader/TestLeaderSelector.java      |  2 +-
 .../java/org/apache/curator/test/Timing.java    | 28 ++++++++++++++++++++
 5 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/872bfb02/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index 44f9486..5d0c5ed 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -261,7 +261,7 @@ public class TestFramework extends BaseClassForTests
             client.getChildren().usingWatcher(watcher).forPath("/base");
             client.create().forPath("/base/child");
 
-            String path = queue.take();
+            String path = new Timing().takeFromQueue(queue);
             Assert.assertEquals(path, "/base");
         }
         finally

http://git-wip-us.apache.org/repos/asf/curator/blob/872bfb02/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index bf1c281..ce0bb26 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@ -180,8 +180,8 @@ public class TestFrameworkEdges extends BaseClassForTests
             final String TEST_PATH = "/a/b/c/test-";
             client.create().withMode(mode).inBackground(callback).forPath(TEST_PATH);
 
-            String name1 = paths.take();
-            String path1 = paths.take();
+            String name1 = timing.takeFromQueue(paths);
+            String path1 = timing.takeFromQueue(paths);
 
             client.close();
 
@@ -196,8 +196,8 @@ public class TestFrameworkEdges extends BaseClassForTests
             createBuilder.debugForceFindProtectedNode = true;
             createBuilder.withMode(mode).inBackground(callback).forPath(TEST_PATH);
 
-            String name2 = paths.take();
-            String path2 = paths.take();
+            String name2 = timing.takeFromQueue(paths);
+            String path2 = timing.takeFromQueue(paths);
 
             Assert.assertEquals(ZKPaths.getPathAndNode(name1).getPath(), ZKPaths.getPathAndNode(TEST_PATH).getPath());
             Assert.assertEquals(ZKPaths.getPathAndNode(name2).getPath(), ZKPaths.getPathAndNode(TEST_PATH).getPath());

http://git-wip-us.apache.org/repos/asf/curator/blob/872bfb02/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
index 216c07c..7b3a07e 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestEventOrdering.java
@@ -143,7 +143,7 @@ public abstract class TestEventOrdering<T extends Closeable> extends BaseClassFo
             int eventSuggestedQty = 0;
             while ( events.size() > 0 )
             {
-                Event event = events.take();
+                Event event = timing.takeFromQueue(events);
                 localEvents.add(event);
                 eventSuggestedQty += (event.eventType == EventType.ADDED) ? 1 : -1;
             }

http://git-wip-us.apache.org/repos/asf/curator/blob/872bfb02/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
index c1622ba..60619d0 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java
@@ -193,7 +193,7 @@ public class TestLeaderSelector extends BaseClassForTests
             selector = new LeaderSelector(client, "/leader", listener);
             selector.start();
 
-            Thread leaderThread = queue.take();
+            Thread leaderThread = timing.takeFromQueue(queue);
             server.stop();
             leaderThread.interrupt();
             server.restart();

http://git-wip-us.apache.org/repos/asf/curator/blob/872bfb02/curator-test/src/main/java/org/apache/curator/test/Timing.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/Timing.java b/curator-test/src/main/java/org/apache/curator/test/Timing.java
index 27e4e53..242aa50 100644
--- a/curator-test/src/main/java/org/apache/curator/test/Timing.java
+++ b/curator-test/src/main/java/org/apache/curator/test/Timing.java
@@ -19,9 +19,11 @@
 
 package org.apache.curator.test;
 
+import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 /**
  * Utility to get various testing times
@@ -128,6 +130,32 @@ public class Timing
     }
 
     /**
+     * Try to take an item from the given queue
+     *
+     * @param queue queue
+     * @return item
+     * @throws Exception interrupted or timed out
+     */
+    public <T> T takeFromQueue(BlockingQueue<T> queue) throws Exception
+    {
+        Timing m = forWaiting();
+        try
+        {
+            T value = queue.poll(m.value, m.unit);
+            if ( value == null )
+            {
+                throw new TimeoutException("Timed out trying to take from queue");
+            }
+            return value;
+        }
+        catch ( InterruptedException e )
+        {
+            Thread.currentThread().interrupt();
+            throw e;
+        }
+    }
+
+    /**
      * Wait on the given semaphore
      *
      * @param semaphore the semaphore


[2/2] curator git commit: Merge branch 'master' into CURATOR-411

Posted by ra...@apache.org.
Merge branch 'master' into CURATOR-411


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

Branch: refs/heads/CURATOR-411
Commit: 5407746c37c6ee08bbefe6632e25f5790226180c
Parents: 872bfb0 32a7755
Author: randgalt <ra...@apache.org>
Authored: Mon May 8 06:15:40 2017 +0200
Committer: randgalt <ra...@apache.org>
Committed: Mon May 8 06:15:40 2017 +0200

----------------------------------------------------------------------
 .../curator/framework/imps/TestFrameworkEdges.java   | 14 +++++++++++---
 .../apache/curator/test/TestingQuorumPeerMain.java   |  3 +--
 .../apache/curator/test/TestingZooKeeperMain.java    |  7 -------
 .../apache/curator/test/TestingZooKeeperServer.java  | 15 +++++++++++----
 .../org/apache/curator/test/ZooKeeperMainFace.java   |  3 ---
 5 files changed, 23 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5407746c/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
----------------------------------------------------------------------
diff --cc curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index ce0bb26,6acbaf6..887f236
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@@ -178,10 -178,17 +178,15 @@@ public class TestFrameworkEdges extend
                  }
              };
              final String TEST_PATH = "/a/b/c/test-";
-             client.create().withMode(mode).inBackground(callback).forPath(TEST_PATH);
+             long ttl = timing.forWaiting().milliseconds()*1000;
+             CreateBuilder firstCreateBuilder = client.create();
+             if(mode.isTTL()) {
+                 firstCreateBuilder.withTtl(ttl);
+             }
+             firstCreateBuilder.withMode(mode).inBackground(callback).forPath(TEST_PATH);
  
 -            String name1 = paths.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);
 -            String path1 = paths.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);
 -            Assert.assertNotNull(name1);
 -            Assert.assertNotNull(path1);
 +            String name1 = timing.takeFromQueue(paths);
 +            String path1 = timing.takeFromQueue(paths);
  
              client.close();