### Question:
ServiceDiscovery { protected void subscribe(final WebSocketSession session) { try { for (final DiscoveryConfig discoveryConfig : serviceRepository.getDiscoveryConfigs()) { subscribe(session, discoveryConfig); } } catch (final Throwable e) { logger.warn("subscribe services failed", e); } } ServiceDiscovery(final ServiceRepository serviceRepository, final ArtemisClientConfig config); void registerDiscoveryConfig(DiscoveryConfig config); Service getService(DiscoveryConfig config);  }### Answer:
@Test public void testSubscribe() throws Exception { final ServiceRepository serviceRepository = new ServiceRepository(ArtemisClientConstants.DiscoveryClientConfig); final String serviceId = Services.newServiceId(); final DiscoveryConfig discoveryConfig = new DiscoveryConfig(serviceId); final Set<Instance> instances = Sets.newHashSet(Instances.newInstance(serviceId), Instances.newInstance(serviceId)); final CountDownLatch addCount = new CountDownLatch(instances.size() * 2); final CountDownLatch deleteCount = new CountDownLatch(instances.size()); final List<ServiceChangeEvent> serviceChangeEvents = Lists.newArrayList(); serviceRepository.registerServiceChangeListener(discoveryConfig, new ServiceChangeListener() { @Override public void onChange(ServiceChangeEvent event) { serviceChangeEvents.add(event); if (InstanceChange.ChangeType.DELETE.equals(event.changeType())) { deleteCount.countDown(); } if (InstanceChange.ChangeType.NEW.equals(event.changeType())) { addCount.countDown(); } } }); Threads.sleep(2000); final InstanceRepository instanceRepository = new InstanceRepository(ArtemisClientConstants.RegistryClientConfig); instanceRepository.register(instances); Assert.assertTrue(addCount.await(2, TimeUnit.SECONDS)); instanceRepository.unregister(instances); Assert.assertTrue(deleteCount.await(2, TimeUnit.SECONDS)); Assert.assertTrue(3 * instances.size() <= serviceChangeEvents.size()); }