* through inactivity.
*
* @throws Exception for any error
*/
public void testInactive() throws Exception {
final Latch latch = new Latch();
CallerListener listener = new CallerListener() {
public void disconnected(Caller caller) {
latch.release();
}
};
ORB server = getORB();
CallbackServer serviceImpl = new CallbackServer(server, latch);
Proxy proxy = server.exportObject(serviceImpl);
server.getRegistry().bind("service", proxy);
ORB client = getClientORB();
client.addCallerListener(getServerURI(), listener);
Registry registry = getRegistry(); // will establish a connection
assertNotNull(registry);
CallbackService service = (CallbackService) registry.lookup("service");
assertNotNull(service);
// make sure the connection isn't reaped through inactivity
// while there are proxies associated with it.
for (int i = 0; i < 10; ++i) {
Runtime.getRuntime().gc();
if (latch.attempt(1000)) {
break;
}
}
if (latch.attempt(0)) {
fail("Connection terminated when there were active proxies");
}
// clear registry proxy and ensure the connection isn't reaped.
// Registry proxy is constructed differently to those serialized
// over the wire.
registry = null;
for (int i = 0; i < 10; ++i) {
Runtime.getRuntime().gc();
if (latch.attempt(1000)) {
break;
}
}
if (latch.attempt(0)) {
fail("Connection terminated when there were active proxies");
}
// clear proxy reference so the connection can be GC'ed
service = null;
// wait for the notification. Need to force the GC to run...
for (int i = 0; i < 10; ++i) {
Runtime.getRuntime().gc();
if (latch.attempt(1000)) {
break;
}
}
if (!latch.attempt(0)) {
fail("CallerListener not notified of disconnection");
}
}