Skip to content

Commit

Permalink
Split pulsar-client-and-admin-shade-test into two parts (apache#8716)
Browse files Browse the repository at this point in the history
Motivation
Add test for apache#8697 and other shade problems.

Modifications
splitting pulsar-client-and-admin-shade-test into two parts, before the pulsar-admin and pulsar-client shade tests were together, can cause some potential problems.

* Add CI test for shade package

* fix style

* fix license

* separate shade package

* fix pom.xml

* fix codestyle

* remove unused import

Co-authored-by: WeijieGuo <[email protected]>
  • Loading branch information
reswqa and WeijieGuo authored Dec 1, 2020
1 parent 91e2f83 commit 7f62bbc
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 38 deletions.
6 changes: 0 additions & 6 deletions tests/bc_2_0_0/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@

<dependencies>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions tests/bc_2_0_1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@

<dependencies>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<module>bc_2_0_0</module>
<module>bc_2_0_1</module>
<module>pulsar-client-all-shade-test</module>
<module>pulsar-client-and-admin-shade-test</module>
<module>pulsar-client-shade-test</module>
<module>pulsar-client-admin-shade-test</module>
</modules>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,25 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.pulsar.tests</groupId>
<artifactId>tests-parent</artifactId>
<version>2.8.0-SNAPSHOT</version>
</parent>

<artifactId>pulsar-client-and-admin-shade-test</artifactId>
<artifactId>pulsar-client-admin-shade-test</artifactId>
<packaging>jar</packaging>
<name>Apache Pulsar :: Tests :: Pulsar-Client-And-Admin-Shade Test</name>
<name>Apache Pulsar :: Tests :: Pulsar-Client-Admin-Shade Test</name>

<dependencies>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>test</scope>
</dependency>

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

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

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down Expand Up @@ -130,6 +116,4 @@
</build>
</profile>
</profiles>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- TODO: we have to put suite files in one file to avoid executing TESTNG test suites multiple times.
see {@link https://github.com/cbeust/testng/issues/508} -->
<suite name="Pulsar Shade Tests" verbose="2" annotations="JDK">
<test name="pulsar-client-and-admin-shade-suite" preserve-order="true" >
<test name="pulsar-client-admin-shade-suite" preserve-order="true" >
<classes>
<class name="org.apache.pulsar.tests.integration.SmokeTest" />
</classes>
Expand Down
6 changes: 0 additions & 6 deletions tests/pulsar-client-all-shade-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@

<dependencies>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client-all</artifactId>
Expand Down
120 changes: 120 additions & 0 deletions tests/pulsar-client-shade-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.pulsar.tests</groupId>
<artifactId>tests-parent</artifactId>
<version>2.8.0-SNAPSHOT</version>
</parent>

<artifactId>pulsar-client-shade-test</artifactId>
<packaging>jar</packaging>
<name>Apache Pulsar :: Tests :: Pulsar-Client-Shade Test</name>

<dependencies>

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

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- only run tests when -DShadeTests is specified //-->
<skipTests>true</skipTests>
<systemPropertyVariables>
<currentVersion>${project.version}</currentVersion>
<maven.buildDirectory>${project.build.directory}</maven.buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>ShadeTests</id>
<activation>
<property>
<name>ShadeTests</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<property>
<name>testRetryCount</name>
<value>0</value>
</property>
<property>
<name>listener</name>
<value>org.apache.pulsar.tests.PulsarTestListener,org.apache.pulsar.tests.AnnotationListener</value>
</property>
</properties>
<argLine>-Xmx2G -XX:MaxDirectMemorySize=8G
-Dio.netty.leakDetectionLevel=advanced
</argLine>
<skipTests>false</skipTests>
<suiteXmlFiles>
<file>src/test/resources/pulsar.xml</file>
</suiteXmlFiles>
<forkCount>1</forkCount>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.pulsar.tests.integration;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;

import java.time.Duration;

import static java.time.temporal.ChronoUnit.SECONDS;

public class PulsarContainer extends GenericContainer<PulsarContainer> {

public static final int PULSAR_PORT = 6650;
public static final int BROKER_HTTP_PORT = 8080;
public static final String DEFAULT_IMAGE_NAME = "apachepulsar/pulsar-test-latest-version:latest";

public PulsarContainer() {
this(DEFAULT_IMAGE_NAME);
}

public PulsarContainer(final String pulsarVersion) {
super(pulsarVersion);
withExposedPorts(BROKER_HTTP_PORT, PULSAR_PORT);
withCommand("/pulsar/bin/pulsar standalone");
waitingFor(new HttpWaitStrategy()
.forPort(BROKER_HTTP_PORT)
.forStatusCode(200)
.forPath("/admin/v2/namespaces/public/default")
.withStartupTimeout(Duration.of(300, SECONDS)));
}

public String getPlainTextPulsarBrokerUrl() {
return String.format("pulsar://%s:%s", this.getContainerIpAddress(), this.getMappedPort(PULSAR_PORT));
}

public String getPulsarAdminUrl() {
return String.format("http://%s:%s", this.getContainerIpAddress(), this.getMappedPort(BROKER_HTTP_PORT));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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.pulsar.tests.integration;

import lombok.Cleanup;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.SubscriptionType;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

public class SmokeTest {

private PulsarContainer pulsarContainer;

@BeforeClass
public void setup(){
pulsarContainer = new PulsarContainer();
pulsarContainer.start();
}

@Test
public void checkClient() throws PulsarClientException {

@Cleanup
PulsarClient client = PulsarClient.builder()
.serviceUrl(pulsarContainer.getPlainTextPulsarBrokerUrl())
.build();

final String inputTopic = "input";

Producer<String> producer = client.newProducer(Schema.STRING)
.topic(inputTopic)
.enableBatching(false)
.create();

Consumer<String> consumer = client.newConsumer(Schema.STRING)
.topic(inputTopic)
.subscriptionName("test-subs")
.ackTimeout(10, TimeUnit.SECONDS)
.subscriptionType(SubscriptionType.Exclusive)
.subscribe();

producer.send("Hello!");
Message<String> message = consumer.receive(10, TimeUnit.SECONDS);

Assert.assertEquals(message.getValue(), "Hello!");

}

@AfterClass
public void cleanup(){
pulsarContainer.stop();
}

}
30 changes: 30 additions & 0 deletions tests/pulsar-client-shade-test/src/test/resources/pulsar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
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.
-->
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<!-- TODO: we have to put suite files in one file to avoid executing TESTNG test suites multiple times.
see {@link https://github.com/cbeust/testng/issues/508} -->
<suite name="Pulsar Shade Tests" verbose="2" annotations="JDK">
<test name="pulsar-client-shade-suite" preserve-order="true" >
<classes>
<class name="org.apache.pulsar.tests.integration.SmokeTest" />
</classes>
</test>
</suite>

0 comments on commit 7f62bbc

Please sign in to comment.