Source:
<code>public void testLedgerHandleAdvOutOfOrderWriteAndFrocedEnsembleChange() throws Exception { long ledgerId = 0xABCDEF; SyncObj syncObj1 = new SyncObj(); ByteBuffer entry; lh = bkc.createLedgerAdv(ledgerId, 3, 3, 3, digestType, ledgerPassword, null); entry = ByteBuffer.allocate(4); for (int i = 0; i < 5; i++) { entry.rewind(); entry.putInt(rng.nextInt(maxInt)); lh.addEntry(i, entry.array()); } ByteBuffer entry1 = ByteBuffer.allocate(4); entry1.putInt(rng.nextInt(maxInt)); lh.asyncAddEntry(10, entry1.array(), 0, entry1.capacity(), this, syncObj1); <START> Thread.sleep(5000); END> CountDownLatch sleepLatch1 = new CountDownLatch(1); ArrayList<BookieSocketAddress> ensemble; ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue(); sleepBookie(ensemble.get(0), sleepLatch1); sleepBookie(ensemble.get(1), sleepLatch1); sleepBookie(ensemble.get(2), sleepLatch1); startNewBookie(); startNewBookie(); startNewBookie(); for (int i = 5; i < 10; i++) { entry.rewind(); entry.putInt(rng.nextInt(maxInt)); lh.addEntry(i, entry.array()); } sleepLatch1.countDown(); synchronized (syncObj1) { while (syncObj1.counter < 1) { syncObj1.wait(); } assertEquals(BKException.Code.OK, syncObj1.rc); } lh.close(); lh = bkc.openLedger(ledgerId, digestType, ledgerPassword); for (int i = 0; i < 11; i++) { lh.readEntries(i, i); } lh.close(); bkc.deleteLedger(ledgerId); }</code><technical_language>avoid Thread.sleep(5000)? inspect ledger handle lh if pending add op received response</technical_language>

Target:
public void testLedgerHandleAdvOutOfOrderWriteAndFrocedEnsembleChange() throws Exception { long ledgerId = 0xABCDEF; SyncObj syncObj1 = new SyncObj(); ByteBuffer entry; lh = bkc.createLedgerAdv(ledgerId, 3, 3, 3, digestType, ledgerPassword, null); entry = ByteBuffer.allocate(4); for (int i = 0; i < 5; i++) { entry.rewind(); entry.putInt(rng.nextInt(maxInt)); lh.addEntry(i, entry.array()); } ByteBuffer entry1 = ByteBuffer.allocate(4); entry1.putInt(rng.nextInt(maxInt)); lh.asyncAddEntry(10, entry1.array(), 0, entry1.capacity(), this, syncObj1); java.util.Queue<PendingAddOp> myPendingAddOps = Whitebox.getInternalState(lh, "pendingAddOps"); PendingAddOp addOp = null; boolean pendingAddOpReceived = false; while (!pendingAddOpReceived) { addOp = myPendingAddOps.peek(); if (addOp.entryId == 10 && addOp.completed) { pendingAddOpReceived = true; } else { Thread.sleep(1000); } } CountDownLatch sleepLatch1 = new CountDownLatch(1); ArrayList<BookieSocketAddress> ensemble; ensemble = lh.getLedgerMetadata().getEnsembles().entrySet().iterator().next().getValue(); sleepBookie(ensemble.get(0), sleepLatch1); sleepBookie(ensemble.get(1), sleepLatch1); sleepBookie(ensemble.get(2), sleepLatch1); startNewBookie(); startNewBookie(); startNewBookie(); for (int i = 5; i < 10; i++) { entry.rewind(); entry.putInt(rng.nextInt(maxInt)); lh.addEntry(i, entry.array()); } sleepLatch1.countDown(); synchronized (syncObj1) { while (syncObj1.counter < 1) { syncObj1.wait(); } assertEquals(BKException.Code.OK, syncObj1.rc); } lh.close(); lh = bkc.openLedger(ledgerId, digestType, ledgerPassword); for (int i = 0; i < 11; i++) { lh.readEntries(i, i); } lh.close(); bkc.deleteLedger(ledgerId); }