/** * Collects an ordered list of Writes to execute to BookKeeper. * * @return The list of Writes to execute. */ private List<Write> getWritesToExecute() { // Calculate how much estimated space there is in the current ledger. final long maxTotalSize = this.config.getBkLedgerMaxSize() - getWriteLedger().ledger.getLength(); // Get the writes to execute from the queue. List<Write> toExecute = this.writes.getWritesToExecute(maxTotalSize); // Check to see if any writes executed on closed ledgers, in which case they either need to be failed (if deemed // appropriate, or retried). if (handleClosedLedgers(toExecute)) { // If any changes were made to the Writes in the list, re-do the search to get a more accurate list of Writes // to execute (since some may have changed Ledgers, more writes may not be eligible for execution). toExecute = this.writes.getWritesToExecute(maxTotalSize); } return toExecute; }
val maxSizeResult = q.getWritesToExecute(sizeLimit); val expectedMaxSizeResult = new ArrayList<Write>(); for (Write w : writes) { writes.get(0).complete(); writes.get(1).beginAttempt(); val result1 = q.getWritesToExecute(Long.MAX_VALUE); val result2 = q.getWritesToExecute(Long.MAX_VALUE); Assert.assertEquals("Unexpected writes fetched when in-progress writes exist after non-in-progress writes.", 0, result2.size()); val result3 = q.getWritesToExecute(Long.MAX_VALUE); AssertExtensions.assertListEquals("Unexpected writes fetched when ledger changed.", writes.subList(beginIndex, ledgerChangeIndex), result3, Object::equals); result3.forEach(Write::complete); q.removeFinishedWrites(); val result4 = q.getWritesToExecute(Long.MAX_VALUE); AssertExtensions.assertListEquals("Unexpected writes fetched from the end, after ledger changed.", writes.subList(ledgerChangeIndex, writes.size()), result4, Object::equals);
AssertExtensions.assertThrows( "getWritesToExecute() worked after close().", () -> q.getWritesToExecute(1), ex -> ex instanceof ObjectClosedException); AssertExtensions.assertThrows(