ARTEMIS-1089 Moving smoke tests under ./tests/smoke-tests

This is moving the smoke tests creates as part of the relication tests.

They are also now based on junit tests.

And to support starting servers I am exposing basedir to unit tests in general.
This commit is contained in:
Clebert Suconic 2017-04-04 20:20:56 -04:00 committed by Martyn Taylor
parent f0ce8a85a2
commit dd27fb587f
14 changed files with 324 additions and 288 deletions

View File

@ -133,10 +133,5 @@ cd scale-down; mvn verify; cd ..
cd transaction-failover; mvn verify; cd ..
cd $ARTEMIS_HOME/examples/smoke/ha
cd replicated-flowcontrol; mvn verify; cd ..
cd $CURRENT_DIR
rm -rf target

View File

@ -96,7 +96,6 @@ under the License.
<modules>
<module>features</module>
<module>protocols</module>
<module>smoke</module>
</modules>
</project>

View File

@ -1,61 +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.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples.smoke</groupId>
<artifactId>smoke</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.activemq.examples.smoke.ha</groupId>
<artifactId>smoke-ha</artifactId>
<packaging>pom</packaging>
<name>ActiveMQ Artemis Failover Examples</name>
<!-- Properties -->
<properties>
<!--
Explicitly declaring the source encoding eliminates the following
message: [WARNING] Using platform encoding (UTF-8 actually) to copy
filtered resources, i.e. build is platform dependent!
-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<activemq.basedir>${project.basedir}/../../..</activemq.basedir>
</properties>
<profiles>
<profile>
<id>release</id>
<modules>
<module>replicated-flowcontrol</module>
</modules>
</profile>
<profile>
<id>examples</id>
<modules>
<module>replicated-flowcontrol</module>
</modules>
</profile>
</profiles>
</project>

View File

@ -1,112 +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.
-->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples.smoke.ha</groupId>
<artifactId>smoke-ha</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>replicated-flowcontrol</artifactId>
<packaging>jar</packaging>
<name>Smoke test for replication, simulating large flow conrol</name>
<properties>
<activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>${qpid.jms.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<!-- this makes it easier in certain envs -->
<javaOptions>-Djava.net.preferIPv4Stack=true</javaOptions>
<instance>${basedir}/target/server0</instance>
<configuration>${basedir}/target/classes/activemq/server0</configuration>
<javaOptions>-Dudp-address=${udp-address}</javaOptions>
</configuration>
</execution>
<execution>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<!-- this makes it easier in certain envs -->
<javaOptions>-Djava.net.preferIPv4Stack=true</javaOptions>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
<javaOptions>-Dudp-address=${udp-address}</javaOptions>
</configuration>
</execution>
<execution>
<id>runClient</id>
<goals>
<goal>runClient</goal>
</goals>
<configuration>
<clientClass>org.apache.activemq.artemis.jms.example.ReplicatedFailbackStaticSmoke</clientClass>
<args>
<param>${basedir}/target/server0</param>
<param>${basedir}/target/server1</param>
</args>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.smoke.ha</groupId>
<artifactId>replicated-flowcontrol</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,20 +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.
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=tcp://localhost:61616?ha=true&retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1
queue.queue/exampleQueue=exampleQueue

View File

@ -1,8 +0,0 @@
# Smoke Tests
Everything under this folder is not meant for "educational" purposes.
These represent production-like scenarios.
In cases where a testcase may be too short lived, we use these smoke tests
to validate production like scenarios

View File

@ -116,6 +116,7 @@
<skipJmsTests>true</skipJmsTests>
<skipExtraTests>true</skipExtraTests>
<skipIntegrationTests>true</skipIntegrationTests>
<skipSmokeTests>true</skipSmokeTests>
<skipJoramTests>true</skipJoramTests>
<skipTimingTests>true</skipTimingTests>
<skipStressTests>true</skipStressTests>
@ -150,7 +151,7 @@
<activemq-surefire-argline>-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dlogging.configuration="file:${activemq.basedir}/tests/config/logging.properties"
-Djava.library.path="${activemq.basedir}/artemis-native/bin" -Djgroups.bind_addr=localhost -Dorg.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory.localBindAddress=localhost
-Djava.net.preferIPv4Stack=true
-Djava.net.preferIPv4Stack=true -Dbasedir=${basedir}
</activemq-surefire-argline>
<activemq.basedir>${project.basedir}</activemq.basedir>
<skipLicenseCheck>true</skipLicenseCheck>
@ -831,6 +832,7 @@
<skipJmsTests>false</skipJmsTests>
<skipJoramTests>false</skipJoramTests>
<skipIntegrationTests>false</skipIntegrationTests>
<skipSmokeTests>false</skipSmokeTests>
<skipTimingTests>true</skipTimingTests>
<skipConcurrentTests>false</skipConcurrentTests>
<skipRestTests>false</skipRestTests>

View File

@ -130,5 +130,6 @@
<module>stress-tests</module>
<module>performance-tests</module>
<module>artemis-test-support</module>
<module>smoke-tests</module>
</modules>
</project>

View File

@ -22,13 +22,12 @@ under the License.
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.examples</groupId>
<artifactId>artemis-examples</artifactId>
<groupId>org.apache.activemq.tests</groupId>
<artifactId>artemis-tests-pom</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.activemq.examples.smoke</groupId>
<artifactId>smoke</artifactId>
<artifactId>smoke-tests</artifactId>
<packaging>pom</packaging>
<name>ActiveMQ Artemis Smoke Tests</name>
@ -43,18 +42,7 @@ under the License.
<activemq.basedir>${project.basedir}/../..</activemq.basedir>
</properties>
<profiles>
<profile>
<id>examples</id>
<modules>
<module>ha</module>
</modules>
</profile>
<profile>
<id>release</id>
<modules>
<module>ha</module>
</modules>
</profile>
</profiles>
<modules>
<module>replicated-flowcontrol</module>
</modules>
</project>

View File

@ -0,0 +1,6 @@
# Smoke tests
These tests are based on real servers.
Each directory here represents a real server created with the maven plugin.

View File

@ -0,0 +1,203 @@
<!--
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq.tests</groupId>
<artifactId>smoke-tests</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>
<artifactId>replicated-flowcontrol</artifactId>
<packaging>jar</packaging>
<name>Smoke Test Replicated</name>
<properties>
<activemq.basedir>${project.basedir}/../../../</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-core-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.activemq.tests</groupId>
<artifactId>unit-tests</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>apache-artemis</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-commons</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-ra</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ejb_3.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.components</groupId>
<artifactId>geronimo-jaspi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>${qpid.jms.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<id>create0</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<!-- this makes it easier in certain envs -->
<javaOptions>-Djava.net.preferIPv4Stack=true</javaOptions>
<instance>${basedir}/target/server0</instance>
<configuration>${basedir}/target/classes/activemq/server0</configuration>
</configuration>
</execution>
<execution>
<phase>install</phase>
<id>create1</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<!-- this makes it easier in certain envs -->
<javaOptions>-Djava.net.preferIPv4Stack=true</javaOptions>
<instance>${basedir}/target/server1</instance>
<configuration>${basedir}/target/classes/activemq/server1</configuration>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.smoke.ha</groupId>
<artifactId>replicated-flowcontrol</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipSmokeTests}</skipTests>
<argLine>${activemq-surefire-argline}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.jms.example;
package org.apache.activemq.artemis.tests.smoke.replicationflow;
import javax.jms.BytesMessage;
import javax.jms.Connection;
@ -23,24 +23,28 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.InitialContext;
import java.io.File;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.util.ServerUtil;
import org.apache.activemq.artemis.utils.ReusableLatch;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
/**
* Example of live and replicating backup pair.
* <p>
* After both servers are started, the live server is killed and the backup becomes active ("fails-over").
* <p>
* Later the live server is restarted and takes back its position by asking the backup to stop ("fail-back").
*/
public class ReplicatedFailbackStaticSmoke {
public class ReplicatedFailbackSmokeTest extends ActiveMQTestBase {
ArrayList<Consumer> consumers = new ArrayList<>();
String server0Location = System.getProperty("basedir") + "/target/server0";
String server1Location = System.getProperty("basedir") + "/target/server1";
private static Process server0;
@ -49,25 +53,47 @@ public class ReplicatedFailbackStaticSmoke {
static final int NUM_MESSAGES = 300_000;
static final int START_CONSUMERS = 100_000;
static final int START_SERVER = 101_000;
static final int KILL_SERVER = -1; // not killing the server right now.. just for future use
static final int NUMBER_OF_CONSUMERS = 10;
static final ReusableLatch latch = new ReusableLatch(NUM_MESSAGES);
static AtomicBoolean running = new AtomicBoolean(true);
static AtomicInteger totalConsumed = new AtomicInteger(0);
public static void main(final String[] args) throws Exception {
@Before
public void cleanupTests() throws Exception {
deleteDirectory(new File(server0Location, "data"));
deleteDirectory(new File(server1Location, "data"));
disableCheckThread();
}
@After
public void after() throws Exception {
ServerUtil.killServer(server0);
ServerUtil.killServer(server1);
}
@Test
public void testPageWhileSynchronizingReplica() throws Exception {
internalTest(false);
}
@Ignore // need to fix this before I can let it running
@Test
public void testPageWhileSyncFailover() throws Exception {
internalTest(true);
}
private void internalTest(boolean failover) throws Exception {
int KILL_SERVER = failover ? 150_000 : -1;
Connection connection = null;
InitialContext initialContext = null;
try {
server0 = ServerUtil.startServer(args[0], ReplicatedFailbackStaticSmoke.class.getSimpleName() + "0", 0, 30000);
server0 = ServerUtil.startServer(server0Location, ReplicatedFailbackSmokeTest.class.getSimpleName() + "0", 0, 30000);
initialContext = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connection = connectionFactory.createConnection();
@ -75,8 +101,6 @@ public class ReplicatedFailbackStaticSmoke {
Queue queue = session.createQueue("exampleQueue");
connection.start();
MessageProducer producer = session.createProducer(queue);
BytesMessage bytesMessage = session.createBytesMessage();
@ -92,17 +116,28 @@ public class ReplicatedFailbackStaticSmoke {
if (i == START_CONSUMERS) {
System.out.println("Starting consumers");
startConsumers();
startConsumers(!failover); // if failover, no AMQP
}
if (KILL_SERVER >= 0 && i == KILL_SERVER) {
session.commit();
System.out.println("Killing server");
ServerUtil.killServer(server0);
Thread.sleep(2000);
connection.close();
connection = connectionFactory.createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue("exampleQueue");
producer = session.createProducer(queue);
}
if (i == START_SERVER) {
System.out.println("Starting extra server");
server1 = ServerUtil.startServer(args[1], ReplicatedFailbackStaticSmoke.class.getSimpleName() + "1", 1, 10000);
server1 = ServerUtil.startServer(server1Location, ReplicatedFailbackSmokeTest.class.getSimpleName() + "1", 1, 10000);
}
}
@ -122,20 +157,18 @@ public class ReplicatedFailbackStaticSmoke {
connection.close();
}
if (initialContext != null) {
initialContext.close();
for (Consumer consumer : consumers) {
consumer.interrupt();
consumer.join();
}
ServerUtil.killServer(server0);
ServerUtil.killServer(server1);
}
}
static void startConsumers() {
void startConsumers(boolean useAMQP) {
for (int i = 0; i < NUMBER_OF_CONSUMERS; i++) {
Consumer consumer = new Consumer(i % 2 == 0, i);
Consumer consumer = new Consumer(useAMQP && i % 2 == 0, i);
consumer.start();
consumers.add(consumer);
}
}
@ -165,6 +198,9 @@ public class ReplicatedFailbackStaticSmoke {
}
void connect() throws Exception {
if (connection != null) {
connection.close();
}
count = 0;
if (amqp) {
factory = new JmsConnectionFactory("amqp://localhost:61616");
@ -181,39 +217,46 @@ public class ReplicatedFailbackStaticSmoke {
@Override
public void run() {
while (running.get()) {
try {
while (running.get()) {
try {
if (connection == null) {
connect();
}
totalCount++;
if (totalCount % 1000 == 0) {
System.out.println(this + " received " + totalCount + " messages");
}
BytesMessage message = (BytesMessage) consumer.receive(5000);
if (message == null) {
System.out.println("Consumer " + this + " couldn't get a message");
if (count > 0) {
session.commit();
latch.countDown(count);
totalConsumed.addAndGet(count);
count = 0;
}
} else {
count++;
if (count == 100) {
session.commit();
latch.countDown(count);
totalConsumed.addAndGet(count);
count = 0;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
try {
if (connection == null) {
connect();
}
totalCount++;
if (totalCount % 1000 == 0) {
System.out.println(this + " received " + totalCount + " messages");
}
BytesMessage message = (BytesMessage) consumer.receive(5000);
if (message == null) {
System.out.println("Consumer " + this + " couldn't get a message");
if (count > 0) {
session.commit();
latch.countDown(count);
totalConsumed.addAndGet(count);
count = 0;
}
} else {
count++;
if (count == 100) {
session.commit();
latch.countDown(count);
totalConsumed.addAndGet(count);
count = 0;
}
}
} catch (Exception e) {
e.printStackTrace();
connection.close();
} catch (Throwable ignored) {
}
}