return new RemoteProcessHornetQServer(SharedBackupServerConfiguration.class.getName());
}
public void testCrashLiveServer() throws Exception
{
TestableServer liveServer = null;
TestableServer backupServer = null;
try
{
liveServer = createLiveServer();
backupServer = createBackupServer();
liveServer.start();
backupServer.start();
ServerLocator locator = HornetQClient.createServerLocatorWithHA(createTransportConfiguration(true,
false,
generateParams(0,
true)));
locator.setFailoverOnInitialConnection(true);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession prodSession = sf.createSession();
prodSession.createQueue("foo", "bar", true);
ClientProducer producer = prodSession.createProducer("foo");
ClientMessage message = prodSession.createMessage(true);
message.putStringProperty("key", "value");
producer.send(message);
prodSession.commit();
prodSession.close();
liveServer.crash();
liveServer = null;
Thread.sleep(5000);
sf = locator.createSessionFactory();
ClientSession consSession = sf.createSession();
consSession.start();
ClientConsumer consumer = consSession.createConsumer("bar");
ClientMessage receivedMessage = consumer.receive(5000);
assertNotNull(receivedMessage);
assertEquals(message.getStringProperty("key"), receivedMessage.getStringProperty("key"));
receivedMessage.acknowledge();
consumer.close();
consSession.deleteQueue("bar");
locator.close();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if (liveServer != null)
{
liveServer.stop();
}
if (backupServer != null)
{
backupServer.stop();
}
}
}