final Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getServerService("ejbd").getPort());
final InitialContext context = new InitialContext(environment);
final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
// Invoke BLUE a few times
invoke(bean, 10, "blue");
// Kill BLUE
blue.kill();
// Invocations should now fail (and not failover)
try {
bean.name();
Assert.fail("Server should be down and failover not hooked up");
} catch (final Exception e) {
// pass
}
}
// Now we start RED
red.start(1, TimeUnit.MINUTES);
// Wait for the reconnectDelay so GREEN can find RED
Thread.sleep((long) (reconnectDelay.getTime(TimeUnit.MILLISECONDS) * 1.5));
// Verify Failover is now functional
{
// RED was never started so GREEN never found any peers
// Lets invoke GREEN then shut it down and verify we have
// no other peers to invoke
final StandaloneServer green = servers.get("green");
final Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + green.getServerService("ejbd").getPort());
final InitialContext context = new InitialContext(environment);
final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
// Invoke GREEN a few times
invoke(bean, 10, "green");