WorkerAdvertiser { public synchronized void advertiseAvailability() { checkInitialized(); logger.info("Advertising availability at <" + listenAddress + ":" + listenPort + ">"); try { serviceDiscovery.registerService(getServiceInstance()); } catch (Exception e) { throw new RuntimeException(e); } } @Inject  WorkerAdvertiser(ZookeeperConfig zookeeperConfig, ServiceDiscovery<WorkerMetadata> serviceDiscovery); synchronized void initListenInfo(@Nonnull String address, int port); synchronized void advertiseAvailability(); synchronized void deAdvertiseAvailability(); UUID getWorkerId();  }
@Test public void testAdvertiseAvailability() throws Exception { workerAdvertiser.initListenInfo("127.0.0.1", 12345); workerAdvertiser.advertiseAvailability(); Collection<ServiceInstance<WorkerMetadata>> instances = serviceDiscovery.queryForInstances(zookeeperConfig.getWorkerServiceName()); assertEquals(1, instances.size()); WorkerMetadata workerMetadata = instances.iterator().next().getPayload(); assertEquals(workerAdvertiser.getWorkerId(), workerMetadata.getWorkerId()); }