Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
field.setAccessible(true);
LRUPool clientpool = (LRUPool) field.get(invoker);
assertEquals(1, clientpool.size());
Set s = clientpool.getContents();
ServerThread serverThread1 = (ServerThread) s.iterator().next();
// Get threadpool.
field = SocketServerInvoker.class.getDeclaredField("threadpool");
field.setAccessible(true);
LinkedList threadpool = (LinkedList) field.get(invoker);
assertEquals(0, threadpool.size());
// Wait for ServerThread to time out.
Thread.sleep(6000);
for (int i = 0; i < 5; i++)
{
Thread.sleep(2000);
if (clientpool.size() == 0) break;
}
if (clientpool.size() > 0)
{
fail("expect clientpool.size() == 0");
}
// Verify original ServerThread was returned to threadpool.
assertEquals(1, threadpool.size());
assertEquals(serverThread1, threadpool.iterator().next());
// Make another invocation and verify ServerThread was reused.
client.invoke("xyz");
assertEquals(1, clientpool.size());
s = clientpool.getContents();
ServerThread serverThread2 = (ServerThread) s.iterator().next();
assertEquals(serverThread1, serverThread2);
client.disconnect();
shutdownServer();
log.info(getName() + " PASSES");