### Question:
EtcdLedgerManager implements LedgerManager { private void processLedgers(KeyStream<Long> ks, Processor<Long> processor, VoidCallback finalCb, Object context, int successRc, int failureRc) { ks.readNext().whenCompleteAsync((ledgers, cause) -> { if (null != cause) { finalCb.processResult(failureRc, null, context); } else { if (ledgers.isEmpty()) { finalCb.processResult(successRc, null, context); } else { ledgers.forEach(l -> processor.process(l, finalCb)); processLedgers(ks, processor, finalCb, context, successRc, failureRc); } } }); } EtcdLedgerManager(Client client,
                      String scope); @Override CompletableFuture<Versioned<LedgerMetadata>> createLedgerMetadata(long ledgerId,
                                                                             LedgerMetadata metadata); @Override CompletableFuture<Void> removeLedgerMetadata(long ledgerId, Version version); @Override CompletableFuture<Versioned<LedgerMetadata>> readLedgerMetadata(long ledgerId); @Override CompletableFuture<Versioned<LedgerMetadata>> writeLedgerMetadata(long ledgerId, LedgerMetadata metadata,
                                                                            Version currentVersion); @Override void registerLedgerMetadataListener(long ledgerId, LedgerMetadataListener listener); @Override void unregisterLedgerMetadataListener(long ledgerId, LedgerMetadataListener listener); @Override void asyncProcessLedgers(Processor<Long> processor,
                                    VoidCallback finalCb,
                                    Object context,
                                    int successRc,
                                    int failureRc); @Override LedgerRangeIterator getLedgerRanges(long opTimeOutMs); @Override void close();  }### Answer:
@Test public void testProcessLedgers() throws Exception { final int numLedgers = 100; createNumLedgers(numLedgers); final CountDownLatch processLatch = new CountDownLatch(numLedgers); final CompletableFuture<Void> doneFuture = new CompletableFuture<>(); lm.asyncProcessLedgers( (l, cb) -> processLatch.countDown(), (rc, path, ctx) -> { if (Code.OK == rc) { FutureUtils.complete(doneFuture, null); } else { FutureUtils.completeExceptionally(doneFuture, BKException.create(rc)); } }, null, Code.OK, Code.MetaStoreException); result(doneFuture); processLatch.await(); }