This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 60a07e9 Migrate CLI integration test mode to use testcontainers
(#2060)
60a07e9 is described below
commit 60a07e981c001cb42e732c76553fd42ea4feee64
Author: Sijie Guo <[email protected]>
AuthorDate: Mon Jul 2 00:16:19 2018 -0700
Migrate CLI integration test mode to use testcontainers (#2060)
---
.../pulsar/tests/topologies/PulsarCluster.java | 8 +-
tests/integration/cli/pom.xml | 10 +-
.../apache/pulsar/tests/integration/TestCLI.java | 191 ++++++++++-----------
.../cli/src/test/resources/arquillian.xml | 32 ----
4 files changed, 101 insertions(+), 140 deletions(-)
diff --git
a/tests/integration-tests-topologies/src/main/java/org/apache/pulsar/tests/topologies/PulsarCluster.java
b/tests/integration-tests-topologies/src/main/java/org/apache/pulsar/tests/topologies/PulsarCluster.java
index 9e2860f..167908e 100644
---
a/tests/integration-tests-topologies/src/main/java/org/apache/pulsar/tests/topologies/PulsarCluster.java
+++
b/tests/integration-tests-topologies/src/main/java/org/apache/pulsar/tests/topologies/PulsarCluster.java
@@ -23,6 +23,7 @@ import static
org.apache.pulsar.tests.containers.PulsarContainer.CS_PORT;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -45,7 +46,8 @@ import org.testcontainers.containers.Network;
@Slf4j
public class PulsarCluster {
- protected static final String ADMIN_SCRIPT = "/pulsar/bin/pulsar-admin";
+ public static final String ADMIN_SCRIPT = "/pulsar/bin/pulsar-admin";
+ public static final String CLIENT_SCRIPT = "/pulsar/bin/pulsar-client";
/**
* Pulsar Cluster Spec.
@@ -183,6 +185,10 @@ public class PulsarCluster {
return brokerList.get(0);
}
+ public Collection<BrokerContainer> getBrokers() {
+ return brokerContainers.values();
+ }
+
public ExecResult runAdminCommandOnAnyBroker(String...commands) throws
Exception {
BrokerContainer container = getAnyBroker();
String[] cmds = new String[commands.length + 1];
diff --git a/tests/integration/cli/pom.xml b/tests/integration/cli/pom.xml
index 9d960ac..5a05b4e 100644
--- a/tests/integration/cli/pom.xml
+++ b/tests/integration/cli/pom.xml
@@ -27,9 +27,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.pulsar.tests</groupId>
- <artifactId>integration-tests-base</artifactId>
+ <artifactId>integration</artifactId>
<version>2.2.0-incubating-SNAPSHOT</version>
- <relativePath>../../integration-tests-base</relativePath>
</parent>
<groupId>org.apache.pulsar.tests.integration</groupId>
@@ -42,6 +41,13 @@
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
<version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pulsar.tests</groupId>
+ <artifactId>integration-tests-topologies</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
diff --git
a/tests/integration/cli/src/test/java/org/apache/pulsar/tests/integration/TestCLI.java
b/tests/integration/cli/src/test/java/org/apache/pulsar/tests/integration/TestCLI.java
index e4a67c1..fdb19cd 100644
---
a/tests/integration/cli/src/test/java/org/apache/pulsar/tests/integration/TestCLI.java
+++
b/tests/integration/cli/src/test/java/org/apache/pulsar/tests/integration/TestCLI.java
@@ -18,47 +18,41 @@
*/
package org.apache.pulsar.tests.integration;
-import static org.testng.Assert.fail;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
-import com.github.dockerjava.api.DockerClient;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.pulsar.tests.DockerUtils;
-import org.apache.pulsar.tests.PulsarClusterUtils;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.arquillian.testng.Arquillian;
+import org.apache.pulsar.tests.containers.BrokerContainer;
+import org.apache.pulsar.tests.topologies.PulsarCluster;
+import org.apache.pulsar.tests.topologies.PulsarClusterTestBase;
+import org.testcontainers.containers.Container.ExecResult;
import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-public class TestCLI extends Arquillian {
- private static String clusterName = "test";
-
- @ArquillianResource
- DockerClient docker;
-
- @BeforeMethod
- public void waitServicesUp() throws Exception {
- Assert.assertTrue(PulsarClusterUtils.waitZooKeeperUp(docker,
clusterName, 30, TimeUnit.SECONDS));
- Assert.assertTrue(PulsarClusterUtils.waitAllBrokersUp(docker,
clusterName));
- }
+/**
+ * Test Pulsar CLI.
+ */
+public class TestCLI extends PulsarClusterTestBase {
@Test
public void testDeprecatedCommands() throws Exception {
- String broker = PulsarClusterUtils.brokerSet(docker,
clusterName).stream().findAny().get();
-
- Assert.assertFalse(DockerUtils.runCommand(docker, broker,
"/pulsar/bin/pulsar-admin", "--help")
- .contains("Usage: properties "));
- Assert.assertTrue(DockerUtils.runCommand(docker, broker,
- "/pulsar/bin/pulsar-admin",
"properties",
- "create",
"compaction-test-cli", "--allowed-clusters", clusterName,
- "--admin-roles",
"admin").contains("deprecated"));
- Assert.assertTrue(DockerUtils.runCommand(docker, broker,
"/pulsar/bin/pulsar-admin", "properties", "list")
- .contains("compaction-test-cli"));
- Assert.assertTrue(DockerUtils.runCommand(docker, broker,
"/pulsar/bin/pulsar-admin", "tenants", "list")
- .contains("compaction-test-cli"));
-
+ String tenantName = "test-deprecated-commands";
+
+ ExecResult result = pulsarCluster.runAdminCommandOnAnyBroker("--help");
+ assertFalse(result.getStdout().isEmpty());
+ assertFalse(result.getStdout().contains("Usage: properties "));
+ result = pulsarCluster.runAdminCommandOnAnyBroker(
+ "properties", "create", tenantName,
+ "--allowed-clusters", pulsarCluster.getClusterName(),
+ "--admin-roles", "admin"
+ );
+ assertTrue(result.getStderr().contains("deprecated"));
+
+ result = pulsarCluster.runAdminCommandOnAnyBroker(
+ "properties", "list");
+ assertTrue(result.getStdout().contains(tenantName));
+ result = pulsarCluster.runAdminCommandOnAnyBroker(
+ "tenants", "list");
+ assertTrue(result.getStdout().contains(tenantName));
}
@Test
@@ -68,119 +62,106 @@ public class TestCLI extends Arquillian {
String subscriptionPrefix = "subscription-";
int i = 0;
- for (String b : PulsarClusterUtils.brokerSet(docker, clusterName)) {
- Assert.assertTrue(
- DockerUtils.runCommand(docker, b,
- "/pulsar/bin/pulsar-admin",
- "persistent",
- "create-subscription",
- "persistent://public/default/" + topic,
- "--subscription",
- subscriptionPrefix + i
- ).isEmpty()
+ for (BrokerContainer container : pulsarCluster.getBrokers()) {
+ ExecResult result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
+ "persistent",
+ "create-subscription",
+ "persistent://public/default/" + topic,
+ "--subscription",
+ "" + subscriptionPrefix + i
);
+ assertTrue(result.getStdout().isEmpty());
+ assertTrue(result.getStderr().isEmpty());
i++;
}
}
@Test
public void testTopicTerminationOnTopicsWithoutConnectedConsumers() throws
Exception {
- String broker = PulsarClusterUtils.brokerSet(docker,
clusterName).stream().findAny().get();
-
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-client",
+ String topicName =
"persistent://public/default/test-topic-termination";
+ BrokerContainer container = pulsarCluster.getAnyBroker();
+ ExecResult result = container.execCmd(
+ PulsarCluster.CLIENT_SCRIPT,
"produce",
"-m",
"\"test topic termination\"",
"-n",
"1",
- "persistent://public/default/test-topic-termination"
- ).contains("1 messages successfully produced"));
+ topicName);
+
+ Assert.assertTrue(result.getStdout().contains("1 messages successfully
produced"));
// terminate the topic
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-admin",
+ result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
"persistent",
"terminate",
- "persistent://public/default/test-topic-termination"
- ).contains("Topic succesfully terminated at"));
+ topicName);
+ Assert.assertTrue(result.getStdout().contains("Topic succesfully
terminated at"));
// try to produce should fail
-
- try {
- DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-client",
- "produce",
- "-m",
- "\"test topic termination\"",
- "-n",
- "1",
- "persistent://public/default/test-topic-termination"
- );
- fail("Should fail to produce messages to a terminated topic");
- } catch (RuntimeException re) {
- // expected
- }
+ result = pulsarCluster.getAnyBroker().execCmd(
+ PulsarCluster.CLIENT_SCRIPT,
+ "produce",
+ "-m",
+ "\"test topic termination\"",
+ "-n",
+ "1",
+ topicName);
+ assertTrue(result.getStdout().contains("Topic was already
terminated"));
}
@Test
public void testSchemaCLI() throws Exception {
- String broker = PulsarClusterUtils.brokerSet(docker,
clusterName).stream().findAny().get();
+ BrokerContainer container = pulsarCluster.getAnyBroker();
+ String topicName = "persistent://public/default/test-schema-cli";
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-client",
+ ExecResult result = container.execCmd(
+ PulsarCluster.CLIENT_SCRIPT,
"produce",
"-m",
"\"test topic schema\"",
"-n",
"1",
- "persistent://public/default/test-schema-cli"
- ).contains("1 messages successfully produced"));
+ topicName);
+ Assert.assertTrue(result.getStdout().contains("1 messages successfully
produced"));
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-admin",
+ result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
"schemas",
"upload",
- "persistent://public/default/test-schema-cli",
+ topicName,
"-f",
"/pulsar/conf/schema_example.conf"
- ).isEmpty());
+ );
+ Assert.assertTrue(result.getStdout().isEmpty());
+ Assert.assertTrue(result.getStderr().isEmpty());
// get schema
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-admin",
+ result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
"schemas",
"get",
- "persistent://public/default/test-schema-cli"
- ).contains("\"type\" : \"STRING\""));
+ topicName);
+ Assert.assertTrue(result.getStdout().contains("\"type\" :
\"STRING\""));
// delete the schema
- Assert.assertTrue(DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-admin",
+ result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
"schemas",
"delete",
- "persistent://public/default/test-schema-cli"
- ).isEmpty());
+ topicName);
+ Assert.assertTrue(result.getStdout().isEmpty());
+ Assert.assertTrue(result.getStderr().isEmpty());
// get schema again
- try {
- DockerUtils.runCommand(
- docker, broker,
- "/pulsar/bin/pulsar-admin",
- "schemas",
- "get",
- "persistent://public/default/test-schema-cli"
- );
- fail("Should fail to get schema if the schema is deleted");
- } catch (RuntimeException re) {
- // expected
- }
+ result = container.execCmd(
+ PulsarCluster.ADMIN_SCRIPT,
+ "schemas",
+ "get",
+ "persistent://public/default/test-schema-cli"
+ );
+ assertTrue(result.getStderr().contains("Reason: HTTP 404 Not Found"));
}
}
diff --git a/tests/integration/cli/src/test/resources/arquillian.xml
b/tests/integration/cli/src/test/resources/arquillian.xml
deleted file mode 100644
index 821d6e6..0000000
--- a/tests/integration/cli/src/test/resources/arquillian.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.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.
-
--->
-<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://jboss.org/schema/arquillian"
- xsi:schemaLocation="http://jboss.org/schema/arquillian
-
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
-
- <extension qualifier="docker">
- <property name="definitionFormat">CUBE</property>
- <property
name="dockerContainersResource">cube-definitions/single-cluster-3-bookie-2-broker.yaml</property>
- </extension>
-
-</arquillian>