Map callbackConnectors = (Map) field.get(client);
assertEquals(1, callbackConnectors.size());
Set callbackConnectorSet = (Set) callbackConnectors.values().iterator().next();
assertEquals(1, callbackConnectorSet.size());
Connector callbackConnector = (Connector) callbackConnectorSet.iterator().next();
ServerInvoker cbsi = callbackConnector.getServerInvoker();
assertTrue(cbsi instanceof BisocketServerInvoker);
field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
field.setAccessible(true);
Map controlConnectionThreadMap = (Map) field.get(cbsi);
assertEquals(1, controlConnectionThreadMap.size());
Thread t = (Thread) controlConnectionThreadMap.values().iterator().next();
Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
Class controlConnectionThreadClass = null;
for (int i = 0; i < classes.length; i++)
{
log.info(classes[i]);
String fqn = classes[i].getName();
String className = fqn.substring(fqn.lastIndexOf('.') + 1);
log.info(className);
if ("BisocketServerInvoker$ControlConnectionThread".equals(className))
{
controlConnectionThreadClass = classes[i];
break;
}
}
assertNotNull(controlConnectionThreadClass);
assertEquals(t.getClass(), controlConnectionThreadClass);
field = controlConnectionThreadClass.getDeclaredField("controlSocket");
field.setAccessible(true);
Socket controlSocket = (Socket) field.get(t);
assertNotNull(controlSocket);
controlSocket.close();
log.info("CLOSED CONTROL SOCKET");
// Shut down the only existing ServerThread on the server side, and therefore
// the only existing pooled connection on the client side, forcing the
// next invocation to depend on the creation of a new control connection.
field = SocketServerInvoker.class.getDeclaredField("clientpool");
field.setAccessible(true);
ServerInvoker serverInvoker = connector.getServerInvoker();
assertTrue(serverInvoker instanceof BisocketServerInvoker);
LRUPool clientpool = (LRUPool) field.get(serverInvoker);
Set serverThreads = clientpool.getContents();
assertEquals(1, serverThreads.size());
((ServerThread)serverThreads.iterator().next()).shutdown();