### Question:
StandardDirectoryAgentServer extends AbstractServer { protected List<ServiceInfo> purgeExpiredServices() { return services.purge(); } StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService);  StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService, Settings settings); static void main(String[] args); static StandardDirectoryAgentServer newInstance(Settings settings); String[] getAddresses(); void setAddresses(String[] addresses); int getPort(); void setPort(int port); Scopes getScopes(); void setScopes(Scopes scopes); Attributes getAttributes(); void setAttributes(Attributes attributes); String getLanguage(); void setLanguage(String language); int getAdvertisementPeriod(); void setAdvertisementPeriod(int advertisementPeriod); int getExpiredServicesPurgePeriod(); void setExpiredServicesPurgePeriod(int expiredServicesPurgePeriod); void addServiceListener(ServiceListener listener); void removeServiceListener(ServiceListener listener); List<ServiceInfo> getServices();  }### Answer:
@Test public void testPurgeExpiredServices() throws Exception { final AtomicInteger removedCount = new AtomicInteger(0); ServiceListener listener = new ServiceListener() { public void serviceAdded(ServiceEvent event) { } public void serviceUpdated(ServiceEvent event) { } public void serviceRemoved(ServiceEvent event) { removedCount.incrementAndGet(); } }; Settings daSettings = newSettings(); daSettings.put(DA_EXPIRED_SERVICES_PURGE_PERIOD_KEY, 1); StandardDirectoryAgentServer da = StandardDirectoryAgentServer.newInstance(daSettings); da.addServiceListener(listener); da.start(); try { int lifetime = 3; ServiceURL serviceURL = new ServiceURL("foo: ServiceInfo service = new ServiceInfo(serviceURL, Locale.ENGLISH.getLanguage(), Scopes.DEFAULT, Attributes.NONE); ServiceAgentClient registrar = SLP.newServiceAgentClient(newSettings()); registrar.register(service); assert da.getServices().size() == 1; Thread.sleep(TimeUnit.SECONDS.toMillis(lifetime + daSettings.get(DA_EXPIRED_SERVICES_PURGE_PERIOD_KEY))); assert removedCount.get() == 1; } finally { da.removeServiceListener(listener); da.stop(); } }