InMemoryEventStore extends AbstractReadableEventStore implements IInMemoryEventStore { @Override public final StreamEventsSlice readEventsForward(final StreamId streamId, final long start, final int count) { Contract.requireArgNotNull("streamId", streamId); Contract.requireArgMin("start", start, 0); Contract.requireArgMin("count", count, 1); ensureOpen(); final List<CommonEvent> events = getStream(streamId, ExpectedVersion.ANY.getNo()).getEvents(); final List<CommonEvent> result = new ArrayList<CommonEvent>(); for (int i = (int) start; (i < (start + count)) && (i < events.size()); i++) { result.add(events.get(i)); } final long fromEventNumber = start; final long nextEventNumber = (start + result.size()); final boolean endOfStream = (result.size() < count); return new StreamEventsSlice(fromEventNumber, result, nextEventNumber, endOfStream); } InMemoryEventStore(@NotNull final Executor executor); @Override final InMemoryEventStore open(); @Override final void close(); @Override final boolean isSupportsCreateStream(); @Override final void createStream(final StreamId streamId); @Override final boolean streamExists(final StreamId streamId); @Override final CommonEvent readEvent(final StreamId streamId, final long eventNumber); @Override final StreamEventsSlice readEventsForward(final StreamId streamId, final long start, final int count); @Override final StreamEventsSlice readEventsBackward(final StreamId streamId, final long start, final int count); @Override final void deleteStream(final StreamId streamId, final long expected, final boolean hardDelete); @Override final void deleteStream(final StreamId streamId, final boolean hardDelete); @Override final long appendToStream(final StreamId streamId, final long expectedVersion, final List<CommonEvent> toAppend); @Override final long appendToStream(final StreamId streamId, final long expectedVersion, final CommonEvent... events); @Override final long appendToStream(final StreamId streamId, final List<CommonEvent> toAppend); @Override final long appendToStream(final StreamId streamId, final CommonEvent... events); @Override final Subscription subscribeToStream(final StreamId streamId, final long eventNumber,
            final BiConsumer<Subscription, CommonEvent> onEvent, final BiConsumer<Subscription, Exception> onDrop); @Override final void unsubscribeFromStream(final Subscription subscription); @Override final StreamState streamState(final StreamId streamId);  }
@Test public void testReadEventsForward() { final StreamId streamId = new SimpleStreamId("MyStream"); final CommonEvent eventOne = event("One"); final CommonEvent eventTwo = event("Two"); final CommonEvent eventThree = event("Three"); testee.appendToStream(streamId, ExpectedVersion.NO_OR_EMPTY_STREAM.getNo(), eventOne, eventTwo, eventThree); final StreamEventsSlice slice1 = testee.readEventsForward(streamId, 0, 2); assertThat(slice1.getEvents()).containsExactly(eventOne, eventTwo); assertThat(slice1.getFromEventNumber()).isEqualTo(0); assertThat(slice1.getNextEventNumber()).isEqualTo(2); assertThat(slice1.isEndOfStream()).isFalse(); final StreamEventsSlice slice2 = testee.readEventsForward(streamId, slice1.getNextEventNumber(), 2); assertThat(slice2.getEvents()).containsExactly(eventThree); assertThat(slice2.getFromEventNumber()).isEqualTo(2); assertThat(slice2.getNextEventNumber()).isEqualTo(3); assertThat(slice2.isEndOfStream()).isTrue(); }