DelegatingAsyncEventStore implements EventStoreAsync { @Override public final CompletableFuture<Long> appendToStream(final StreamId streamId, final long expectedVersion, final List<CommonEvent> toAppend) { return CompletableFuture.supplyAsync(new Supplier<Long>() { @Override public Long get() { return delegate.appendToStream(streamId, expectedVersion, toAppend); } }, executor); } DelegatingAsyncEventStore(@NotNull final Executor executor, @NotNull final EventStore delegate); @Override final CompletableFuture<Void> open(); @Override final void close(); @Override final CompletableFuture<CommonEvent> readEvent(final StreamId streamId, final long eventNumber); @Override final CompletableFuture<StreamEventsSlice> readEventsForward(final StreamId streamId,
            final long start, final int count); @Override final CompletableFuture<StreamEventsSlice> readEventsBackward(final StreamId streamId,
            final long start, final int count); @Override final CompletableFuture<Void> deleteStream(final StreamId streamId, final long expected,
            final boolean hardDelete); @Override final CompletableFuture<Void> deleteStream(final StreamId streamId, final boolean hardDelete); @Override final CompletableFuture<Long> appendToStream(final StreamId streamId, final long expectedVersion,
            final List<CommonEvent> toAppend); @Override final CompletableFuture<Long> appendToStream(final StreamId streamId, final long expectedVersion,
            final CommonEvent... events); @Override final CompletableFuture<Long> appendToStream(final StreamId streamId,
            final List<CommonEvent> toAppend); @Override final CompletableFuture<Long> appendToStream(final StreamId streamId,
            final CommonEvent... events); @Override final CompletableFuture<Boolean> streamExists(final StreamId streamId); @Override final CompletableFuture<StreamState> streamState(final StreamId streamId); @Override final boolean isSupportsCreateStream(); @Override CompletableFuture<Void> createStream(final StreamId streamId);  }
@Test public void testAppendToStreamArrayExpectedVersion() throws Exception { final StreamId streamId = new SimpleStreamId("MyStream"); final CommonEvent eventOne = event("One"); final CommonEvent eventTwo = event("Two"); when(delegate.appendToStream(streamId, ANY_VERSION, eventOne, eventTwo)).thenReturn(1L); final long result = testee.appendToStream(streamId, ANY_VERSION, eventOne, eventTwo).get(); assertThat(result).isEqualTo(1L); verify(delegate).appendToStream(streamId, ANY_VERSION, eventOne, eventTwo); }
@Test public void testAppendToStreamArrayAnyVersion() throws Exception { final StreamId streamId = new SimpleStreamId("MyStream"); final CommonEvent eventOne = event("One"); final CommonEvent eventTwo = event("Two"); when(delegate.appendToStream(streamId, eventOne, eventTwo)).thenReturn(1L); final long result = testee.appendToStream(streamId, eventOne, eventTwo).get(); assertThat(result).isEqualTo(1L); verify(delegate).appendToStream(streamId, eventOne, eventTwo); }
@Test public void testAppendToStreamListExpectedVersion() throws Exception { final StreamId streamId = new SimpleStreamId("MyStream"); final List<CommonEvent> events = new ArrayList<>(); when(delegate.appendToStream(streamId, ANY_VERSION, events)).thenReturn(1L); final long result = testee.appendToStream(streamId, ANY_VERSION, events).get(); assertThat(result).isEqualTo(1L); verify(delegate).appendToStream(streamId, ANY_VERSION, events); }
@Test public void testAppendToStreamListAnyVersion() throws Exception { final StreamId streamId = new SimpleStreamId("MyStream"); final List<CommonEvent> events = new ArrayList<>(); when(delegate.appendToStream(streamId, events)).thenReturn(1L); final long result = testee.appendToStream(streamId, events).get(); assertThat(result).isEqualTo(1L); verify(delegate).appendToStream(streamId, events); }