private void processCommits(Collection<List<CompletableOperation>> items) { try { do { this.stateUpdater.process(items.stream().flatMap(List::stream).map(CompletableOperation::getOperation).iterator()); items = this.commitQueue.poll(MAX_COMMIT_QUEUE_SIZE); } while (!items.isEmpty()); } catch (Throwable ex) { // MemoryStateUpdater.process() should only throw DataCorruptionExceptions, but just in case it // throws something else (i.e. NullPtr), we still need to handle it. log.error("{}: MemoryStateUpdater.process failure.", traceObjectId, ex); // Then fail the remaining operations (which also handles fatal errors) and bail out. if (isFatalException(ex)) { Callbacks.invokeSafely(OperationProcessor.this::errorHandler, ex, null); } } }
/** * Tests the basic ability dequeue items using poll() as they are added. */ @Test public void testAddSinglePoll() throws Exception { @Cleanup BlockingDrainingQueue<Integer> queue = new BlockingDrainingQueue<>(); for (int i = 0; i < ITEM_COUNT; i++) { queue.add(i); Queue<Integer> entries = queue.poll(MAX_READ_COUNT); Assert.assertEquals("Unexpected number of items polled.", 1, entries.size()); Assert.assertEquals("Unexpected value polled from queue.", i, (int) entries.peek()); } val remainingItems = queue.poll(1); Assert.assertEquals("poll() did not return an empty collection when queue was empty.", 0, remainingItems.size()); }
operations = this.operationQueue.poll(MAX_READ_AT_ONCE);
/** * Tests the basic ability to dequeue items as a batch using poll(). */ @Test public void testAddMultiPoll() throws Exception { @Cleanup BlockingDrainingQueue<Integer> queue = new BlockingDrainingQueue<>(); populate(queue); for (int i = 0; i < ITEM_COUNT; i += MAX_READ_COUNT) { Queue<Integer> entries = queue.poll(MAX_READ_COUNT); int expectedCount = Math.min(MAX_READ_COUNT, ITEM_COUNT - i); Assert.assertEquals("Unexpected number of items polled.", expectedCount, entries.size()); int expectedValue = i; for (int value : entries) { Assert.assertEquals("Unexpected value polled from queue.", expectedValue, value); expectedValue++; } } }
() -> queue.poll(MAX_READ_COUNT), ex -> ex instanceof IllegalStateException); Assert.assertEquals("Unexpected value polled from queue.", valueToQueue, (int) result.peek()); val remainingItems = queue.poll(MAX_READ_COUNT); Assert.assertEquals("Queue was not emptied out after take() completed successfully.", 0, remainingItems.size());