From 8d52534f608eec861a2e0ce6f5d50353c0eddaca Mon Sep 17 00:00:00 2001 From: jetoile Date: Fri, 1 Nov 2019 13:27:34 +0100 Subject: [PATCH] add TI for pulsar --- sample/pom.xml | 1 + sample/pulsar-integrationtest/pom.xml | 131 ++++++++++++++++++ .../sample/pulsar/PulsarIntegrationTest.java | 50 +++---- .../resources/hadoop-unit-default.properties | 0 4 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 sample/pulsar-integrationtest/pom.xml rename hadoop-unit-pulsar/src/test/java/fr/jetoile/hadoopunit/component/PulsarBootstrapTest.java => sample/pulsar-integrationtest/src/test/java/fr/jetoile/hadoopunit/sample/pulsar/PulsarIntegrationTest.java (68%) rename {hadoop-unit-pulsar => sample/pulsar-integrationtest}/src/test/resources/hadoop-unit-default.properties (100%) diff --git a/sample/pom.xml b/sample/pom.xml index 302c0c56..6242b370 100644 --- a/sample/pom.xml +++ b/sample/pom.xml @@ -20,6 +20,7 @@ knox-hbase-webhdfs redis confluent-integrationtest + pulsar-integrationtest docker-integrationtest dockercompose-integrationtest diff --git a/sample/pulsar-integrationtest/pom.xml b/sample/pulsar-integrationtest/pom.xml new file mode 100644 index 00000000..77c8f977 --- /dev/null +++ b/sample/pulsar-integrationtest/pom.xml @@ -0,0 +1,131 @@ + + + + sample + fr.jetoile.hadoop + 3.6-SNAPSHOT + + 4.0.0 + + pulsar-integrationtest + + + 2.4.1 + + + + + fr.jetoile.hadoop + hadoop-unit-commons + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + test + + + + org.jboss.resteasy + resteasy-client + 4.3.1.Final + test + + + + org.apache.pulsar + pulsar-client + ${pulsar.version} + test + + + + + + default + + true + + !travis + + + + + + + hadoop-unit-maven-plugin + fr.jetoile.hadoop + ${hadoop-unit.version} + + + start + + embedded-start + + pre-integration-test + + + embedded-stop + + embedded-stop + + post-integration-test + + + + + + ZOOKEEPER + hadoop-unit-zookeeper + fr.jetoile.hadoop + ${hadoop-unit.version} + fr.jetoile.hadoopunit.component.ZookeeperBootstrap + + + BOOKKEEPER + hadoop-unit-bookkeeper + fr.jetoile.hadoop + ${hadoop-unit.version} + fr.jetoile.hadoopunit.component.BookkeeperBootstrap + + + PULSAR + hadoop-unit-pulsar + fr.jetoile.hadoop + ${hadoop-unit.version} + fr.jetoile.hadoopunit.component.PulsarBootstrap + + + + + + + + + + + + travis + + false + + travis + + + + + + maven-surefire-plugin + + true + + + + + + + + \ No newline at end of file diff --git a/hadoop-unit-pulsar/src/test/java/fr/jetoile/hadoopunit/component/PulsarBootstrapTest.java b/sample/pulsar-integrationtest/src/test/java/fr/jetoile/hadoopunit/sample/pulsar/PulsarIntegrationTest.java similarity index 68% rename from hadoop-unit-pulsar/src/test/java/fr/jetoile/hadoopunit/component/PulsarBootstrapTest.java rename to sample/pulsar-integrationtest/src/test/java/fr/jetoile/hadoopunit/sample/pulsar/PulsarIntegrationTest.java index e8e51d39..fe8e2057 100644 --- a/hadoop-unit-pulsar/src/test/java/fr/jetoile/hadoopunit/component/PulsarBootstrapTest.java +++ b/sample/pulsar-integrationtest/src/test/java/fr/jetoile/hadoopunit/sample/pulsar/PulsarIntegrationTest.java @@ -1,51 +1,36 @@ -/* - * Licensed 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 fr.jetoile.hadoopunit.component; - -import fr.jetoile.hadoopunit.HadoopBootstrap; +package fr.jetoile.hadoopunit.sample.pulsar; + import fr.jetoile.hadoopunit.HadoopUnitConfig; import fr.jetoile.hadoopunit.exception.BootstrapException; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.pulsar.client.admin.PulsarAdminException; import org.apache.pulsar.client.api.*; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.MalformedURLException; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Response; import java.util.concurrent.TimeUnit; import static org.assertj.core.api.Assertions.assertThat; -@Ignore -public class PulsarBootstrapTest { +public class PulsarIntegrationTest { - private static final Logger LOGGER = LoggerFactory.getLogger(PulsarBootstrapTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(PulsarIntegrationTest.class); private static final String TOPIC = "hello"; private static final int NUM_OF_MESSAGES = 100; + private static final String PULSAR_IP_CLIENT_KEY = "pulsar.client.ip"; + private static final String PULSAR_PORT_KEY = "pulsar.port"; + private static final String PULSAR_HTTP_PORT_KEY = "pulsar.http.port"; static private Configuration configuration; @BeforeClass public static void setup() throws BootstrapException { -// HadoopBootstrap.INSTANCE.startAll(); - try { configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE); } catch (ConfigurationException e) { @@ -56,13 +41,12 @@ public static void setup() throws BootstrapException { @AfterClass public static void tearDown() throws BootstrapException { -// HadoopBootstrap.INSTANCE.stopAll(); } @Test - public void pulsarShouldStart() throws PulsarClientException, MalformedURLException, PulsarAdminException { + public void pulsarShouldStart() throws PulsarClientException { final PulsarClient client = PulsarClient.builder() - .serviceUrl("pulsar://" + configuration.getString(PulsarConfig.PULSAR_IP_CLIENT_KEY) + ":" + configuration.getInt(PulsarConfig.PULSAR_PORT_KEY)) + .serviceUrl("pulsar://" + configuration.getString(PULSAR_IP_CLIENT_KEY) + ":" + configuration.getInt(PULSAR_PORT_KEY)) .build(); final Producer producer = client.newProducer(Schema.STRING) @@ -92,4 +76,12 @@ public void pulsarShouldStart() throws PulsarClientException, MalformedURLExcept client.close(); } -} \ No newline at end of file + @Test + public void functionWorker_should_response() { + Client client = ClientBuilder.newClient(); + + String response = client.target("http://" + configuration.getString(PULSAR_IP_CLIENT_KEY) + ":" + configuration.getInt(PULSAR_HTTP_PORT_KEY) + "/admin/v2/worker/cluster").request().get(String.class); + + assertThat(response).isEqualTo("[{\"workerId\":\"c-pulsar-cluster-1-fw-127.0.0.1-22023\",\"workerHostname\":\"127.0.0.1\",\"port\":22023}]"); + } +} diff --git a/hadoop-unit-pulsar/src/test/resources/hadoop-unit-default.properties b/sample/pulsar-integrationtest/src/test/resources/hadoop-unit-default.properties similarity index 100% rename from hadoop-unit-pulsar/src/test/resources/hadoop-unit-default.properties rename to sample/pulsar-integrationtest/src/test/resources/hadoop-unit-default.properties