// Fail bridge and reconnecting immediately
public void testFailoverAndReconnectImmediately() throws Exception
{
NodeManager nodeManager = new InVMNodeManager();
Map<String, Object> server0Params = new HashMap<String, Object>();
HornetQServer server0 = createHornetQServer(0, server0Params, isNetty(), nodeManager);
Map<String, Object> server1Params = new HashMap<String, Object>();
HornetQServer server1 = createHornetQServer(1, isNetty(), server1Params);
Map<String, Object> server2Params = new HashMap<String, Object>();
HornetQServer service2 = createBackupHornetQServer(2, server2Params, isNetty(), 0, nodeManager);
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params, "server1tc");
TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");
connectors.put(server1tc.getName(), server1tc);
connectors.put(server2tc.getName(), server2tc);
server0.getConfiguration().setConnectorConfigurations(connectors);
server1.getConfiguration().setConnectorConfigurations(connectors);
final String bridgeName = "bridge1";
final String testAddress = "testAddress";
final String queueName0 = "queue0";
final String forwardAddress = "forwardAddress";
final long retryInterval = 50;
final double retryIntervalMultiplier = 1d;
final int reconnectAttempts = 1;
final int confirmationWindowSize = 1024;
ArrayList<String> staticConnectors = new ArrayList<String>();
staticConnectors.add(server1tc.getName());
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
queueName0,
forwardAddress,
null,
null,
retryInterval,
retryIntervalMultiplier,
reconnectAttempts,
false,
confirmationWindowSize,
HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
staticConnectors,
false,
ConfigurationImpl.DEFAULT_CLUSTER_USER,
ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);
List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
queueConfigs1.add(queueConfig1);
server1.getConfiguration().setQueueConfigurations(queueConfigs1);
service2.getConfiguration().setQueueConfigurations(queueConfigs1);
ServerLocator locator = null;
try
{
service2.start();
server1.start();
server0.start();
BridgeReconnectTest.log.info("** failing connection");
// Now we will simulate a failure of the bridge connection between server0 and server1
server0.stop(true);
waitForServerStart(service2);
locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server2tc);
ClientSessionFactory csf0 = locator.createSessionFactory(server2tc);
ClientSession session0 = csf0.createSession(false, true, true);
ClientProducer prod0 = session0.createProducer(testAddress);
ClientSessionFactory csf2 = locator.createSessionFactory(server2tc);
ClientSession session2 = csf2.createSession(false, true, true);
ClientConsumer cons2 = session2.createConsumer(queueName0);
session2.start();
final int numMessages = 10;
SimpleString propKey = new SimpleString("propkey");
for (int i = 0; i < numMessages; i++)
{
ClientMessage message = session0.createMessage(true);
message.putIntProperty(propKey, i);
prod0.send(message);
}
for (int i = 0; i < numMessages; i++)
{
ClientMessage r1 = cons2.receive(1500);
Assert.assertNotNull(r1);
Assert.assertEquals(i, r1.getObjectProperty(propKey));
}
session0.close();
session2.close();
}
finally
{
if (locator != null)
{
locator.close();
}
server0.stop();
server1.stop();
service2.stop();
}
Assert.assertEquals(0, server0.getRemotingService().getConnections().size());
Assert.assertEquals(0, server1.getRemotingService().getConnections().size());
Assert.assertEquals(0, service2.getRemotingService().getConnections().size());
}