Source:
<code>public void testOffHeapStore() throws Exception { final AsyncDispatcher<MockMessage> asyncDispatcher = threadLockingDispatcherFactory.createAsyncDispatcher(module); final AtomicBoolean allThreadsLocked = new AtomicBoolean(false); ThreadLockingSyncDispatcher<MockMessage> threadLockingSyncDispatcher = threadLockingDispatcherFactory.getThreadLockingSyncDispatcher(); threadLockingSyncDispatcher.waitForThreads(NUM_THREADS).thenRun(() -> { allThreadsLocked.set(true); }); final List<CompletableFuture<MockMessage>> futures = new ArrayList<>(); for (int i = 0; i < NUM_THREADS + QUEUE_SIZE; i++) { futures.add(asyncDispatcher.send(new MockMessage(Integer.toString(i)))); } await().atMost(30, SECONDS).until(() -> allThreadsLocked.get()); assertEquals(0, threadLockingSyncDispatcher.getNumExtraThreadsWaiting()); assertEquals(QUEUE_SIZE, asyncDispatcher.getQueueSize()); int numOfMessagesInOffHeap = 0; for (int i = NUM_THREADS + QUEUE_SIZE; i < NUM_THREADS + QUEUE_SIZE + OFFHEAP_MESSAGES; i++) { CompletableFuture<MockMessage> future = asyncDispatcher.send(new MockMessage(Integer.toString(i))); Thread.sleep(100); futures.add(future); } assertThat(offHeapStore.getNumOfMessages(module.getId()), equalTo(OFFHEAP_MESSAGES -1)); threadLockingSyncDispatcher.release(); await().atMost(30, SECONDS).until(() -> asyncDispatcher.getQueueSize(), equalTo(0)); await().atMost(30, SECONDS).until(() -> threadLockingDispatcherFactory.getNumMessageDispatched(), greaterThan(QUEUE_SIZE + OFFHEAP_MESSAGES)); <START> <END> CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[]{})); asyncDispatcher.close(); }</code><technical_language>of this behavior apply. longer tests applicable</technical_language>

Target:
public void testOffHeapStore() throws Exception { final AsyncDispatcher<MockMessage> asyncDispatcher = threadLockingDispatcherFactory.createAsyncDispatcher(module); final AtomicBoolean allThreadsLocked = new AtomicBoolean(false); ThreadLockingSyncDispatcher<MockMessage> threadLockingSyncDispatcher = threadLockingDispatcherFactory.getThreadLockingSyncDispatcher(); threadLockingSyncDispatcher.waitForThreads(NUM_THREADS).thenRun(() -> { allThreadsLocked.set(true); }); final List<CompletableFuture<MockMessage>> futures = new ArrayList<>(); for (int i = 0; i < NUM_THREADS + QUEUE_SIZE; i++) { futures.add(asyncDispatcher.send(new MockMessage(Integer.toString(i)))); } await().atMost(30, SECONDS).until(allThreadsLocked::get); assertEquals(0, threadLockingSyncDispatcher.getNumExtraThreadsWaiting()); assertEquals(QUEUE_SIZE, asyncDispatcher.getQueueSize()); int numOfMessagesInOffHeap = 0; for (int i = NUM_THREADS + QUEUE_SIZE; i < NUM_THREADS + QUEUE_SIZE + OFFHEAP_MESSAGES; i++) { CompletableFuture<MockMessage> future = asyncDispatcher.send(new MockMessage(Integer.toString(i))); futures.add(future); } assertThat(offHeapStore.getNumOfMessages(module.getId()), greaterThanOrEqualTo(OFFHEAP_MESSAGES-1)); threadLockingSyncDispatcher.release(); await().atMost(30, SECONDS).until(asyncDispatcher::getQueueSize, equalTo(0)); await().atMost(30, SECONDS).until(threadLockingDispatcherFactory::getNumMessageDispatched, greaterThan(QUEUE_SIZE + OFFHEAP_MESSAGES)); CompletableFuture.allOf(futures.toArray(new CompletableFuture<?>[]{})); asyncDispatcher.close(); }