Fixing test so that the test methods can be run out of order.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/cca51eb2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/cca51eb2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/cca51eb2 Branch: refs/heads/apache-blur-0.2 Commit: cca51eb28949389265459e594a606bf98538dff8 Parents: 023277c Author: Aaron McCurry <[email protected]> Authored: Sat Sep 21 22:47:45 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Sat Sep 21 22:47:45 2013 -0400 ---------------------------------------------------------------------- .../blur/manager/indexserver/SafeModeTest.java | 35 +++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/cca51eb2/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java ---------------------------------------------------------------------- diff --git a/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java b/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java index bde5180..540ad34 100644 --- a/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java +++ b/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java @@ -35,14 +35,15 @@ import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooKeeper; +import org.junit.After; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class SafeModeTest { private static String path = "./target/test-zk"; - private static ZooKeeper zk; private static MiniCluster miniCluster; @BeforeClass @@ -50,6 +51,17 @@ public class SafeModeTest { new File(path).mkdirs(); miniCluster = new MiniCluster(); miniCluster.startZooKeeper(path, true); + } + + @AfterClass + public static void stopZooKeeper() throws InterruptedException { + miniCluster.shutdownZooKeeper(); + } + + private ZooKeeper zk; + + @Before + public void setup() throws IOException { zk = new ZooKeeper(miniCluster.getZkConnectionString(), 20000, new Watcher() { @Override public void process(WatchedEvent event) { @@ -58,10 +70,10 @@ public class SafeModeTest { }); } - @AfterClass - public static void stopZooKeeper() throws InterruptedException { + @After + public void teardown() throws KeeperException, InterruptedException { + rm(zk, "/testing"); zk.close(); - miniCluster.shutdownZooKeeper(); } @Test @@ -120,6 +132,10 @@ public class SafeModeTest { } }); + + SafeMode setupSafeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, + TimeUnit.SECONDS, 60); + setupSafeMode.registerNode("node1", null); SafeMode safeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 60); @@ -139,6 +155,10 @@ public class SafeModeTest { } }); + + SafeMode setupSafeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, + TimeUnit.SECONDS, 60); + setupSafeMode.registerNode("node10", null); SafeMode safeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 15); @@ -170,4 +190,11 @@ public class SafeModeTest { return thread; } + private static void rm(ZooKeeper zk, String path) throws KeeperException, InterruptedException { + List<String> children = zk.getChildren(path, false); + for (String c : children) { + rm(zk, path + "/" + c); + } + zk.delete(path, -1); + } }
