Source:
public void testLedgerCreateAdvWithLedgerIdInLoop() throws Exception { int ledgerCount = 40; long maxId = Long.MAX_VALUE; if (!baseConf.getLedgerManagerFactoryClass().equals(LongHierarchicalLedgerManagerFactory.class)) { maxId = 9999999999L; } rng.longs(ledgerCount, 1, maxId) .mapToObj(ledgerId -> { LOG.info("Creating adv ledger with id {}", ledgerId); return bkc.newCreateLedgerOp() .withEnsembleSize(1).withWriteQuorumSize(1).withAckQuorumSize(1) .withDigestType(org.apache.bookkeeper.client.api.DigestType.CRC32) .withPassword(ledgerPassword).makeAdv().withLedgerId(ledgerId) .execute() .thenApply(writer -> { LOG.info("Writing stream of entries to {}", numEntriesToWrite, ledgerId); List<Integer> entries = rng.ints(numEntriesToWrite, 0, maxInt) .mapToObj(Integer::valueOf) .collect(Collectors.toList()); CompletableFuture<?> lastRequest = null; for (int i = 0; i < entries.size(); i++) { ByteBuf entry = Unpooled.buffer(4); entry.writeInt(entries.get(i)); LOG.info("Writing {}:{} as {}", ledgerId, i, entries.get(i)); lastRequest = writer.write(i, entry); } lastRequest.join(); return Pair.of(writer, entries); }); }) .parallel().map(CompletableFuture::join) .forEach(e -> { try { WriteAdvHandle handle = e.getLeft(); List<Integer> entries = e.getRight(); LOG.info("Read entries for ledger: {}", handle); readEntries(handle, entries); handle.close(); bkc.deleteLedger(handle.getId()); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); Assert.fail("Test interrupted"); } catch (Exception ex) { LOG.info("Readback failed with exception", ex); Assert.fail("Readback failed " + ex.getMessage()); } }); }

Target:
public void testLedgerCreateAdvWithLedgerIdInLoop() throws Exception { int ledgerCount = 40; long maxId = 9999999999L; if (baseConf.getLedgerManagerFactoryClass().equals(LongHierarchicalLedgerManagerFactory.class)) { maxId = Long.MAX_VALUE; } rng.longs(ledgerCount, 0, maxId) .mapToObj(ledgerId -> { LOG.info("Creating adv ledger with id {}", ledgerId); return bkc.newCreateLedgerOp() .withEnsembleSize(1).withWriteQuorumSize(1).withAckQuorumSize(1) .withDigestType(org.apache.bookkeeper.client.api.DigestType.CRC32) .withPassword(ledgerPassword).makeAdv().withLedgerId(ledgerId) .execute() .thenApply(writer -> { LOG.info("Writing stream of entries to {}", numEntriesToWrite, ledgerId); List<ByteBuf> entries = rng.ints(numEntriesToWrite, 0, maxInt) .mapToObj(i -> { ByteBuf entry = Unpooled.buffer(4); entry.retain(); entry.writeInt(i); return entry; }) .collect(Collectors.toList()); CompletableFuture<?> lastRequest = null; int i = 0; for (ByteBuf entry : entries) { long entryId = i++; LOG.info("Writing {}:{} as {}", ledgerId, entryId, entry.slice().readInt()); lastRequest = writer.write(entryId, entry); } lastRequest.join(); return Pair.of(writer, entries); }); }) .parallel().map(CompletableFuture::join) .forEach(e -> { try { WriteAdvHandle handle = e.getLeft(); List<ByteBuf> entries = e.getRight(); LOG.info("Read entries for ledger: {}", handle.getId()); readEntries(handle, entries); entries.forEach(ByteBuf::release); handle.close(); bkc.deleteLedger(handle.getId()); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); Assert.fail("Test interrupted"); } catch (Exception ex) { LOG.info("Readback failed with exception", ex); Assert.fail("Readback failed " + ex.getMessage()); } }); }