You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by co...@apache.org on 2017/06/21 10:11:27 UTC

sentry git commit: SENTRY-1809 - Use Apache Curator in the Kafka tests

Repository: sentry
Updated Branches:
  refs/heads/master a2cff586d -> 28f9610a8


SENTRY-1809 - Use Apache Curator in the Kafka tests


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/28f9610a
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/28f9610a
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/28f9610a

Branch: refs/heads/master
Commit: 28f9610a8973e79dbf1faa0b0c06f1b930cc4ddf
Parents: a2cff58
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Wed Jun 21 11:10:57 2017 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Wed Jun 21 11:10:57 2017 +0100

----------------------------------------------------------------------
 sentry-tests/sentry-tests-kafka/pom.xml         |  5 ++
 .../tests/e2e/kafka/EmbeddedZkServer.java       | 71 --------------------
 .../sentry/tests/e2e/kafka/KafkaTestServer.java | 13 ++--
 3 files changed, 11 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/28f9610a/sentry-tests/sentry-tests-kafka/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-kafka/pom.xml b/sentry-tests/sentry-tests-kafka/pom.xml
index 4c0ae77..48dd145 100644
--- a/sentry-tests/sentry-tests-kafka/pom.xml
+++ b/sentry-tests/sentry-tests-kafka/pom.xml
@@ -61,6 +61,11 @@ limitations under the License.
       <artifactId>sentry-service-server</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.curator</groupId>
+      <artifactId>curator-framework</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <profiles>
     <profile>

http://git-wip-us.apache.org/repos/asf/sentry/blob/28f9610a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/EmbeddedZkServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/EmbeddedZkServer.java b/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/EmbeddedZkServer.java
deleted file mode 100644
index 442ddff..0000000
--- a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/EmbeddedZkServer.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.sentry.tests.e2e.kafka;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-public class EmbeddedZkServer {
-    private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedZkServer.class);
-
-    private Path snapshotDir = null;
-    private Path logDir = null;
-    private ZooKeeperServer zookeeper = null;
-    private NIOServerCnxnFactory factory = null;
-
-    public EmbeddedZkServer(int port) throws Exception {
-        snapshotDir = Files.createTempDirectory("zookeeper-snapshot-");
-        logDir = Files.createTempDirectory("zookeeper-log-");
-        int tickTime = 500;
-        zookeeper = new ZooKeeperServer(snapshotDir.toFile(), logDir.toFile(), tickTime);
-        factory = new NIOServerCnxnFactory();
-        InetSocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port);
-        LOGGER.info("Starting Zookeeper at " + addr);
-        factory.configure(addr, 0);
-        factory.startup(zookeeper);
-    }
-
-    public void shutdown() throws IOException {
-        try {
-            zookeeper.shutdown();
-        } catch (Exception e) {
-            LOGGER.error("Failed to shutdown ZK server", e);
-        }
-
-        try {
-            factory.shutdown();
-        } catch (Exception e) {
-            LOGGER.error("Failed to shutdown Zk connection factory.", e);
-        }
-
-        FileUtils.deleteDirectory(logDir.toFile());
-        FileUtils.deleteDirectory(snapshotDir.toFile());
-    }
-
-    public ZooKeeperServer getZk() {
-        return zookeeper;
-    }
-}

http://git-wip-us.apache.org/repos/asf/sentry/blob/28f9610a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/KafkaTestServer.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/KafkaTestServer.java b/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/KafkaTestServer.java
index b82c028..e7273ee 100644
--- a/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/KafkaTestServer.java
+++ b/sentry-tests/sentry-tests-kafka/src/main/java/org/apache/sentry/tests/e2e/kafka/KafkaTestServer.java
@@ -18,6 +18,8 @@
 package org.apache.sentry.tests.e2e.kafka;
 
 import kafka.server.KafkaServerStartable;
+
+import org.apache.curator.test.TestingServer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,15 +34,13 @@ import java.util.Properties;
 public class KafkaTestServer {
     private static final Logger LOGGER = LoggerFactory.getLogger(KafkaTestServer.class);
 
-    private int zkPort = -1;
     private int kafkaPort = -1;
-    private EmbeddedZkServer zkServer = null;
+    private TestingServer zkServer;
     private KafkaServerStartable kafkaServer = null;
     private File sentrySitePath = null;
 
     public KafkaTestServer(File sentrySitePath) throws Exception {
         this.sentrySitePath = sentrySitePath;
-        this.zkPort = TestUtils.getFreePort();
         createZkServer();
         this.kafkaPort = TestUtils.getFreePort();
         createKafkaServer();
@@ -60,7 +60,7 @@ public class KafkaTestServer {
 
         if (zkServer != null) {
             try {
-                zkServer.shutdown();
+                zkServer.stop();
                 LOGGER.info("Stopped ZK server.");
             } catch (IOException e) {
                 LOGGER.error("Failed to shutdown ZK server.", e);
@@ -82,7 +82,7 @@ public class KafkaTestServer {
     private void setupKafkaProps(Properties props) throws UnknownHostException {
         props.put("listeners", "SSL://" + InetAddress.getLocalHost().getHostAddress() + ":" + kafkaPort);
         props.put("log.dir", getTempDirectory().toAbsolutePath().toString());
-        props.put("zookeeper.connect", InetAddress.getLocalHost().getHostAddress() + ":" + zkPort);
+        props.put("zookeeper.connect", zkServer.getConnectString());
         props.put("replica.socket.timeout.ms", "1500");
         props.put("controller.socket.timeout.ms", "1500");
         props.put("controlled.shutdown.enable", true);
@@ -110,8 +110,7 @@ public class KafkaTestServer {
 
     private void createZkServer() throws Exception {
         try {
-            zkServer = new EmbeddedZkServer(zkPort);
-            zkPort = zkServer.getZk().getClientPort();
+            zkServer = new TestingServer();
         } catch (Exception e) {
             LOGGER.error("Failed to create testing zookeeper server.");
             throw new RuntimeException(e);