### Question:
ConsoleCommunicationImplementation implements ConsoleCommunication { public int getNumberOfConnections() { return m_acceptor == null ? 0 : m_acceptor.getNumberOfConnections(); } ConsoleCommunicationImplementation(Resources resources,
			ConsoleProperties properties, ErrorHandler errorHandler,
			TimeAuthority timeAuthority);  ConsoleCommunicationImplementation(Resources resources,
                                            ConsoleProperties properties,
                                            ErrorHandler errorHandler,
                                            TimeAuthority timeAuthority,
                                            long idlePollDelay,
                                            long inactiveClientTimeOut); MessageDispatchRegistry getMessageDispatchRegistry(); @PreDestroy void shutdown(); boolean processOneMessage(); int getNumberOfConnections(); void sendToAgents(Message message); void sendToAddressedAgents(Address address, Message message);  }### Answer:
@Test public void testConstruction() throws Exception { m_processMessagesThread.start(); m_properties.setConsolePort(m_usedServerSocket.getLocalPort()); final ConsoleCommunicationImplementation consoleCommunication = new ConsoleCommunicationImplementation(s_resources, m_properties, m_errorHandler, m_timeAuthority, 500, 10000); assertEquals(0, consoleCommunication.getNumberOfConnections()); final ConsoleCommunicationImplementation consoleCommunication2 = new ConsoleCommunicationImplementation(s_resources, m_properties, m_errorHandler, m_timeAuthority); assertEquals(0, consoleCommunication2.getNumberOfConnections()); }
@Test public void testDistributionControl() throws Exception { final Socket socket = new StubConnector(InetAddress.getByName(null).getHostName(), m_properties.getConsolePort(), ConnectionType.AGENT) .connect(); final DistributionControl distributionControl = new DistributionControlImplementation(m_consoleCommunication); final Socket socket2 = new StubConnector(InetAddress.getByName(null).getHostName(), m_properties.getConsolePort(), ConnectionType.AGENT) .connect(); waitForNumberOfConnections(2); socket2.close(); final Address address = new SendToEveryoneAddress(); int n = 0; while (m_consoleCommunication.getNumberOfConnections() != 1) { distributionControl.clearFileCaches(address); ++n; assertTrue(n < 10); } for (int i = 0; i < n; ++i) { assertTrue(readMessage(socket) instanceof ClearCacheMessage); } final File relativePath = new File("foo"); final File fullPath = new File(getDirectory(), relativePath.getPath()); createRandomFile(fullPath); final FileContents fileContents = new FileContents(getDirectory(), relativePath); distributionControl.sendFile(address, fileContents); assertTrue(readMessage(socket) instanceof DistributeFileMessage); socket.close(); m_processMessagesThread.start(); m_properties.setConsoleHost("localhost"); waitForNumberOfConnections(0); final Socket socket3 = new StubConnector(InetAddress.getByName(null).getHostName(), m_properties.getConsolePort(), ConnectionType.AGENT) .connect(); waitForNumberOfConnections(1); distributionControl.clearFileCaches(address); assertTrue(readMessage(socket3) instanceof ClearCacheMessage); distributionControl.setHighWaterMark(address, new StubCacheHighWaterMark("", 100)); assertTrue( readMessage(socket3) instanceof DistributionCacheCheckpointMessage); }