Source:
<code>public void testStopDuringProcess() throws ExecutionException, InterruptedException, TimeoutException { PersistenceManager persistenceManager = extractComponent(cache, PersistenceManager.class); KeyPartitioner keyPartitioner = extractComponent(cache, KeyPartitioner.class); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k1", "v1", cache), keyPartitioner.getSegment("k1"), BOTH)); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k2", "v2", cache), keyPartitioner.getSegment("k2"), BOTH)); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k3", "v3", cache), keyPartitioner.getSegment("k3"), BOTH)); final CountDownLatch before = new CountDownLatch(1); final CountDownLatch after = new CountDownLatch(1); Future<Integer> c = fork(() -> { TestSubscriber<Object> subscriber = TestSubscriber.create(0); Flowable.fromPublisher(persistenceManager.publishEntries(true, true)) .subscribe(subscriber); before.countDown(); assertTrue(after.await(10, TimeUnit.SECONDS)); subscriber.request(Long.MAX_VALUE); subscriber.await(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertComplete(); return subscriber.valueCount(); }); assertTrue(before.await(30, TimeUnit.SECONDS)); Future<Void> stopFuture = fork(persistenceManager::stop); <START> expectException(TimeoutException.class, () -> stopFuture.get(150, TimeUnit.MILLISECONDS)); <END> after.countDown(); Integer count = c.get(30, TimeUnit.SECONDS); stopFuture.get(30, TimeUnit.SECONDS); assertEquals(3, count.intValue()); }</code><technical_language>This risky, main thread easily start stopFuture.get() 200ms persistenceManager.stop() running in parallel other tests. I suggest blocking publisher a latch instead. In fact I kill slowStore config, I feel slows choose operation slow down, 100ms is enough</technical_language>

Target:
public void testStopDuringProcess() throws ExecutionException, InterruptedException, TimeoutException { PersistenceManager persistenceManager = extractComponent(cache, PersistenceManager.class); KeyPartitioner keyPartitioner = extractComponent(cache, KeyPartitioner.class); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k1", "v1", cache), keyPartitioner.getSegment("k1"), BOTH)); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k2", "v2", cache), keyPartitioner.getSegment("k2"), BOTH)); CompletionStages.join(persistenceManager.writeToAllNonTxStores(MarshalledEntryUtil.create("k3", "v3", cache), keyPartitioner.getSegment("k3"), BOTH)); final CountDownLatch before = new CountDownLatch(1); final CountDownLatch after = new CountDownLatch(1); Future<Integer> c = fork(() -> { TestSubscriber<Object> subscriber = TestSubscriber.create(0); Flowable.fromPublisher(persistenceManager.publishEntries(true, true)) .subscribe(subscriber); before.countDown(); assertTrue(after.await(10, TimeUnit.SECONDS)); subscriber.request(Long.MAX_VALUE); subscriber.await(10, TimeUnit.SECONDS); subscriber.assertNoErrors(); subscriber.assertComplete(); return subscriber.valueCount(); }); assertTrue(before.await(30, TimeUnit.SECONDS)); Future<Void> stopFuture = fork(persistenceManager::stop); expectException(TimeoutException.class, () -> stopFuture.get(50, TimeUnit.MILLISECONDS)); after.countDown(); Integer count = c.get(30, TimeUnit.SECONDS); stopFuture.get(30, TimeUnit.SECONDS); assertEquals(3, count.intValue()); }