final WindowExt window = WindowExt.getHostWindow();
final TestServerListener serverListener = new TestServerListener();
Server server = Server.listen(window, channelName, serverListener);
final TestListener clientListenerA = new TestListener();
final Client clientA = Client.connect(window, channelName, clientListenerA);
ServerClientAndListener serverPairA = serverListener.getListenerAndChannelAt(0);
assertTrue("Channel is null.", serverPairA.channel != null);
assertTrue("Listener is null.", serverPairA.listener != null);
assertTrue("server failed to connect.", serverPairA.listener.isConnected());
assertTrue("client failed to connect.", clientListenerA.isConnected());
final TestListener clientListenerB = new TestListener();
final Client clientB = Client.connect(window, channelName, clientListenerB);
ServerClientAndListener serverPairB = serverListener.getListenerAndChannelAt(1);
assertTrue("Channel is null.", serverPairB.channel != null);
assertTrue("Listener is null.", serverPairB.listener != null);
assertTrue("server failed to connect.", serverPairB.listener.isConnected());
assertTrue("client failed to connect.", clientListenerB.isConnected());
serverPairA.channel.close();
assertFalse("server failed to close.", serverPairA.listener.isConnected());
assertFalse("client failed to close.", clientListenerA.isConnected());
serverPairB.channel.close();
assertFalse("server failed to close.", serverPairB.listener.isConnected());
assertFalse("client failed to close.", clientListenerB.isConnected());
// Ensures there is no error calling close on a channel that was previously
// closed.
clientA.close();
clientB.close();
server.close();
assertTrue("Server Connector did not null out after close.",
window.getObjectProperty(PROPERTY_NAME + channelName) == null);
}