Skip to content

Commit

Permalink
add TI for pulsar
Browse files Browse the repository at this point in the history
  • Loading branch information
jetoile committed Nov 1, 2019
1 parent 462bfb7 commit 8d52534
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 29 deletions.
1 change: 1 addition & 0 deletions sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<module>knox-hbase-webhdfs</module>
<module>redis</module>
<module>confluent-integrationtest</module>
<module>pulsar-integrationtest</module>
<module>docker-integrationtest</module>
<module>dockercompose-integrationtest</module>
</modules>
Expand Down
131 changes: 131 additions & 0 deletions sample/pulsar-integrationtest/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sample</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>3.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>pulsar-integrationtest</artifactId>

<properties>
<pulsar.version>2.4.1</pulsar.version>
</properties>

<dependencies>
<dependency>
<groupId>fr.jetoile.hadoop</groupId>
<artifactId>hadoop-unit-commons</artifactId>
</dependency>

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>4.3.1.Final</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
<version>${pulsar.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!travis</name>
</property>
</activation>

<build>
<plugins>
<plugin>
<artifactId>hadoop-unit-maven-plugin</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<executions>
<execution>
<id>start</id>
<goals>
<goal>embedded-start</goal>
</goals>
<phase>pre-integration-test</phase>
</execution>
<execution>
<id>embedded-stop</id>
<goals>
<goal>embedded-stop</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
<configuration>
<components>
<componentArtifact implementation="fr.jetoile.hadoopunit.ComponentArtifact">
<componentName>ZOOKEEPER</componentName>
<artifactId>hadoop-unit-zookeeper</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<mainClass>fr.jetoile.hadoopunit.component.ZookeeperBootstrap</mainClass>
</componentArtifact>
<componentArtifact implementation="fr.jetoile.hadoopunit.ComponentArtifact">
<componentName>BOOKKEEPER</componentName>
<artifactId>hadoop-unit-bookkeeper</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<mainClass>fr.jetoile.hadoopunit.component.BookkeeperBootstrap</mainClass>
</componentArtifact>
<componentArtifact implementation="fr.jetoile.hadoopunit.ComponentArtifact">
<componentName>PULSAR</componentName>
<artifactId>hadoop-unit-pulsar</artifactId>
<groupId>fr.jetoile.hadoop</groupId>
<version>${hadoop-unit.version}</version>
<mainClass>fr.jetoile.hadoopunit.component.PulsarBootstrap</mainClass>
</componentArtifact>
</components>

</configuration>

</plugin>
</plugins>
</build>

</profile>
<profile>
<id>travis</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>travis</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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<String> producer = client.newProducer(Schema.STRING)
Expand Down Expand Up @@ -92,4 +76,12 @@ public void pulsarShouldStart() throws PulsarClientException, MalformedURLExcept
client.close();
}

}
@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}]");
}
}

0 comments on commit 8d52534

Please sign in to comment.