Skip to content
Browse files

JBPAPP6-1393 Fix backup bridge deployment: deploy&start bridges on cl…

  • Loading branch information...
1 parent 84baac5 commit 6acabc8cb361e27270abcd0a4659da65bf8e2166 Francisco Borges committed with clebertsuconic Mar 27, 2013
View
31 hornetq-server/src/main/java/org/hornetq/core/server/cluster/ClusterManager.java
@@ -258,12 +258,18 @@ public synchronized void start() throws Exception
}
}
+ deployConfiguredBridges();
+ state = State.STARTED;
+ }
+
+ private final void deployConfiguredBridges() throws Exception
+ {
+ if (backup)
+ return;
for (BridgeConfiguration config : configuration.getBridgeConfigurations())
{
- deployBridge(config, !backup);
+ deployBridge(config);
}
-
- state = State.STARTED;
}
public void stop() throws Exception
@@ -352,13 +358,21 @@ public ClusterConnection getClusterConnection(final String name)
return clusterConnections.get(name);
}
- // backup node becomes live
- public synchronized void activate()
+ /**
+ * Activates several cluster services. Used by backups on failover.
+ * @throws Exception
+ */
+ public synchronized void activate() throws Exception
{
+ if (state != State.STARTED && state != State.DEPLOYED)
+ return;
+
if (backup)
{
backup = false;
+ deployConfiguredBridges();
+
for (BroadcastGroup broadcastGroup : broadcastGroups.values())
{
try
@@ -441,7 +455,7 @@ public void removeClusterLocator(final ServerLocatorInternal serverLocator)
this.clusterLocators.remove(serverLocator);
}
- public synchronized void deployBridge(final BridgeConfiguration config, final boolean start) throws Exception
+ public synchronized void deployBridge(final BridgeConfiguration config) throws Exception
{
if (config.getName() == null)
{
@@ -599,10 +613,7 @@ public synchronized void deployBridge(final BridgeConfiguration config, final bo
managementService.registerBridge(bridge, config);
- if (start)
- {
- bridge.start();
- }
+ bridge.start();
}
View
2 hornetq-server/src/main/java/org/hornetq/core/server/impl/HornetQServerImpl.java
@@ -1288,7 +1288,7 @@ public void deployBridge(BridgeConfiguration config) throws Exception
{
if (clusterManager != null)
{
- clusterManager.deployBridge(config, true);
+ clusterManager.deployBridge(config);
}
}
View
80 ...tests/src/test/java/org/hornetq/tests/integration/cluster/bridge/BridgeReconnectTest.java
@@ -73,7 +73,7 @@
final String bridgeName = "bridge1";
final String testAddress = "testAddress";
- final String queueName0 = "queue0";
+ final String queueName = "queue0";
final String forwardAddress = "forwardAddress";
final long retryInterval = 50;
@@ -121,6 +121,10 @@ private String getConnector()
return INVM_CONNECTOR_FACTORY;
}
+ /**
+ * Backups must successfully deploy its bridges on fail-over.
+ * @see https://bugzilla.redhat.com/show_bug.cgi?id=900764
+ */
public void testFailoverDeploysBridge() throws Exception
{
NodeManager nodeManager = new InVMNodeManager(false);
@@ -134,7 +138,41 @@ public void testFailoverDeploysBridge() throws Exception
server0.getConfiguration().setConnectorConfigurations(connectors);
server1.getConfiguration().setConnectorConfigurations(connectors);
+ server2.getConfiguration().setConnectorConfigurations(connectors);
+ reconnectAttempts = -1;
+ BridgeConfiguration bridgeConfiguration = createBridgeConfig();
+ bridgeConfiguration.setQueueName(queueName);
+ List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
+ bridgeConfigs.add(bridgeConfiguration);
+ server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
+ server2.getConfiguration().setBridgeConfigurations(bridgeConfigs);
+
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
+ List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
+ queueConfigs0.add(queueConfig0);
+ server1.getConfiguration().setQueueConfigurations(queueConfigs0);
+
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
+ List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
+ queueConfigs1.add(queueConfig1);
+ server0.getConfiguration().setQueueConfigurations(queueConfigs1);
+ server2.getConfiguration().setQueueConfigurations(queueConfigs1);
+
+ startServers();
+
+ waitForServerStart(server0);
+ server0.stop(true);
+
+ waitForServerStart(server2);
+
+ locator = addServerLocator(HornetQClient.createServerLocatorWithoutHA(server0tc, server2tc));
+
+ ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
+
+ session0 = csf0.createSession(false, true, true);
+ Map<String, Bridge> bridges = server2.getClusterManager().getBridges();
+ assertTrue("backup must deploy bridge on failover", !bridges.isEmpty());
}
// Fail bridge and reconnecting immediately
@@ -160,12 +198,12 @@ public void testFailoverAndReconnectImmediately() throws Exception
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
- CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
- CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
@@ -181,17 +219,17 @@ public void testFailoverAndReconnectImmediately() throws Exception
locator = addServerLocator(HornetQClient.createServerLocatorWithoutHA(server0tc, server2tc));
- ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
+ ClientSessionFactory csf0 = addSessionFactory(locator.createSessionFactory(server2tc));
session0 = csf0.createSession(false, true, true);
- ClientProducer prod0 = session0.createProducer(testAddress);
+ ClientProducer prod0 = session0.createProducer(testAddress);
- ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc));
+ ClientSessionFactory csf2 = addSessionFactory(locator.createSessionFactory(server2tc));
session2 = csf2.createSession(false, true, true);
- ClientConsumer cons2 = session2.createConsumer(queueName0);
+ ClientConsumer cons2 = session2.createConsumer(queueName);
session2.start();
@@ -221,7 +259,7 @@ public void testFailoverAndReconnectImmediately() throws Exception
private BridgeConfiguration createBridgeConfig()
{
- return new BridgeConfiguration(bridgeName, queueName0, forwardAddress, null, null,
+ return new BridgeConfiguration(bridgeName, queueName, forwardAddress, null, null,
HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
HornetQClient.DEFAULT_CONNECTION_TTL, retryInterval,
@@ -251,12 +289,12 @@ public void testFailoverAndReconnectAfterAFewTries() throws Exception
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
- CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
- CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
@@ -276,7 +314,7 @@ public void testFailoverAndReconnectAfterAFewTries() throws Exception
ClientProducer prod0 = session0.createProducer(testAddress);
- ClientConsumer cons2 = session2.createConsumer(queueName0);
+ ClientConsumer cons2 = session2.createConsumer(queueName);
session2.start();
@@ -319,12 +357,12 @@ public void testReconnectSameNode() throws Exception
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
- CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
- CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
@@ -340,7 +378,7 @@ public void testReconnectSameNode() throws Exception
ClientProducer prod0 = session0.createProducer(testAddress);
- ClientConsumer cons1 = session1.createConsumer(queueName0);
+ ClientConsumer cons1 = session1.createConsumer(queueName);
session1.start();
@@ -401,7 +439,7 @@ private void testShutdownServerCleanlyAndReconnectSameNode(final boolean sleep)
final long clientFailureCheckPeriod = 1000;
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
- queueName0,
+ queueName,
forwardAddress,
null,
null,
@@ -423,12 +461,12 @@ private void testShutdownServerCleanlyAndReconnectSameNode(final boolean sleep)
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
- CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
- CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
@@ -458,7 +496,7 @@ private void testShutdownServerCleanlyAndReconnectSameNode(final boolean sleep)
ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
session1 = csf1.createSession(false, true, true);
- ClientConsumer cons1 = session1.createConsumer(queueName0);
+ ClientConsumer cons1 = session1.createConsumer(queueName);
session1.start();
@@ -534,12 +572,12 @@ public void testFailoverThenFailAgainAndReconnect() throws Exception
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
- CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
- CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
+ CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
@@ -555,7 +593,7 @@ public void testFailoverThenFailAgainAndReconnect() throws Exception
ClientProducer prod0 = session0.createProducer(testAddress);
- ClientConsumer cons1 = session1.createConsumer(queueName0);
+ ClientConsumer cons1 = session1.createConsumer(queueName);
session1.start();

0 comments on commit 6acabc8

Please sign in to comment.
Something went wrong with that request. Please try again.