Source:
public void testLedgerHandleAdvFunctionality() throws Exception { long ledgerId = 0xABCDEF; lh = bkc.createLedgerAdv(ledgerId, 5, 3, 2, digestType, ledgerPassword, null); numEntriesToWrite = 3; ByteBuffer entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); lh.addEntry(0, entry.array()); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); CountDownLatch latch = new CountDownLatch(1); final int[] returnedRC = new int[1]; lh.asyncAddEntry(1, entry.array(), new AddCallback() { @Override public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) { CountDownLatch latch = (CountDownLatch) ctx; returnedRC[0] = rc; latch.countDown(); } }, latch); latch.await(); assertTrue("Returned code is expected to be OK", returnedRC[0] == BKException.Code.OK); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); try { lh.addEntry(2, entry.array(), -3, 9); fail("AddEntry is called with negative offset and incorrect length," + "so it is expected to throw IndexOutOfBoundsException"); } catch (RuntimeException exception) { } entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); lh.addEntry(2, entry.array()); lh.close(); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); try { lh.addEntry(3, entry.array()); fail("AddEntry is called after the close of LedgerHandle," + "so it is expected to throw BKLedgerClosedException"); } catch (BKLedgerClosedException exception) { } readEntries(lh, entries1); bkc.deleteLedger(ledgerId); }

Target:
public void testLedgerHandleAdvFunctionality() throws Exception { long ledgerId = 0xABCDEF; lh = bkc.createLedgerAdv(ledgerId, 5, 3, 2, digestType, ledgerPassword, null); numEntriesToWrite = 3; ByteBuffer entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); lh.addEntry(0, entry.array()); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); CountDownLatch latch = new CountDownLatch(1); final int[] returnedRC = new int[1]; lh.asyncAddEntry(1, entry.array(), new AddCallback() { @Override public void addComplete(int rc, LedgerHandle lh, long entryId, Object ctx) { CountDownLatch latch = (CountDownLatch) ctx; returnedRC[0] = rc; latch.countDown(); } }, latch); latch.await(); assertTrue("Returned code is expected to be OK", returnedRC[0] == BKException.Code.OK); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); try { lh.addEntry(2, entry.array(), -3, 9); fail("AddEntry is called with negative offset and incorrect length," + "so it is expected to throw RuntimeException/IndexOutOfBoundsException"); } catch (RuntimeException exception) { } entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); lh.addEntry(2, entry.array()); lh.close(); entry = ByteBuffer.allocate(4); entry.putInt(rng.nextInt(maxInt)); entry.position(0); entries1.add(entry.array()); try { lh.addEntry(3, entry.array()); fail("AddEntry is called after the close of LedgerHandle," + "so it is expected to throw BKLedgerClosedException"); } catch (BKLedgerClosedException exception) { } readEntries(lh, entries1); bkc.deleteLedger(ledgerId); }