HashMap config = new HashMap();
config.put(InvokerLocator.FORCE_REMOTE, "true");
config.put(ServerInvoker.TIMEOUT, "60000");
config.put(Client.ENABLE_LEASE, "true");
addClientConfig(config);
final Client client = new Client(locator, config);
try
{
client.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
log.info("making first invocation");
Object response = client.invoke("test");
assertEquals("test", response);
log.info("first invocation succeeds");
new Thread()
{
public void run()
{
try
{
// Wait for the server to be disabled.
Thread.sleep(10000);
try
{
// This invocation may use up a listening connection,
// depending on transport.
HashMap metadata = new HashMap();
metadata.put("timeout", shortTimeoutString());
log.info("making invocation");
client.invoke("test", metadata);
log.info("made invocation");
}
catch (Exception e)
{
log.info("client.invoke(\"test\") failed (that's OK)");
}
// Set disconnectTimeout to 1 second.
log.info("calling client.disconnect()");
client.setDisconnectTimeout(shortTimeout());
client.disconnect();
log.info("returned from client.disconnect()");
}
catch (Throwable e)
{
log.info("error in client.disconnect()", e);
}
}
}.start();
// It should take the Client a little while for LeasePinger's attempts to contact
// the server to time out. Wait for about 4 seconds after the call to
// Client.disconnect() and then verify that the Client has successfully
// disconnected even though the server is disabled.
Thread.sleep(16000);
assertFalse(client.isConnected());
log.info(getName() + " PASSES");
}