This commit is contained in:
Clebert Suconic 2018-05-03 12:12:51 -04:00
commit 6c7843f0a6
5 changed files with 457 additions and 0 deletions

View File

@ -39,6 +39,7 @@ import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
import org.apache.activemq.artemis.junit.Wait;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.ReusableLatch;
import org.junit.Assert;
@ -100,6 +101,88 @@ public class RedeployTest extends ActiveMQTestBase {
}
}
@Test
public void testRedeployWithFailover() throws Exception {
EmbeddedJMS live = new EmbeddedJMS();
EmbeddedJMS backup = new EmbeddedJMS();
try {
// set these system properties to use in the relevant broker.xml files
System.setProperty("live-data-dir", getTestDirfile().toPath() + "/redeploy-live-data");
System.setProperty("backup-data-dir", getTestDirfile().toPath() + "/redeploy-backup-data");
Path liveBrokerXML = getTestDirfile().toPath().resolve("live.xml");
Path backupBrokerXML = getTestDirfile().toPath().resolve("backup.xml");
URL url1 = RedeployTest.class.getClassLoader().getResource("reload-live-original.xml");
URL url2 = RedeployTest.class.getClassLoader().getResource("reload-live-changed.xml");
URL url3 = RedeployTest.class.getClassLoader().getResource("reload-backup-original.xml");
URL url4 = RedeployTest.class.getClassLoader().getResource("reload-backup-changed.xml");
Files.copy(url1.openStream(), liveBrokerXML);
Files.copy(url3.openStream(), backupBrokerXML);
live.setConfigResourcePath(liveBrokerXML.toUri().toString());
live.start();
waitForServerToStart(live.getActiveMQServer());
backup.setConfigResourcePath(backupBrokerXML.toUri().toString());
backup.start();
Wait.waitFor(() -> backup.getActiveMQServer().isReplicaSync(), 10000, 200);
final ReusableLatch liveReloadLatch = new ReusableLatch(1);
Runnable liveTick = () -> liveReloadLatch.countDown();
live.getActiveMQServer().getReloadManager().setTick(liveTick);
final ReusableLatch backupReloadTickLatch = new ReusableLatch(1);
Runnable backupTick = () -> backupReloadTickLatch.countDown();
backup.getActiveMQServer().getReloadManager().setTick(backupTick);
liveReloadLatch.await(10, TimeUnit.SECONDS);
Files.copy(url2.openStream(), liveBrokerXML, StandardCopyOption.REPLACE_EXISTING);
liveBrokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000);
liveReloadLatch.countUp();
live.getActiveMQServer().getReloadManager().setTick(liveTick);
liveReloadLatch.await(10, TimeUnit.SECONDS);
backupReloadTickLatch.await(10, TimeUnit.SECONDS);
Files.copy(url4.openStream(), backupBrokerXML, StandardCopyOption.REPLACE_EXISTING);
backupBrokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000);
backupReloadTickLatch.countUp();
backup.getActiveMQServer().getReloadManager().setTick(backupTick);
backupReloadTickLatch.await(10, TimeUnit.SECONDS);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession();
Queue queue = session.createQueue("myQueue2");
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("text"));
}
live.stop();
Wait.waitFor(() -> (backup.getActiveMQServer().isActive()), 5000, 100);
factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61617");
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession();
Queue queue = session.createQueue("myQueue2");
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("text"));
connection.start();
MessageConsumer consumer = session.createConsumer(session.createQueue("myQueue2"));
Assert.assertNotNull("Queue wasn't deployed accordingly", consumer.receive(5000));
Assert.assertNotNull(consumer.receive(5000));
}
} finally {
live.stop();
backup.stop();
System.clearProperty("live-data-dir");
System.clearProperty("backup-data-dir");
}
}
private boolean tryConsume() throws JMSException {
try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection();

View File

@ -0,0 +1,96 @@
<?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.
-->
<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>0.0.0.0</name>
<configuration-file-refresh-period>100</configuration-file-refresh-period>
<security-enabled>false</security-enabled>
<paging-directory>${backup-data-dir}/paging</paging-directory>
<bindings-directory>${backup-data-dir}/bindings</bindings-directory>
<journal-directory>${backup-data-dir}/journal</journal-directory>
<large-messages-directory>${backup-data-dir}/large-messages</large-messages-directory>
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61617</acceptor>
</acceptors>
<connectors>
<connector name="artemis">tcp://127.0.0.1:61617</connector>
</connectors>
<ha-policy>
<replication>
<slave>
<allow-failback>true</allow-failback>
</slave>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>artemis</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>artemis</connector-ref>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>
<addresses>
<address name="myQueue">
<anycast>
<queue name="myQueue"/>
</anycast>
</address>
<address name="myQueue2">
<anycast>
<queue name="myQueue2"/>
</anycast>
</address>
</addresses>
</core>
</configuration>

View File

@ -0,0 +1,91 @@
<?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.
-->
<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>0.0.0.0</name>
<configuration-file-refresh-period>100</configuration-file-refresh-period>
<security-enabled>false</security-enabled>
<paging-directory>${backup-data-dir}/paging</paging-directory>
<bindings-directory>${backup-data-dir}/bindings</bindings-directory>
<journal-directory>${backup-data-dir}/journal</journal-directory>
<large-messages-directory>${backup-data-dir}/large-messages</large-messages-directory>
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61617</acceptor>
</acceptors>
<connectors>
<connector name="artemis">tcp://127.0.0.1:61617</connector>
</connectors>
<ha-policy>
<replication>
<slave>
<allow-failback>true</allow-failback>
</slave>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>artemis</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>artemis</connector-ref>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>
<addresses>
<address name="myQueue">
<anycast>
<queue name="myQueue"/>
</anycast>
</address>
</addresses>
</core>
</configuration>

View File

@ -0,0 +1,96 @@
<?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.
-->
<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>0.0.0.0</name>
<configuration-file-refresh-period>100</configuration-file-refresh-period>
<security-enabled>false</security-enabled>
<paging-directory>${live-data-dir}/paging</paging-directory>
<bindings-directory>${live-data-dir}/bindings</bindings-directory>
<journal-directory>${live-data-dir}/journal</journal-directory>
<large-messages-directory>${live-data-dir}/large-messages</large-messages-directory>
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61616</acceptor>
</acceptors>
<connectors>
<connector name="artemis">tcp://127.0.0.1:61616</connector>
</connectors>
<ha-policy>
<replication>
<master>
<check-for-live-server>true</check-for-live-server>
</master>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>artemis</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>artemis</connector-ref>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>
<addresses>
<address name="myQueue">
<anycast>
<queue name="myQueue"/>
</anycast>
</address>
<address name="myQueue2">
<anycast>
<queue name="myQueue2"/>
</anycast>
</address>
</addresses>
</core>
</configuration>

View File

@ -0,0 +1,91 @@
<?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.
-->
<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core">
<name>0.0.0.0</name>
<configuration-file-refresh-period>100</configuration-file-refresh-period>
<security-enabled>false</security-enabled>
<paging-directory>${live-data-dir}/paging</paging-directory>
<bindings-directory>${live-data-dir}/bindings</bindings-directory>
<journal-directory>${live-data-dir}/journal</journal-directory>
<large-messages-directory>${live-data-dir}/large-messages</large-messages-directory>
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61616</acceptor>
</acceptors>
<connectors>
<connector name="artemis">tcp://127.0.0.1:61616</connector>
</connectors>
<ha-policy>
<replication>
<master>
<check-for-live-server>true</check-for-live-server>
</master>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>5000</broadcast-period>
<connector-ref>artemis</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<connector-ref>artemis</connector-ref>
<message-load-balancing>STRICT</message-load-balancing>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
</cluster-connections>
<addresses>
<address name="myQueue">
<anycast>
<queue name="myQueue"/>
</anycast>
</address>
</addresses>
</core>
</configuration>