### Question:
ResourceBalancerService extends AbstractIdleService { protected ResourceBalancerService(String serviceName, int partitionCount, ZKClient zkClient, DiscoveryService discoveryService, final DiscoveryServiceClient discoveryServiceClient) { this.serviceName = serviceName; this.partitionCount = partitionCount; this.discoveryService = discoveryService; final ZKClient zk = ZKClients.namespace(zkClient, "/" + serviceName); this.election = new LeaderElection(zk, serviceName, new ElectionHandler() { private ResourceCoordinator coordinator; @Override public void leader() { coordinator = new ResourceCoordinator(zk, discoveryServiceClient, new BalancedAssignmentStrategy()); coordinator.startAndWait(); } @Override public void follower() { if (coordinator != null) { coordinator.stopAndWait(); coordinator = null; } } }); this.resourceClient = new ResourceCoordinatorClient(zk); this.completion = SettableFuture.create(); } protected  ResourceBalancerService(String serviceName,
                                    int partitionCount,
                                    ZKClient zkClient,
                                    DiscoveryService discoveryService,
                                    final DiscoveryServiceClient discoveryServiceClient);   }### Answer:
@Test public void testResourceBalancerService() throws Exception { ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build(); zkClient.startAndWait(); try (ZKDiscoveryService discoveryService = new ZKDiscoveryService(zkClient)) { final TestBalancerService stopFailureService = new TestBalancerService("test", 4, zkClient, discoveryService, discoveryService, false, false); stopFailureService.startAndWait(); Tasks.waitFor(ImmutableSet.of(0, 1, 2, 3), new Callable<Set<Integer>>() { @Override public Set<Integer> call() throws Exception { return stopFailureService.getPartitions(); } }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); Cancellable cancellable = discoveryService.register( new Discoverable("test", new InetSocketAddress(InetAddress.getLoopbackAddress(), 1234))); try { Tasks.waitFor(2, new Callable<Integer>() { @Override public Integer call() throws Exception { return stopFailureService.getPartitions().size(); } }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { cancellable.cancel(); } } finally { zkClient.stopAndWait(); } }