You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@distributedlog.apache.org by si...@apache.org on 2016/12/28 00:45:05 UTC

incubator-distributedlog git commit: DL-150: Ensure namespace path is created for TestZKLogMetadataForWriter

Repository: incubator-distributedlog
Updated Branches:
  refs/heads/master 48d29356f -> 1503e1994


DL-150: Ensure namespace path is created for TestZKLogMetadataForWriter

Author: Sijie Guo <si...@twitter.com>

Reviewers: Leigh Stewart <ls...@apache.org>

Closes #83 from sijie/sijie/FixTestCreateLogMetadata


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

Branch: refs/heads/master
Commit: 1503e1994dd575cf38f1c3811895d4e0c2c0ed78
Parents: 48d2935
Author: Sijie Guo <si...@twitter.com>
Authored: Tue Dec 27 16:45:43 2016 -0800
Committer: Sijie Guo <si...@apache.org>
Committed: Tue Dec 27 16:45:43 2016 -0800

----------------------------------------------------------------------
 .../metadata/TestZKLogMetadataForWriter.java    | 30 +++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/1503e199/distributedlog-core/src/test/java/com/twitter/distributedlog/impl/metadata/TestZKLogMetadataForWriter.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/test/java/com/twitter/distributedlog/impl/metadata/TestZKLogMetadataForWriter.java b/distributedlog-core/src/test/java/com/twitter/distributedlog/impl/metadata/TestZKLogMetadataForWriter.java
index 17e9ac7..648b828 100644
--- a/distributedlog-core/src/test/java/com/twitter/distributedlog/impl/metadata/TestZKLogMetadataForWriter.java
+++ b/distributedlog-core/src/test/java/com/twitter/distributedlog/impl/metadata/TestZKLogMetadataForWriter.java
@@ -29,20 +29,24 @@ import com.twitter.distributedlog.DistributedLogManager;
 import com.twitter.distributedlog.DistributedLogConstants;
 import com.twitter.distributedlog.exceptions.LogNotFoundException;
 import com.twitter.distributedlog.ZooKeeperClient;
-import com.twitter.distributedlog.ZooKeeperClientBuilder;
 import com.twitter.distributedlog.ZooKeeperClusterTestCase;
 import com.twitter.distributedlog.util.DLUtils;
 import com.twitter.distributedlog.util.FutureUtils;
 import com.twitter.distributedlog.util.Utils;
 import org.apache.bookkeeper.meta.ZkVersion;
+import org.apache.bookkeeper.util.ZkUtils;
 import org.apache.bookkeeper.versioning.Versioned;
 import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Transaction;
+import org.apache.zookeeper.ZooDefs;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.net.URI;
 import java.util.List;
@@ -55,12 +59,15 @@ import static org.junit.Assert.*;
  */
 public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
+    private static final Logger logger = LoggerFactory.getLogger(TestZKLogMetadataForWriter.class);
+
     private final static int sessionTimeoutMs = 30000;
 
     @Rule
     public TestName testName = new TestName();
 
     private ZooKeeperClient zkc;
+    private URI uri;
 
     private static void createLog(ZooKeeperClient zk, URI uri, String logName, String logIdentifier)
             throws Exception {
@@ -98,6 +105,17 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
                 .uri(DLMTestUtil.createDLMURI(zkPort, "/"))
                 .sessionTimeoutMs(sessionTimeoutMs)
                 .build();
+        uri = DLMTestUtil.createDLMURI(zkPort, "");
+        try {
+            ZkUtils.createFullPathOptimistic(
+                    zkc.get(),
+                    uri.getPath(),
+                    new byte[0],
+                    ZooDefs.Ids.OPEN_ACL_UNSAFE,
+                    CreateMode.PERSISTENT);
+        } catch (KeeperException.NodeExistsException nee) {
+            logger.debug("The namespace uri already exists.");
+        }
     }
 
     @After
@@ -187,7 +205,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingLogSegmentsPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -198,7 +215,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingMaxTxIdPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -209,7 +225,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingLockPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -220,7 +235,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingReadLockPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -231,7 +245,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingVersionPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -253,7 +266,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataMissingAllPath() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         String logRootPath = getLogRootPath(uri, logName, logIdentifier);
@@ -269,7 +281,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataOnExistedLog() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         List<String> pathsToDelete = Lists.newArrayList();
@@ -278,7 +289,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadata() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         List<String> pathsToDelete = Lists.newArrayList();
@@ -288,7 +298,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000, expected = LogNotFoundException.class)
     public void testCreateLogMetadataWithCreateIfNotExistsSetToFalse() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         FutureUtils.result(ZKLogMetadataForWriter.of(uri, logName, logIdentifier,
@@ -297,7 +306,6 @@ public class TestZKLogMetadataForWriter extends ZooKeeperClusterTestCase {
 
     @Test(timeout = 60000)
     public void testCreateLogMetadataWithCustomMetadata() throws Exception {
-        URI uri = DLMTestUtil.createDLMURI(zkPort, "");
         String logName = testName.getMethodName();
         String logIdentifier = "<default>";
         List<String> pathsToDelete = Lists.newArrayList();