### Question:
IdService extends AbstractIdleService { public String getNewClusterId() { return String.format("%08d", generateId(Type.CLUSTER)); } @Inject private  IdService(final ZKClient zkClient, Configuration conf);   IdService(final ZKClient zkClient, int startId, int incrementBy); String getNewClusterId(); JobId getNewJobId(String clusterId); TaskId getNewTaskId(JobId jobId);  }### Answer:
@Test public void testIds() throws InterruptedException, SQLException, ClassNotFoundException { final IdService idService = new IdService(zkClient, 3, 10); idService.startAndWait(); final int incrementsPerThread = 100; final int numThreads = 20; final CyclicBarrier barrier = new CyclicBarrier(numThreads); final CountDownLatch latch = new CountDownLatch(numThreads); ExecutorService executor = Executors.newFixedThreadPool(numThreads); for (int i = 0; i < numThreads; i++) { executor.execute(new Runnable() { @Override public void run() { for (int j = 0; j < incrementsPerThread; j++) { try { barrier.await(); idService.getNewClusterId(); } catch (Exception e) { Throwables.propagate(e); } } latch.countDown(); } }); } latch.await(); long expected = 3 + numThreads * incrementsPerThread * 10; long actual = Long.valueOf(idService.getNewClusterId()); Assert.assertEquals(expected, actual); }