Repository: curator
Updated Branches:
  refs/heads/CURATOR-114 [created] b04c8b5af


CURATOR-114 - Modified the TestingServer to expose the restart() method
on the underlying TestingZooKeeperServer. Modified all unit tests that
were previously using the stop() and then recreate using existing
temporary directory and port approach for restarting the server, so that
they now just call the restart() method.

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

Branch: refs/heads/CURATOR-114
Commit: 27c70aab9a3d86ba9a8a20e3ae28ef5bed147300
Parents: 6e98562
Author: Cameron McKenzie <came...@unico.com.au>
Authored: Tue Jun 17 13:49:03 2014 +1000
Committer: Cameron McKenzie <came...@unico.com.au>
Committed: Tue Jun 17 13:49:03 2014 +1000

----------------------------------------------------------------------
 .../java/org/apache/curator/BasicTests.java     |   2 +-
 .../java/org/apache/curator/TestRetryLoop.java  |   2 +-
 .../framework/imps/TestFailedDeleteManager.java |  12 +-
 .../curator/framework/imps/TestFramework.java   |   2 +-
 .../framework/imps/TestFrameworkEdges.java      |   2 +-
 .../recipes/leader/TestLeaderLatch.java         |   2 +-
 .../recipes/leader/TestLeaderSelector.java      |   2 +-
 .../locks/TestInterProcessMutexBase.java        |   2 +-
 .../org/apache/curator/test/TestingServer.java  | 112 ++++++++++++++++---
 .../x/discovery/TestServiceDiscovery.java       |   5 +-
 10 files changed, 109 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-client/src/test/java/org/apache/curator/BasicTests.java
----------------------------------------------------------------------
diff --git a/curator-client/src/test/java/org/apache/curator/BasicTests.java 
b/curator-client/src/test/java/org/apache/curator/BasicTests.java
index b886f3c..d25ae61 100644
--- a/curator-client/src/test/java/org/apache/curator/BasicTests.java
+++ b/curator-client/src/test/java/org/apache/curator/BasicTests.java
@@ -138,7 +138,7 @@ public class BasicTests extends BaseClassForTests
             server.stop();
             Thread.sleep(1000);
 
-            server = new TestingServer(serverPort, tempDirectory);
+            server.restart();
             Assert.assertTrue(client.blockUntilConnectedOrTimedOut());
             byte[]      readData = client.getZooKeeper().getData("/test", 
false, null);
             Assert.assertEquals(readData, writtenData);

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
----------------------------------------------------------------------
diff --git a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java 
b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
index c839807..430f587 100644
--- a/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
+++ b/curator-client/src/test/java/org/apache/curator/TestRetryLoop.java
@@ -74,7 +74,7 @@ public class TestRetryLoop extends BaseClassForTests
 
                     case 2:
                     {
-                        server = new TestingServer(serverPort, tempDirectory);
+                        server.restart();
                         break;
                     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFailedDeleteManager.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFailedDeleteManager.java
 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFailedDeleteManager.java
index fe74a72..0e66f0e 100644
--- 
a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFailedDeleteManager.java
+++ 
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFailedDeleteManager.java
@@ -82,7 +82,7 @@ public class TestFailedDeleteManager extends BaseClassForTests
 
             timing.sleepABit();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             Assert.assertTrue(timing.awaitLatch(latch));
 
             timing.sleepABit();
@@ -145,7 +145,7 @@ public class TestFailedDeleteManager extends 
BaseClassForTests
 
             timing.sleepABit();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             Assert.assertTrue(timing.awaitLatch(latch));
 
             timing.sleepABit();
@@ -208,7 +208,7 @@ public class TestFailedDeleteManager extends 
BaseClassForTests
 
             timing.sleepABit();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             Assert.assertTrue(timing.awaitLatch(latch));
 
             timing.sleepABit();
@@ -240,7 +240,6 @@ public class TestFailedDeleteManager extends 
BaseClassForTests
             int     serverPort = server.getPort();
 
             server.stop(); // cause the next delete to fail
-            server = null;
             try
             {
                 client.delete().forPath(PATH);
@@ -251,11 +250,10 @@ public class TestFailedDeleteManager extends 
BaseClassForTests
                 // expected
             }
             
-            server = new TestingServer(serverPort, serverDir);
+            server.restart();
             Assert.assertNotNull(client.checkExists().forPath(PATH));
 
             server.stop(); // cause the next delete to fail
-            server = null;
             try
             {
                 client.delete().guaranteed().forPath(PATH);
@@ -266,7 +264,7 @@ public class TestFailedDeleteManager extends 
BaseClassForTests
                 // expected
             }
 
-            server = new TestingServer(serverPort, serverDir);
+            server.restart();
 
             final int       TRIES = 5;
             for ( int i = 0; i < TRIES; ++i )

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/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 93d346b..08a284c 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
@@ -266,7 +266,7 @@ public class TestFramework extends BaseClassForTests
                 // expected
             }
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             try
             {
                 client.setData().forPath("/test", "test".getBytes());

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/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 4cc6330..9adb70f 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
@@ -359,7 +359,7 @@ public class TestFrameworkEdges extends BaseClassForTests
                     {
                         try
                         {
-                            server = new TestingServer(serverPort, 
tempDirectory);
+                            server.restart();
                         }
                         catch ( Exception e )
                         {

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
 
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
index b827e15..42ae74e 100644
--- 
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
+++ 
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
@@ -151,7 +151,7 @@ public class TestLeaderLatch extends BaseClassForTests
 
             Assert.assertEquals(getLeaders(latches).size(), 0);
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             Assert.assertEquals(waitForALeader(latches, timing).size(), 1); // 
should reconnect
         }
         finally

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/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 87306a1..ec909f7 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
@@ -182,7 +182,7 @@ public class TestLeaderSelector extends BaseClassForTests
             timing.sleepABit();
             debugLeadershipWaitLatch.countDown();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
 
             Assert.assertFalse(takeLeadershipLatch.await(3, TimeUnit.SECONDS));

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
----------------------------------------------------------------------
diff --git 
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
 
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
index 8b4ce46..3fe8110 100644
--- 
a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
+++ 
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutexBase.java
@@ -96,7 +96,7 @@ public abstract class TestInterProcessMutexBase extends 
BaseClassForTests
 
                                     server.stop();
                                     
Assert.assertTrue(timing.awaitLatch(latch));
-                                    server = new 
TestingServer(server.getPort(), server.getTempDirectory());
+                                    server.restart();
                                 }
                             }
                             finally

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
----------------------------------------------------------------------
diff --git 
a/curator-test/src/main/java/org/apache/curator/test/TestingServer.java 
b/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
index fe9dade..d20a9f8 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
@@ -37,47 +37,104 @@ public class TestingServer implements Closeable
 
     /**
      * Create the server using a random port
-     *
-     * @throws Exception errors
+     * 
+     * @throws Exception
+     *             errors
      */
     public TestingServer() throws Exception
     {
+        this(true);
+    }
+
+    /**
+     * Create the server using a random port
+     * 
+     * @param start
+     *            True if the server should be started, false otherwise
+     * @throws Exception
+     *             errors
+     */
+    public TestingServer(boolean start) throws Exception
+    {
         this(-1, null);
     }
 
     /**
      * Create the server using the given port
-     *
-     * @param port the port
-     * @throws Exception errors
+     * 
+     * @param port
+     *            the port
+     * @throws Exception
+     *             errors
      */
     public TestingServer(int port) throws Exception
     {
-        this(port, null);
+        this(port, true);
+    }
+
+    /**
+     * Create the server using the given port
+     * 
+     * @param port
+     *            the port
+     * @param start
+     *            True if the server should be started, false otherwise
+     * @throws Exception
+     *             errors
+     */
+    public TestingServer(int port, boolean start) throws Exception
+    {
+        this(port, null, start);
     }
 
     /**
      * Create the server using the given port
-     *
-     * @param port          the port
-     * @param tempDirectory directory to use
-     * @throws Exception errors
+     * 
+     * @param port
+     *            the port
+     * @param tempDirectory
+     *            directory to use
+     * @throws Exception
+     *             errors
      */
     public TestingServer(int port, File tempDirectory) throws Exception
     {
-        this(new InstanceSpec(tempDirectory, port, -1, -1, true, -1));
+        this(port, tempDirectory, true);
     }
 
-    public TestingServer(InstanceSpec spec) throws Exception
+    /**
+     * Create the server using the given port
+     * 
+     * @param port
+     *            the port
+     * @param tempDirectory
+     *            directory to use
+     * @param start
+     *            True if the server should be started, false otherwise
+     * @throws Exception
+     *             errors
+     */
+    public TestingServer(int port, File tempDirectory, boolean start)
+            throws Exception
+    {
+        this(new InstanceSpec(tempDirectory, port, -1, -1, true, -1), start);
+    }
+
+    public TestingServer(InstanceSpec spec, boolean start) throws Exception
     {
         this.spec = spec;
-        testingZooKeeperServer = new TestingZooKeeperServer(new 
QuorumConfigBuilder(spec));
-        testingZooKeeperServer.start();
+        testingZooKeeperServer = new TestingZooKeeperServer(
+                new QuorumConfigBuilder(spec));
+
+        if (start)
+        {
+            testingZooKeeperServer.start();
+        }
     }
 
     /**
      * Return the port being used
-     *
+     * 
      * @return port
      */
     public int getPort()
@@ -87,7 +144,7 @@ public class TestingServer implements Closeable
 
     /**
      * Returns the temp directory being used
-     *
+     * 
      * @return directory
      */
     public File getTempDirectory()
@@ -96,6 +153,16 @@ public class TestingServer implements Closeable
     }
 
     /**
+     * Start the server
+     * 
+     * @throws Exception
+     */
+    public void start() throws Exception
+    {
+        testingZooKeeperServer.start();
+    }
+
+    /**
      * Stop the server without deleting the temp directory
      */
     public void stop() throws IOException
@@ -104,6 +171,17 @@ public class TestingServer implements Closeable
     }
 
     /**
+     * Restart the server. This is only valid if the server has previously been
+     * stopped.
+     * 
+     * @throws Exception
+     */
+    public void restart() throws Exception
+    {
+        testingZooKeeperServer.restart();
+    }
+
+    /**
      * Close the server and any open clients and delete the temp directory
      */
     @Override
@@ -114,7 +192,7 @@ public class TestingServer implements Closeable
 
     /**
      * Returns the connection string to use
-     *
+     * 
      * @return connection string
      */
     public String getConnectString()

http://git-wip-us.apache.org/repos/asf/curator/blob/27c70aab/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
----------------------------------------------------------------------
diff --git 
a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
 
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
index 354b88a..73de7fc 100644
--- 
a/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
+++ 
b/curator-x-discovery/src/test/java/org/apache/curator/x/discovery/TestServiceDiscovery.java
@@ -26,7 +26,6 @@ import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.KillSession;
-import org.apache.curator.test.TestingServer;
 import org.apache.curator.test.Timing;
 import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
 import org.apache.curator.x.discovery.details.ServiceDiscoveryImpl;
@@ -83,7 +82,7 @@ public class TestServiceDiscovery extends BaseClassForTests
             KillSession.kill(client.getZookeeperClient().getZooKeeper(), 
server.getConnectString());
             server.stop();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             closeables.add(server);
 
             timing.acquireSemaphore(semaphore, 2);
@@ -129,7 +128,7 @@ public class TestServiceDiscovery extends BaseClassForTests
             KillSession.kill(client.getZookeeperClient().getZooKeeper(), 
server.getConnectString());
             server.stop();
 
-            server = new TestingServer(server.getPort(), 
server.getTempDirectory());
+            server.restart();
             closeables.add(server);
 
             timing.acquireSemaphore(semaphore);

Reply via email to