Source:
public void testMergeSegmentWithDifferentProcessingGroupsAndSequencingPolicies() throws Exception { EventMessageHandler otherHandler = mock(EventMessageHandler.class); when(otherHandler.canHandle(any())).thenReturn(true); when(otherHandler.supportsReset()).thenReturn(true); EventHandlerInvoker mockInvoker = SimpleEventHandlerInvoker.builder() .eventHandlers(singleton(otherHandler)) .sequencingPolicy(m -> 0) .build(); initProcessor(TrackingEventProcessorConfiguration.forParallelProcessing(2).andBatchSize(5), builder -> builder .eventHandlerInvoker(new MultiEventHandlerInvoker(eventHandlerInvoker, mockInvoker))); List<EventMessage<?>> handledEvents = new CopyOnWriteArrayList<>(); when(mockHandler.handle(any())).thenAnswer(i -> { TrackedEventMessage<?> message = i.getArgument(0); System.out.println(Thread.currentThread().getName() + " handled " + message.trackingToken()); return handledEvents.add(message);}); publishEvents(10); testSubject.start(); while (testSubject.processingStatus().size() < 2 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } System.out.println("Asked to release Segment 1"); testSubject.releaseSegment(1); while (testSubject.processingStatus().size() != 1 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } publishEvents(10); testSubject.mergeSegment(0); publishEvents(10); while (testSubject.processingStatus().size() != 1 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } assertWithin(5, TimeUnit.SECONDS, () -> assertEquals(30, handledEvents.size())); Thread.sleep(100); assertEquals(30, handledEvents.size()); }

Target:
public void testMergeSegmentWithDifferentProcessingGroupsAndSequencingPolicies() throws Exception { EventMessageHandler otherHandler = mock(EventMessageHandler.class); when(otherHandler.canHandle(any())).thenReturn(true); when(otherHandler.supportsReset()).thenReturn(true); EventHandlerInvoker mockInvoker = SimpleEventHandlerInvoker.builder() .eventHandlers(singleton(otherHandler)) .sequencingPolicy(m -> 0) .build(); initProcessor(TrackingEventProcessorConfiguration.forParallelProcessing(2).andBatchSize(5), builder -> builder .eventHandlerInvoker(new MultiEventHandlerInvoker(eventHandlerInvoker, mockInvoker))); List<EventMessage<?>> handledEvents = new CopyOnWriteArrayList<>(); when(mockHandler.handle(any())).thenAnswer(i -> { TrackedEventMessage<?> message = i.getArgument(0); return handledEvents.add(message); }); publishEvents(10); testSubject.start(); while (testSubject.processingStatus().size() < 2 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } System.out.println("Asked to release Segment 1"); testSubject.releaseSegment(1); while (testSubject.processingStatus().size() != 1 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } publishEvents(10); testSubject.mergeSegment(0); publishEvents(10); while (testSubject.processingStatus().size() != 1 || !testSubject.processingStatus().values().stream().allMatch(EventTrackerStatus::isCaughtUp)) { Thread.sleep(10); } assertWithin(5, TimeUnit.SECONDS, () -> assertEquals(30, handledEvents.size())); Thread.sleep(100); assertEquals(30, handledEvents.size()); }