Repository: activemq-artemis Updated Branches: refs/heads/master 582907f31 -> 2edc972c5
ARTEMIS-1089 Simplifying smoke tests Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/c767e93b Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/c767e93b Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/c767e93b Branch: refs/heads/master Commit: c767e93bf53f4ed51f7d771a2e5183b25ff08bf7 Parents: 582907f Author: Clebert Suconic <[email protected]> Authored: Wed Apr 5 10:25:28 2017 -0400 Committer: Clebert Suconic <[email protected]> Committed: Wed Apr 5 15:55:09 2017 -0400 ---------------------------------------------------------------------- .../activemq/artemis/util/ServerUtil.java | 9 + tests/smoke-tests/pom.xml | 217 +++++++++++++-- .../smoke-tests/replicated-flowcontrol/pom.xml | 203 -------------- .../main/resources/activemq/server0/broker.xml | 118 -------- .../main/resources/activemq/server1/broker.xml | 121 --------- .../ReplicatedFailbackSmokeTest.java | 268 ------------------ .../servers/replicated-static0/broker.xml | 118 ++++++++ .../servers/replicated-static1/broker.xml | 121 +++++++++ .../tests/smoke/common/SmokeTestBase.java | 62 +++++ .../ReplicationFlowControlTest.java | 270 +++++++++++++++++++ 10 files changed, 768 insertions(+), 739 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/artemis-cli/src/main/java/org/apache/activemq/artemis/util/ServerUtil.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/util/ServerUtil.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/util/ServerUtil.java index fa443b5..405e777 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/util/ServerUtil.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/util/ServerUtil.java @@ -39,6 +39,15 @@ public class ServerUtil { return startServer(artemisInstance, serverName, 0, 0); } + /** + * + * @param artemisInstance + * @param serverName it will be used on logs + * @param id it will be used to add on the port + * @param timeout + * @return + * @throws Exception + */ public static Process startServer(String artemisInstance, String serverName, int id, int timeout) throws Exception { boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win"); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/pom.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml index 89ea128..4b06386 100644 --- a/tests/smoke-tests/pom.xml +++ b/tests/smoke-tests/pom.xml @@ -1,26 +1,21 @@ -<?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 + 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. + 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>artemis-tests-pom</artifactId> @@ -28,21 +23,185 @@ under the License. </parent> <artifactId>smoke-tests</artifactId> - <packaging>pom</packaging> - <name>ActiveMQ Artemis Smoke Tests</name> + <packaging>jar</packaging> + <name>Smoke Tests</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> + <activemq.basedir>${project.basedir}/../../</activemq.basedir> </properties> - <modules> - <module>replicated-flowcontrol</module> - </modules> + <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> + <!-- this dependency is here to make sure this module is only executed + after the distribution is created. + Otherwise it will get here before the build eventually. + e.g if you use mvn install -T 20 --> + <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>test-compile</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/replicated-static0</instance> + <configuration>${basedir}/target/classes/servers/replicated-static0</configuration> + </configuration> + </execution> + <execution> + <phase>test-compile</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/replicated-static1</instance> + <configuration>${basedir}/target/classes/servers/replicated-static1</configuration> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.apache.activemq.tests</groupId> + <artifactId>smoke-tests</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> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/replicated-flowcontrol/pom.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/replicated-flowcontrol/pom.xml b/tests/smoke-tests/replicated-flowcontrol/pom.xml deleted file mode 100644 index fd22c59..0000000 --- a/tests/smoke-tests/replicated-flowcontrol/pom.xml +++ /dev/null @@ -1,203 +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. ---> -<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> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server0/broker.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server0/broker.xml b/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server0/broker.xml deleted file mode 100644 index 0e58838..0000000 --- a/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server0/broker.xml +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- -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. ---><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - - - <core xmlns="urn:activemq:core"> - - <bindings-directory>./data/bindings</bindings-directory> - - <journal-directory>./data/journal</journal-directory> - - <large-messages-directory>./data/largemessages</large-messages-directory> - - <paging-directory>./data/paging</paging-directory> - - <cluster-user>exampleUser</cluster-user> - - <cluster-password>secret</cluster-password> - - <ha-policy> - <replication> - <master> - <!--we need this for auto failback--> - <check-for-live-server>true</check-for-live-server> - </master> - </replication> - </ha-policy> - - <connectors> - <connector name="netty-connector">tcp://localhost:61616</connector> - <connector name="netty-backup-connector">tcp://localhost:61617</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> - </acceptors> - - <cluster-connections> - <cluster-connection name="my-cluster"> - <connector-ref>netty-connector</connector-ref> - <static-connectors> - <connector-ref>netty-backup-connector</connector-ref> - </static-connectors> - </cluster-connection> - </cluster-connections> - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="exampleQueue"> - <permission roles="guest" type="createDurableQueue"/> - <permission roles="guest" type="deleteDurableQueue"/> - <permission roles="guest" type="createNonDurableQueue"/> - <permission roles="guest" type="deleteNonDurableQueue"/> - <permission roles="guest" type="consume"/> - <permission roles="guest" type="send"/> - </security-setting> - </security-settings> - <address-settings> - <!-- if you define auto-create on certain queues, management has to be auto-create --> - <address-setting match="activemq.management#"> - <dead-letter-address>DLQ</dead-letter-address> - <expiry-address>ExpiryQueue</expiry-address> - <redelivery-delay>0</redelivery-delay> - <!-- with -1 only the global-max-size is in use for limiting --> - <max-size-bytes>-1</max-size-bytes> - <message-counter-history-day-limit>10</message-counter-history-day-limit> - <address-full-policy>PAGE</address-full-policy> - <auto-create-queues>true</auto-create-queues> - <auto-create-addresses>true</auto-create-addresses> - <auto-create-jms-queues>true</auto-create-jms-queues> - <auto-create-jms-topics>true</auto-create-jms-topics> - </address-setting> - <!--default for catch all--> - <address-setting match="#"> - <dead-letter-address>DLQ</dead-letter-address> - <expiry-address>ExpiryQueue</expiry-address> - <redelivery-delay>0</redelivery-delay> - <!-- with -1 only the global-max-size is in use for limiting --> - <max-size-bytes>200MB</max-size-bytes> - <page-size-bytes>100MB</page-size-bytes> - - <message-counter-history-day-limit>10</message-counter-history-day-limit> - <address-full-policy>PAGE</address-full-policy> - <auto-create-queues>true</auto-create-queues> - <auto-create-addresses>true</auto-create-addresses> - <auto-create-jms-queues>true</auto-create-jms-queues> - <auto-create-jms-topics>true</auto-create-jms-topics> - </address-setting> - </address-settings> - - <addresses> - <address name="exampleQueue"> - <anycast> - <queue name="exampleQueue"/> - </anycast> - </address> - </addresses> - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server1/broker.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server1/broker.xml b/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server1/broker.xml deleted file mode 100644 index e67613d..0000000 --- a/tests/smoke-tests/replicated-flowcontrol/src/main/resources/activemq/server1/broker.xml +++ /dev/null @@ -1,121 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- -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. ---><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> - - - - <core xmlns="urn:activemq:core"> - - <bindings-directory>./data/bindings</bindings-directory> - - <journal-directory>./data/journal</journal-directory> - - <large-messages-directory>./data/largemessages</large-messages-directory> - - <paging-directory>./data/paging</paging-directory> - - <cluster-user>exampleUser</cluster-user> - - <cluster-password>secret</cluster-password> - - <ha-policy> - <replication> - <slave> - <allow-failback>true</allow-failback> - <!-- not needed but tells the backup not to restart after failback as there will be > 0 backups saved --> - <max-saved-replicated-journals-size>0</max-saved-replicated-journals-size> - </slave> - </replication> - </ha-policy> - - <!-- Connectors --> - <connectors> - <connector name="netty-live-connector">tcp://localhost:61616</connector> - <connector name="netty-connector">tcp://localhost:61617</connector> - </connectors> - - <!-- Acceptors --> - <acceptors> - <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor> - </acceptors> - - <cluster-connections> - <cluster-connection name="my-cluster"> - <connector-ref>netty-connector</connector-ref> - <static-connectors> - <connector-ref>netty-live-connector</connector-ref> - </static-connectors> - </cluster-connection> - </cluster-connections> - <!-- Other config --> - - <security-settings> - <!--security for example queue--> - <security-setting match="exampleQueue"> - <permission roles="guest" type="createDurableQueue"/> - <permission roles="guest" type="deleteDurableQueue"/> - <permission roles="guest" type="createNonDurableQueue"/> - <permission roles="guest" type="deleteNonDurableQueue"/> - <permission roles="guest" type="consume"/> - <permission roles="guest" type="send"/> - </security-setting> - </security-settings> - - <address-settings> - <!-- if you define auto-create on certain queues, management has to be auto-create --> - <address-setting match="activemq.management#"> - <dead-letter-address>DLQ</dead-letter-address> - <expiry-address>ExpiryQueue</expiry-address> - <redelivery-delay>0</redelivery-delay> - <!-- with -1 only the global-max-size is in use for limiting --> - <max-size-bytes>-1</max-size-bytes> - <message-counter-history-day-limit>10</message-counter-history-day-limit> - <address-full-policy>PAGE</address-full-policy> - <auto-create-queues>true</auto-create-queues> - <auto-create-addresses>true</auto-create-addresses> - <auto-create-jms-queues>true</auto-create-jms-queues> - <auto-create-jms-topics>true</auto-create-jms-topics> - </address-setting> - <!--default for catch all--> - <address-setting match="#"> - <dead-letter-address>DLQ</dead-letter-address> - <expiry-address>ExpiryQueue</expiry-address> - <redelivery-delay>0</redelivery-delay> - <!-- with -1 only the global-max-size is in use for limiting --> - <max-size-bytes>200MB</max-size-bytes> - <page-size-bytes>100MB</page-size-bytes> - - <message-counter-history-day-limit>10</message-counter-history-day-limit> - <address-full-policy>PAGE</address-full-policy> - <auto-create-queues>true</auto-create-queues> - <auto-create-addresses>true</auto-create-addresses> - <auto-create-jms-queues>true</auto-create-jms-queues> - <auto-create-jms-topics>true</auto-create-jms-topics> - </address-setting> - </address-settings> - - <addresses> - <address name="exampleQueue"> - <anycast> - <queue name="exampleQueue"/> - </anycast> - </address> - </addresses> - </core> -</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/replicated-flowcontrol/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicatedFailbackSmokeTest.java ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/replicated-flowcontrol/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicatedFailbackSmokeTest.java b/tests/smoke-tests/replicated-flowcontrol/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicatedFailbackSmokeTest.java deleted file mode 100644 index 9e81851..0000000 --- a/tests/smoke-tests/replicated-flowcontrol/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicatedFailbackSmokeTest.java +++ /dev/null @@ -1,268 +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. - */ -package org.apache.activemq.artemis.tests.smoke.replicationflow; - -import javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -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; - -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; - - private static Process server1; - - static final int NUM_MESSAGES = 300_000; - static final int START_CONSUMERS = 100_000; - static final int START_SERVER = 101_000; - 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); - - - @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; - - try { - server0 = ServerUtil.startServer(server0Location, ReplicatedFailbackSmokeTest.class.getSimpleName() + "0", 0, 30000); - - ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); - - connection = connectionFactory.createConnection(); - - Session session = connection.createSession(true, Session.SESSION_TRANSACTED); - - Queue queue = session.createQueue("exampleQueue"); - - MessageProducer producer = session.createProducer(queue); - - BytesMessage bytesMessage = session.createBytesMessage(); - bytesMessage.writeBytes(new byte[20 * 1024]); - - for (int i = 0; i < NUM_MESSAGES; i++) { - - producer.send(bytesMessage); - if (i % 1000 == 0) { - System.out.println("Sent " + i + " messages, consumed=" + totalConsumed.get()); - session.commit(); - } - - if (i == START_CONSUMERS) { - System.out.println("Starting consumers"); - 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(server1Location, ReplicatedFailbackSmokeTest.class.getSimpleName() + "1", 1, 10000); - } - - } - - session.commit(); - - System.out.println("Awaiting all consumers to finish"); - while (!latch.await(5, TimeUnit.SECONDS)) { - System.out.println("Missing " + latch.getCount() + ", totalConsumed = " + totalConsumed); - } - - } finally { - - running.set(false); - - if (connection != null) { - connection.close(); - } - - for (Consumer consumer : consumers) { - consumer.interrupt(); - consumer.join(); - } - } - } - - void startConsumers(boolean useAMQP) { - for (int i = 0; i < NUMBER_OF_CONSUMERS; i++) { - Consumer consumer = new Consumer(useAMQP && i % 2 == 0, i); - consumer.start(); - consumers.add(consumer); - } - } - - static class Consumer extends Thread { - - ConnectionFactory factory; - Connection connection; - Session session; - Queue queue; - MessageConsumer consumer; - int count = 0; - int totalCount = 0; - - final int consumerID; - - final boolean amqp; - - Consumer(boolean amqp, int id) { - super("amqp=" + amqp + ", id=" + id); - this.amqp = amqp; - this.consumerID = id; - } - - @Override - public String toString() { - return "Consumer " + consumerID + ", amqp::" + amqp; - } - - void connect() throws Exception { - if (connection != null) { - connection.close(); - } - count = 0; - if (amqp) { - factory = new JmsConnectionFactory("amqp://localhost:61616"); - } else { - factory = new ActiveMQConnectionFactory(); // using default is fine here - } - - connection = factory.createConnection(); - session = connection.createSession(true, Session.SESSION_TRANSACTED); - queue = session.createQueue("exampleQueue"); - consumer = session.createConsumer(queue); - connection.start(); - } - - @Override - public void run() { - 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 { - connection.close(); - } catch (Throwable ignored) { - } - } - - System.out.println("Giving up the loop " + this); - - } - - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/src/main/resources/servers/replicated-static0/broker.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/src/main/resources/servers/replicated-static0/broker.xml b/tests/smoke-tests/src/main/resources/servers/replicated-static0/broker.xml new file mode 100644 index 0000000..0e58838 --- /dev/null +++ b/tests/smoke-tests/src/main/resources/servers/replicated-static0/broker.xml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- +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. +--><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> + + + + <core xmlns="urn:activemq:core"> + + <bindings-directory>./data/bindings</bindings-directory> + + <journal-directory>./data/journal</journal-directory> + + <large-messages-directory>./data/largemessages</large-messages-directory> + + <paging-directory>./data/paging</paging-directory> + + <cluster-user>exampleUser</cluster-user> + + <cluster-password>secret</cluster-password> + + <ha-policy> + <replication> + <master> + <!--we need this for auto failback--> + <check-for-live-server>true</check-for-live-server> + </master> + </replication> + </ha-policy> + + <connectors> + <connector name="netty-connector">tcp://localhost:61616</connector> + <connector name="netty-backup-connector">tcp://localhost:61617</connector> + </connectors> + + <!-- Acceptors --> + <acceptors> + <acceptor name="netty-acceptor">tcp://localhost:61616</acceptor> + </acceptors> + + <cluster-connections> + <cluster-connection name="my-cluster"> + <connector-ref>netty-connector</connector-ref> + <static-connectors> + <connector-ref>netty-backup-connector</connector-ref> + </static-connectors> + </cluster-connection> + </cluster-connections> + <!-- Other config --> + + <security-settings> + <!--security for example queue--> + <security-setting match="exampleQueue"> + <permission roles="guest" type="createDurableQueue"/> + <permission roles="guest" type="deleteDurableQueue"/> + <permission roles="guest" type="createNonDurableQueue"/> + <permission roles="guest" type="deleteNonDurableQueue"/> + <permission roles="guest" type="consume"/> + <permission roles="guest" type="send"/> + </security-setting> + </security-settings> + <address-settings> + <!-- if you define auto-create on certain queues, management has to be auto-create --> + <address-setting match="activemq.management#"> + <dead-letter-address>DLQ</dead-letter-address> + <expiry-address>ExpiryQueue</expiry-address> + <redelivery-delay>0</redelivery-delay> + <!-- with -1 only the global-max-size is in use for limiting --> + <max-size-bytes>-1</max-size-bytes> + <message-counter-history-day-limit>10</message-counter-history-day-limit> + <address-full-policy>PAGE</address-full-policy> + <auto-create-queues>true</auto-create-queues> + <auto-create-addresses>true</auto-create-addresses> + <auto-create-jms-queues>true</auto-create-jms-queues> + <auto-create-jms-topics>true</auto-create-jms-topics> + </address-setting> + <!--default for catch all--> + <address-setting match="#"> + <dead-letter-address>DLQ</dead-letter-address> + <expiry-address>ExpiryQueue</expiry-address> + <redelivery-delay>0</redelivery-delay> + <!-- with -1 only the global-max-size is in use for limiting --> + <max-size-bytes>200MB</max-size-bytes> + <page-size-bytes>100MB</page-size-bytes> + + <message-counter-history-day-limit>10</message-counter-history-day-limit> + <address-full-policy>PAGE</address-full-policy> + <auto-create-queues>true</auto-create-queues> + <auto-create-addresses>true</auto-create-addresses> + <auto-create-jms-queues>true</auto-create-jms-queues> + <auto-create-jms-topics>true</auto-create-jms-topics> + </address-setting> + </address-settings> + + <addresses> + <address name="exampleQueue"> + <anycast> + <queue name="exampleQueue"/> + </anycast> + </address> + </addresses> + </core> +</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/src/main/resources/servers/replicated-static1/broker.xml ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/src/main/resources/servers/replicated-static1/broker.xml b/tests/smoke-tests/src/main/resources/servers/replicated-static1/broker.xml new file mode 100644 index 0000000..e67613d --- /dev/null +++ b/tests/smoke-tests/src/main/resources/servers/replicated-static1/broker.xml @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- +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. +--><configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd"> + + + + <core xmlns="urn:activemq:core"> + + <bindings-directory>./data/bindings</bindings-directory> + + <journal-directory>./data/journal</journal-directory> + + <large-messages-directory>./data/largemessages</large-messages-directory> + + <paging-directory>./data/paging</paging-directory> + + <cluster-user>exampleUser</cluster-user> + + <cluster-password>secret</cluster-password> + + <ha-policy> + <replication> + <slave> + <allow-failback>true</allow-failback> + <!-- not needed but tells the backup not to restart after failback as there will be > 0 backups saved --> + <max-saved-replicated-journals-size>0</max-saved-replicated-journals-size> + </slave> + </replication> + </ha-policy> + + <!-- Connectors --> + <connectors> + <connector name="netty-live-connector">tcp://localhost:61616</connector> + <connector name="netty-connector">tcp://localhost:61617</connector> + </connectors> + + <!-- Acceptors --> + <acceptors> + <acceptor name="netty-acceptor">tcp://localhost:61617</acceptor> + </acceptors> + + <cluster-connections> + <cluster-connection name="my-cluster"> + <connector-ref>netty-connector</connector-ref> + <static-connectors> + <connector-ref>netty-live-connector</connector-ref> + </static-connectors> + </cluster-connection> + </cluster-connections> + <!-- Other config --> + + <security-settings> + <!--security for example queue--> + <security-setting match="exampleQueue"> + <permission roles="guest" type="createDurableQueue"/> + <permission roles="guest" type="deleteDurableQueue"/> + <permission roles="guest" type="createNonDurableQueue"/> + <permission roles="guest" type="deleteNonDurableQueue"/> + <permission roles="guest" type="consume"/> + <permission roles="guest" type="send"/> + </security-setting> + </security-settings> + + <address-settings> + <!-- if you define auto-create on certain queues, management has to be auto-create --> + <address-setting match="activemq.management#"> + <dead-letter-address>DLQ</dead-letter-address> + <expiry-address>ExpiryQueue</expiry-address> + <redelivery-delay>0</redelivery-delay> + <!-- with -1 only the global-max-size is in use for limiting --> + <max-size-bytes>-1</max-size-bytes> + <message-counter-history-day-limit>10</message-counter-history-day-limit> + <address-full-policy>PAGE</address-full-policy> + <auto-create-queues>true</auto-create-queues> + <auto-create-addresses>true</auto-create-addresses> + <auto-create-jms-queues>true</auto-create-jms-queues> + <auto-create-jms-topics>true</auto-create-jms-topics> + </address-setting> + <!--default for catch all--> + <address-setting match="#"> + <dead-letter-address>DLQ</dead-letter-address> + <expiry-address>ExpiryQueue</expiry-address> + <redelivery-delay>0</redelivery-delay> + <!-- with -1 only the global-max-size is in use for limiting --> + <max-size-bytes>200MB</max-size-bytes> + <page-size-bytes>100MB</page-size-bytes> + + <message-counter-history-day-limit>10</message-counter-history-day-limit> + <address-full-policy>PAGE</address-full-policy> + <auto-create-queues>true</auto-create-queues> + <auto-create-addresses>true</auto-create-addresses> + <auto-create-jms-queues>true</auto-create-jms-queues> + <auto-create-jms-topics>true</auto-create-jms-topics> + </address-setting> + </address-settings> + + <addresses> + <address name="exampleQueue"> + <anycast> + <queue name="exampleQueue"/> + </anycast> + </address> + </addresses> + </core> +</configuration> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/common/SmokeTestBase.java ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/common/SmokeTestBase.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/common/SmokeTestBase.java new file mode 100644 index 0000000..f91a361 --- /dev/null +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/common/SmokeTestBase.java @@ -0,0 +1,62 @@ +/** + * 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.activemq.artemis.tests.smoke.common; + +import java.io.File; +import java.util.ArrayList; + +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.apache.activemq.artemis.util.ServerUtil; +import org.junit.After; + +public class SmokeTestBase extends ActiveMQTestBase { + ArrayList<Process> processes = new ArrayList(); + + public static final String basedir = System.getProperty("basedir"); + + @After + public void after() throws Exception { + for (Process process : processes) { + try { + ServerUtil.killServer(process); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + + public String getServerLocation(String serverName) { + return basedir + "/target/" + serverName; + } + + public void cleanupData(String serverName) { + String location = getServerLocation(serverName); + deleteDirectory(new File(location, "data")); + } + + public void addProcess(Process process) { + processes.add(process); + } + + public Process startServer(String serverName, int portID, int timeout) throws Exception { + Process process = ServerUtil.startServer(getServerLocation(serverName), serverName, portID, timeout); + addProcess(process); + return process; + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/c767e93b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicationFlowControlTest.java ---------------------------------------------------------------------- diff --git a/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicationFlowControlTest.java b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicationFlowControlTest.java new file mode 100644 index 0000000..4433775 --- /dev/null +++ b/tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/replicationflow/ReplicationFlowControlTest.java @@ -0,0 +1,270 @@ +/* + * 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.activemq.artemis.tests.smoke.replicationflow; + +import javax.jms.BytesMessage; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +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.smoke.common.SmokeTestBase; +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; + +public class ReplicationFlowControlTest extends SmokeTestBase { + + + public static final String SERVER_NAME_0 = "replicated-static0"; + public static final String SERVER_NAME_1 = "replicated-static1"; + + ArrayList<Consumer> consumers = new ArrayList<>(); + private static Process server0; + + private static Process server1; + + static final int NUM_MESSAGES = 300_000; + static final int START_CONSUMERS = 100_000; + static final int START_SERVER = 101_000; + 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); + + + + @Before + public void before() throws Exception { + cleanupData(SERVER_NAME_0); + cleanupData(SERVER_NAME_1); + disableCheckThread(); + } + + @After + @Override + public void after() throws Exception { + super.after(); + cleanupData(SERVER_NAME_0); + cleanupData(SERVER_NAME_1); + } + + @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; + + try { + server0 = startServer(SERVER_NAME_0, 0, 30000); + + ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); + + connection = connectionFactory.createConnection(); + + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + + Queue queue = session.createQueue("exampleQueue"); + + MessageProducer producer = session.createProducer(queue); + + BytesMessage bytesMessage = session.createBytesMessage(); + bytesMessage.writeBytes(new byte[20 * 1024]); + + for (int i = 0; i < NUM_MESSAGES; i++) { + + producer.send(bytesMessage); + if (i % 1000 == 0) { + System.out.println("Sent " + i + " messages, consumed=" + totalConsumed.get()); + session.commit(); + } + + if (i == START_CONSUMERS) { + System.out.println("Starting consumers"); + 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 = startServer(SERVER_NAME_1, 0, 30000); + } + + } + + session.commit(); + + System.out.println("Awaiting all consumers to finish"); + while (!latch.await(5, TimeUnit.SECONDS)) { + System.out.println("Missing " + latch.getCount() + ", totalConsumed = " + totalConsumed); + } + + } finally { + + running.set(false); + + if (connection != null) { + connection.close(); + } + + for (Consumer consumer : consumers) { + consumer.interrupt(); + consumer.join(); + } + } + } + + void startConsumers(boolean useAMQP) { + for (int i = 0; i < NUMBER_OF_CONSUMERS; i++) { + Consumer consumer = new Consumer(useAMQP && i % 2 == 0, i); + consumer.start(); + consumers.add(consumer); + } + } + + static class Consumer extends Thread { + + ConnectionFactory factory; + Connection connection; + Session session; + Queue queue; + MessageConsumer consumer; + int count = 0; + int totalCount = 0; + + final int consumerID; + + final boolean amqp; + + Consumer(boolean amqp, int id) { + super("amqp=" + amqp + ", id=" + id); + this.amqp = amqp; + this.consumerID = id; + } + + @Override + public String toString() { + return "Consumer " + consumerID + ", amqp::" + amqp; + } + + void connect() throws Exception { + if (connection != null) { + connection.close(); + } + count = 0; + if (amqp) { + factory = new JmsConnectionFactory("amqp://localhost:61616"); + } else { + factory = new ActiveMQConnectionFactory(); // using default is fine here + } + + connection = factory.createConnection(); + session = connection.createSession(true, Session.SESSION_TRANSACTED); + queue = session.createQueue("exampleQueue"); + consumer = session.createConsumer(queue); + connection.start(); + } + + @Override + public void run() { + 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 { + connection.close(); + } catch (Throwable ignored) { + } + } + + System.out.println("Giving up the loop " + this); + + } + + } +}
