### Question:
EtcdLedgerManager implements LedgerManager { @Override public LedgerRangeIterator getLedgerRanges(long opTimeOutMs) { KeyStream<Long> ks = new KeyStream<>( kvClient, ByteSequence.fromString(EtcdUtils.getLedgerKey(scope, 0L)), ByteSequence.fromString(EtcdUtils.getLedgerKey(scope, Long.MAX_VALUE)), bs -> { UUID uuid = EtcdUtils.parseLedgerKey(bs.toStringUtf8()); return uuid.getLeastSignificantBits(); } ); KeyIterator<Long> ki = new KeyIterator<>(ks); return new LedgerRangeIterator() { @Override public boolean hasNext() throws IOException { try { return ki.hasNext(); } catch (Exception e) { if (e instanceof IOException) { throw ((IOException) e); } else { throw new IOException(e); } } } @Override public LedgerRange next() throws IOException { try { final List<Long> values = ki.next(); final Set<Long> ledgers = Sets.newTreeSet(); ledgers.addAll(values); return new LedgerRange(ledgers); } catch (Exception e) { if (e instanceof IOException) { throw ((IOException) e); } else { throw new IOException(e); } } } }; } 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 testLedgerRangeIterator() throws Exception { final int numLedgers = 100; createNumLedgers(numLedgers); long nextLedgerId = 0L; LedgerRangeIterator iter = lm.getLedgerRanges(0); while (iter.hasNext()) { LedgerRange lr = iter.next(); for (Long lid : lr.getLedgers()) { assertEquals(nextLedgerId, lid.longValue()); ++nextLedgerId; } } assertEquals((long) numLedgers, nextLedgerId); }