### Question:
Acceptor { ResourcePool getSocketSet(final ConnectionType connectionType) throws ShutdownException { synchronized (m_socketSets) { if (m_isShutdown) { throw new ShutdownException("Acceptor has been shut down"); } final ResourcePool original = m_socketSets.get(connectionType); if (original != null) { return original; } else { final ResourcePool newSocketSet = new ResourcePoolImplementation(); newSocketSet.addListener( new ResourcePool.Listener() { public void resourceAdded(ResourcePool.Resource resource) { final ConnectionIdentity connection = ((SocketWrapper)resource).getConnectionIdentity(); getListeners(connectionType).apply( new ListenerSupport.Informer<Listener>() { public void inform(Listener l) { l.connectionAccepted(connectionType, connection); } }); } public void resourceClosed(ResourcePool.Resource resource) { final ConnectionIdentity connection = ((SocketWrapper)resource).getConnectionIdentity(); getListeners(connectionType).apply( new ListenerSupport.Informer<Listener>() { public void inform(Listener l) { l.connectionClosed(connectionType, connection); } }); } }); m_socketSets.put(connectionType, newSocketSet); return newSocketSet; } } } Acceptor(String addressString,
                  int port,
                  int numberOfThreads,
                  TimeAuthority timeAuthority); void shutdown(); int getPort(); Exception getPendingException(); int getNumberOfConnections(); void addListener(ConnectionType connectionType, Listener listener);  }### Answer:
@Test public void testGetSocketSet() throws Exception { final Acceptor acceptor = createAcceptor(2); assertEquals(0, acceptor.getNumberOfConnections()); final RandomStubFactory<Acceptor.Listener> listenerStubFactory = RandomStubFactory.create(Acceptor.Listener.class); acceptor.addListener(ConnectionType.WORKER, listenerStubFactory.getStub()); final ResourcePool controlSocketSet = acceptor.getSocketSet(ConnectionType.AGENT); assertNotNull(controlSocketSet); assertTrue(controlSocketSet.reserveNext().isSentinel()); final Connector controlConnector = new Connector("localhost", acceptor.getPort(), ConnectionType.AGENT); final Connector reportConnector = new Connector("localhost", acceptor.getPort(), ConnectionType.WORKER); controlConnector.connect(); controlConnector.connect(); reportConnector.connect(); for (int i = 0; controlSocketSet.countActive() != 2 && i < 10; ++i) { Thread.sleep(i * i * 10); } listenerStubFactory.waitUntilCalled(1000); final CallData callData = listenerStubFactory.assertSuccess("connectionAccepted", ConnectionType.class, ConnectionIdentity.class); assertEquals(ConnectionType.WORKER, callData.getParameters()[0]); listenerStubFactory.assertNoMoreCalls(); assertSame(controlSocketSet, acceptor.getSocketSet(ConnectionType.AGENT)); final List<?> controlSocketResources = controlSocketSet.reserveAll(); assertEquals(2, controlSocketResources.size()); final ResourcePool reportSocketSet = acceptor.getSocketSet(ConnectionType.WORKER); for (int i=0; reportSocketSet.countActive() != 1 && i<10; ++i) { Thread.sleep(i * i * 10); } assertEquals(3, acceptor.getNumberOfConnections()); assertSame(reportSocketSet, acceptor.getSocketSet(ConnectionType.WORKER)); final List<?> reportSocketResources = reportSocketSet.reserveAll(); assertEquals(1, reportSocketResources.size()); acceptor.shutdown(); assertEquals(0, acceptor.getNumberOfConnections()); final CallData callData2 = listenerStubFactory.assertSuccess("connectionClosed", ConnectionType.class, ConnectionIdentity.class); assertEquals(callData.getParameters()[1], callData2.getParameters()[1]); }