sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject sentry git commit: SENTRY-1809 - Use Apache Curator in the Kafka tests
Date Thu, 22 Jun 2017 09:52:24 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign a785d29c9 -> c3e92f2f7


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/c3e92f2f
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/c3e92f2f
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/c3e92f2f

Branch: refs/heads/sentry-ha-redesign
Commit: c3e92f2f7e7361ee9f686b055949f85e63cbd96a
Parents: a785d29
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Jun 21 11:10:57 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Jun 22 09:38:16 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/c3e92f2f/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 44ee045..5a3374c 100644
--- a/sentry-tests/sentry-tests-kafka/pom.xml
+++ b/sentry-tests/sentry-tests-kafka/pom.xml
@@ -60,6 +60,11 @@ limitations under the License.
       <groupId>org.apache.sentry</groupId>
       <artifactId>sentry-provider-db</artifactId>
     </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/c3e92f2f/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/c3e92f2f/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);


Mime
View raw message