### Question:
StandardServiceAgentServer extends AbstractServiceAgent { public static StandardServiceAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); return new StandardServiceAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, settings); } StandardServiceAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer);  StandardServiceAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, Settings settings); static void main(String[] args); static StandardServiceAgentServer newInstance(Settings settings);  }### Answer:
@Test public void testRegisterUpdateDeregisterWithDirectoryAgent() throws Exception { Settings saSettings = newSettings(); saSettings.put(SA_UNICAST_PREFER_TCP, true); StandardServiceAgentServer sa = StandardServiceAgentServer.newInstance(saSettings); sa.start(); assert sa.getServices().isEmpty(); try { StandardDirectoryAgentServer da = newDirectoryAgent(); da.start(); assert da.getServices().isEmpty(); try { Thread.sleep(500); ServiceURL serviceURL = new ServiceURL("service:abstract:concrete: ServiceInfo service = new ServiceInfo(serviceURL, Defaults.get(LANGUAGE_KEY), Scopes.DEFAULT, Attributes.NONE); ServiceAgentClient client = SLP.newServiceAgentClient(saSettings); client.register(service); List<ServiceInfo> saServices = sa.getServices(); assert saServices.size() == 1; assert saServices.get(0).getKey().equals(service.getKey()); List<ServiceInfo> daServices = da.getServices(); assert daServices.size() == 1; assert daServices.get(0).getKey().equals(service.getKey()); client.deregister(service.getServiceURL(), service.getLanguage()); saServices = sa.getServices(); assert saServices.isEmpty(); daServices = da.getServices(); assert daServices.isEmpty(); } finally { da.stop(); } } finally { sa.stop(); } }
@Test public void testListenForDirectoryAgents() throws Exception { StandardServiceAgentServer sa = StandardServiceAgentServer.newInstance(newSettings()); sa.start(); try { assert sa.getDirectoryAgents().size() == 0; StandardDirectoryAgentServer directoryAgent = newDirectoryAgent(); directoryAgent.start(); try { Thread.sleep(500); assert sa.getDirectoryAgents().size() == 1; } finally { directoryAgent.stop(); } } finally { sa.stop(); } }
@Test public void testServiceRenewalNotPerformed() throws Exception { StandardServiceAgentServer sa = StandardServiceAgentServer.newInstance(newSettings()); sa.start(); try { int lifetime = 2; ServiceURL serviceURL = new ServiceURL("service:abstract:concrete: String language = Defaults.get(LANGUAGE_KEY); ServiceInfo service = new ServiceInfo(serviceURL, language, Scopes.DEFAULT, Attributes.NONE); ServiceAgentClient client = SLP.newServiceAgentClient(newSettings()); client.register(service); UserAgentClient ua = SLP.newUserAgentClient(newSettings()); List<ServiceInfo> services = ua.findServices(serviceURL.getServiceType(), null, null, null); assert services.size() == 1; TimeUnit.SECONDS.sleep(lifetime + 1); services = ua.findServices(serviceURL.getServiceType(), null, null, null); assert services.size() == 0; } finally { sa.stop(); } }