accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [1/4] accumulo git commit: ACCUMULO-3000: Added tests for "existing ZooKeeper" functionality
Date Wed, 20 May 2015 16:55:59 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master a9d1ad4a7 -> acf60826e


ACCUMULO-3000: Added tests for "existing ZooKeeper" functionality


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0c069d1f
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0c069d1f
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0c069d1f

Branch: refs/heads/master
Commit: 0c069d1f5003fd309432765c863fb47c066a1d33
Parents: dd55a16
Author: Trent Nadeau <tanadeau@gmail.com>
Authored: Tue Apr 21 10:47:11 2015 -0400
Committer: Trent Nadeau <tanadeau@gmail.com>
Committed: Fri May 15 15:19:01 2015 -0400

----------------------------------------------------------------------
 .gitignore                                      |   1 +
 minicluster/pom.xml                             |  10 ++
 ...niAccumuloClusterExistingZooKeepersTest.java | 107 +++++++++++++++++++
 pom.xml                                         |  12 +++
 4 files changed, 130 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/0c069d1f/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 56204d2..f7db771 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@
 /.pydevproject
 /.idea
 /*.iml
+.*.swp

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0c069d1f/minicluster/pom.xml
----------------------------------------------------------------------
diff --git a/minicluster/pom.xml b/minicluster/pom.xml
index ff390f9..afd459c 100644
--- a/minicluster/pom.xml
+++ b/minicluster/pom.xml
@@ -105,6 +105,16 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.curator</groupId>
+      <artifactId>curator-framework</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.curator</groupId>
+      <artifactId>curator-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.easymock</groupId>
       <artifactId>easymock</artifactId>
       <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0c069d1f/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterExistingZooKeepersTest.java
----------------------------------------------------------------------
diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterExistingZooKeepersTest.java
b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterExistingZooKeepersTest.java
new file mode 100644
index 0000000..d9fb63e
--- /dev/null
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterExistingZooKeepersTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.minicluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.commons.io.FileUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.TestingServer;
+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;
+
+public class MiniAccumuloClusterExistingZooKeepersTest {
+  private static final File BASE_DIR = new File(
+          System.getProperty("user.dir") + "/target/mini-tests/" + MiniAccumuloClusterExistingZooKeepersTest.class.getName());
+
+  private static final String SECRET = "superSecret";
+
+  private static final Logger log = LoggerFactory.getLogger(MiniAccumuloClusterExistingZooKeepersTest.class);
+  private TestingServer zooKeeper;
+  private MiniAccumuloCluster accumulo;
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setupTestCluster() throws Exception {
+    assertTrue(BASE_DIR.mkdirs() || BASE_DIR.isDirectory());
+    File testDir = new File(BASE_DIR, testName.getMethodName());
+    FileUtils.deleteQuietly(testDir);
+    assertTrue(testDir.mkdir());
+
+    zooKeeper = new TestingServer();
+
+    MiniAccumuloConfig config = new MiniAccumuloConfig(testDir, SECRET);
+    config.setExistingZooKeepers(zooKeeper.getConnectString());
+    accumulo = new MiniAccumuloCluster(config);
+    accumulo.start();
+  }
+
+  @After
+  public void teardownTestCluster() {
+    if (accumulo != null) {
+      try {
+        accumulo.stop();
+      } catch (IOException | InterruptedException e) {
+        log.warn("Failure during tear down", e);
+      }
+    }
+
+    if (zooKeeper != null) {
+      try {
+        zooKeeper.close();
+      } catch (IOException e) {
+        log.warn("Failure stopping test ZooKeeper server");
+      }
+    }
+  }
+
+  @Test
+  public void canConnectViaExistingZooKeeper() throws Exception {
+    Connector conn = accumulo.getConnector("root", SECRET);
+    Instance instance = conn.getInstance();
+    assertEquals(zooKeeper.getConnectString(), instance.getZooKeepers());
+
+    String tableName = "foo";
+    conn.tableOperations().create(tableName);
+    Map<String,String> tableIds = conn.tableOperations().tableIdMap();
+    assertTrue(tableIds.containsKey(tableName));
+
+    String zkTablePath = String.format("/accumulo/%s/tables/%s/name", instance.getInstanceID(),
tableIds.get(tableName));
+    try (CuratorFramework client = CuratorFrameworkFactory.newClient(zooKeeper.getConnectString(),
new RetryOneTime(1))) {
+      client.start();
+      assertNotNull(client.checkExists().forPath(zkTablePath));
+      assertEquals(tableName, new String(client.getData().forPath(zkTablePath)));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0c069d1f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a6ac82c..4883639 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,6 +119,8 @@
     <accumulo.release.version>${project.version}</accumulo.release.version>
     <!-- bouncycastle version for test dependencies -->
     <bouncycastle.version>1.50</bouncycastle.version>
+    <!-- Curator version -->
+    <curator.version>2.7.1</curator.version>
     <!-- relative path for Eclipse format; should override in child modules if necessary
-->
     <eclipseFormatterStyle>${project.parent.basedir}/contrib/Eclipse-Accumulo-Codestyle.xml</eclipseFormatterStyle>
     <!-- findbugs-maven-plugin won't work on jdk8 or later; set to 3.0.0 or newer -->
@@ -355,6 +357,16 @@
         <version>2.0</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-framework</artifactId>
+        <version>${curator.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.curator</groupId>
+        <artifactId>curator-test</artifactId>
+        <version>${curator.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-client</artifactId>
         <version>${hadoop.version}</version>


Mime
View raw message