You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by el...@apache.org on 2014/11/22 23:04:57 UTC

[26/50] incubator-slider git commit: SLIDER-622: fix ZK Integration tests to be more independent and better @ cleaning up

SLIDER-622: fix ZK Integration tests to be more independent and better @ cleaning up


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/b88c7759
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/b88c7759
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/b88c7759

Branch: refs/heads/master
Commit: b88c775949bd2fd9d0605b2d8ea4c86724cbc42b
Parents: e04c51b
Author: Steve Loughran <st...@apache.org>
Authored: Tue Nov 11 11:40:44 2014 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Nov 11 15:04:19 2014 +0000

----------------------------------------------------------------------
 .../apache/slider/core/zk/ZKIntegration.java    | 18 ++++++++-
 .../common/tools/TestZKIntegration.groovy       | 41 +++++++++++++-------
 2 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/b88c7759/slider-core/src/main/java/org/apache/slider/core/zk/ZKIntegration.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/zk/ZKIntegration.java b/slider-core/src/main/java/org/apache/slider/core/zk/ZKIntegration.java
index 0d96559..0c28229 100644
--- a/slider-core/src/main/java/org/apache/slider/core/zk/ZKIntegration.java
+++ b/slider-core/src/main/java/org/apache/slider/core/zk/ZKIntegration.java
@@ -29,13 +29,14 @@ import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 
-public class ZKIntegration implements Watcher {
+public class ZKIntegration implements Watcher, Closeable {
 
 /**
  * Base path for services
@@ -115,7 +116,20 @@ public class ZKIntegration implements Watcher {
                              createClusterPath,
                              watchEventHandler);
   }
-  
+
+
+  @Override
+  public synchronized void close() throws IOException {
+    if (zookeeper != null) {
+      try {
+        zookeeper.close();
+      } catch (InterruptedException ignored) {
+
+      }
+      zookeeper = null;
+    }
+  }
+
   public String getConnectionString() {
     return zkConnection;
   }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/b88c7759/slider-core/src/test/groovy/org/apache/slider/common/tools/TestZKIntegration.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestZKIntegration.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestZKIntegration.groovy
index 460dafb..0aa1b91 100644
--- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestZKIntegration.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestZKIntegration.groovy
@@ -21,6 +21,8 @@ package org.apache.slider.common.tools
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.FileUtil
+import org.apache.hadoop.registry.server.services.MicroZookeeperServiceKeys
 import org.apache.slider.client.SliderClient
 import org.apache.slider.core.zk.ZKIntegration
 import org.apache.slider.test.KeysForTests
@@ -28,6 +30,7 @@ import org.apache.slider.test.YarnZKMiniClusterTestBase
 import org.apache.zookeeper.CreateMode
 import org.apache.zookeeper.ZooDefs
 import org.apache.zookeeper.data.Stat
+import org.junit.After
 import org.junit.Before
 import org.junit.Test
 
@@ -38,32 +41,46 @@ class TestZKIntegration extends YarnZKMiniClusterTestBase implements KeysForTest
 
   // as the static compiler doesn't resolve consistently
   public static final String USER = KeysForTests.USERNAME
+  private ZKIntegration zki
 
   @Before
   void createCluster() {
     Configuration conf = configuration
-    createMicroZKCluster(methodName.methodName, conf)
+    def name = methodName.methodName
+    File zkdir = new File("target/zk/${name}")
+    FileUtil.fullyDelete(zkdir);
+    conf.set(MicroZookeeperServiceKeys.KEY_ZKSERVICE_DIR, zkdir.absolutePath)
+    createMicroZKCluster("-"+ name, conf)
+  }
+
+  @After
+  void closeZKI() {
+    zki?.close()
+    zki = null;
   }
 
   @Test
   public void testIntegrationCreate() throws Throwable {
     assertHasZKCluster()
-    ZKIntegration zki = createZKIntegrationInstance(
-        getZKBinding(), "cluster1", true, false, 5000)
+    initZKI()
     String userPath = ZKIntegration.mkSliderUserPath(USER)
     Stat stat = zki.stat(userPath)
     assert stat != null
     log.info("User path $userPath has stat $stat")
   }
 
+  public ZKIntegration initZKI() {
+    zki = createZKIntegrationInstance(
+        getZKBinding(), methodName.methodName, true, false, 5000)
+    return zki
+  }
+
   @Test
   public void testListUserClustersWithoutAnyClusters() throws Throwable {
     assertHasZKCluster()
-
-    ZKIntegration zki = createZKIntegrationInstance(
-        getZKBinding(), "", true, false, 5000)
+    initZKI()
     String userPath = ZKIntegration.mkSliderUserPath(USER)
-    List<String> clusters = zki.clusters
+    List<String> clusters = this.zki.clusters
     assert clusters.empty
   }
 
@@ -71,8 +88,7 @@ class TestZKIntegration extends YarnZKMiniClusterTestBase implements KeysForTest
   public void testListUserClustersWithOneCluster() throws Throwable {
     assertHasZKCluster()
 
-    ZKIntegration zki = createZKIntegrationInstance(
-        getZKBinding(), methodName.methodName, true, false, 5000)
+    initZKI()
     String userPath = ZKIntegration.mkSliderUserPath(USER)
     String fullPath = zki.createPath(userPath, "/cluster-",
                                      ZooDefs.Ids.OPEN_ACL_UNSAFE,
@@ -85,8 +101,7 @@ class TestZKIntegration extends YarnZKMiniClusterTestBase implements KeysForTest
 
   @Test
   public void testListUserClustersWithTwoCluster() throws Throwable {
-    ZKIntegration zki = createZKIntegrationInstance(
-        getZKBinding(), methodName.methodName, true, false, 5000)
+    initZKI()
     String userPath = ZKIntegration.mkSliderUserPath(USER)
     String c1 = createEphemeralChild(zki, userPath)
     log.info("Ephemeral path $c1")
@@ -103,7 +118,7 @@ class TestZKIntegration extends YarnZKMiniClusterTestBase implements KeysForTest
     MockSliderClient client = new MockSliderClient()
 
     String path = client.createZookeeperNode("cl1", true)
-    ZKIntegration zki = client.lastZKIntegration
+    zki = client.lastZKIntegration
 
     String zkPath = ZKIntegration.mkClusterPath(USER, "cl1")
     assert zkPath == "/services/slider/users/" + USER + "/cl1", "zkPath must be as expected"
@@ -140,7 +155,7 @@ class TestZKIntegration extends YarnZKMiniClusterTestBase implements KeysForTest
 
     @Override
     protected ZKIntegration getZkClient(String clusterName, String user) {
-      zki = createZKIntegrationInstance(getZKBinding(), "cl1", true, false, 5000)
+      zki = createZKIntegrationInstance(getZKBinding(), clusterName, true, false, 5000)
       return zki;
     }