DispatchingEventSource { public DispatchingEventReplayer<T> replaying(String aggregateId, TimeRange timeRange) { return DispatchingEventReplayer.dispatching( causalOrderComparator, eventDispatcher, typeBinding.replaying(eventSource, aggregateId, timeRange)); } private  DispatchingEventSource(MultiTypeEventDispatcher<T> eventDispatcher,
                                   Comparator<Event> causalOrderComparator,
                                   EventTypeBinding typeBinding,
                                   EventSource eventSource); static DispatchingEventSource<T> dispatching(EventSource eventSource, Class<T> handlerClass); DispatchingEventReplayer<T> replaying(String aggregateId, TimeRange timeRange); DispatchingEventReplayer<T> replaying(String aggregateId); DispatchingCachedEventSource<T> preload(Collection<String> aggregateIds, TimeRange timeRange); DispatchingCachedEventSource<T> preload(Collection<String> aggregateIds); DispatchingCachedEventSource<T> preload(String...aggregateIds);  }
@Test public void replayAndCollectFirst() { String id1 = "id1"; String id2 = "id2"; eventBus.dispatch(PersonEvents.class, batch -> { batch.createdV2(nextTimestamp(), id1, "Arthur Putey", 41); batch.createdV1(nextTimestamp(), id2, "Arthur Dent"); batch.nameUpdated(nextTimestamp(), id1, "Arthur Daley"); batch.nameUpdated(nextTimestamp(), id2, "Arthur Mumby"); }); assertThat(createdEventDispatchingEventSource.replaying(id1).<String>collectFirst( caller -> (ts, id, n, age) -> caller.accept(n)), equalTo(Optional.of("Arthur Putey"))); assertThat(createdEventDispatchingEventSource.replaying(id2).<String>collectFirst( caller -> (ts, id, n, age) -> caller.accept(n)), equalTo(Optional.empty())); }
@Test public void replayAndCollectAll() { String id1 = "id1"; String id2 = "id2"; eventBus.dispatch(PersonEvents.class, batch -> { batch.createdV2(nextTimestamp(), id1, "Arthur Putey", 41); batch.createdV1(nextTimestamp(), id2, "Arthur Dent"); batch.nameUpdated(nextTimestamp(), id1, "Arthur Daley"); batch.nameUpdated(nextTimestamp(), id2, "Arthur Mumby"); }); assertThat(testEventDispatchingEventSource.replaying(id1).inAscendingOrder().collectAll(nameCollector), contains("Arthur Putey", "Arthur Daley")); assertThat(testEventDispatchingEventSource.replaying(id2).inAscendingOrder().collectAll(nameCollector), contains("Arthur Dent", "Arthur Mumby")); }