/** * Returns a stream of events that should be recorded. By default, an empty stream returned. * * @return stream of events * @throws Exception if the command is to be rejected, an exception has to be thrown. In this case, no events will * be recorded */ public EventStream<S> events() throws Exception { return EventStream.empty(); }
/** * @param state state * @param stream stream of events * @param <S> state type * @return event stream with a state and a stream */ public static <S> EventStream<S> ofWithState(S state, Stream<? extends Event> stream) { return new EventStream<>(state, stream); }
@Test public void testOf2() throws Exception { EventStream<String> test = EventStream.ofWithState("test", EventCausalityEstablished.builder().build()); assertEquals(test.getState(), "test"); assertEquals(test.getStream().collect(Collectors.<Event>toSet()).size(), 1); }
@Override public EventStream<Void> events() throws Exception { TestEvent event = new TestEvent(test, reference); return EventStream.of(event); }
@Test public void testBuilder1() throws Exception { EventStream<String> test = EventStream.<String>builder().add(EventCausalityEstablished.builder().build()).build(); assertNull(test.getState()); Event event = test.getStream().findFirst().get(); assertTrue(event instanceof EventCausalityEstablished); }
@Override public EventStream<TestEvent> events() throws Exception { TestEvent event = new TestEvent(); return EventStream.ofWithState(event, event); }
@Test @SneakyThrows public void passthrough() { EventStream<Void> eventStream = new SomeCommand("a").events(null, null); assertTrue(eventStream.getStream().anyMatch(e -> e instanceof SomeEvent)); }
@Test public void testOf4() throws Exception { EventStream<String> test = EventStream.ofWithState("test", Stream.of(EventCausalityEstablished.builder().build(), EventCausalityEstablished.builder().build())); assertEquals(test.getState(), "test"); assertEquals(test.getStream().collect(Collectors.<Event>toSet()).size(), 2); }
@Override public EventStream<Void> events() throws Exception { return EventStream.of(new SomeEvent()); } }
@Test public void testBuilder() throws Exception { EventStream<String> test = EventStream.builder("test").add(EventCausalityEstablished.builder().build()).build(); assertEquals(test.getState(), "test"); Event event = test.getStream().findFirst().get(); assertTrue(event instanceof EventCausalityEstablished); }
@Override public EventStream<Created> events() throws Exception { Created created = new Created(); return EventStream.ofWithState(created, created); }
@Test public void testOf3() throws Exception { EventStream<String> test = EventStream.ofWithState("test", EventCausalityEstablished.builder().build(), EventCausalityEstablished.builder().build()); assertEquals(test.getState(), "test"); assertEquals(test.getStream().collect(Collectors.<Event>toSet()).size(), 2); }
@Override public EventStream<Void> events() throws Exception { return EventStream.of(BogusEvent.builder().build()); }
@Override public EventStream<UUID> events() throws Exception { TestEvent event = new TestEvent(prop); return EventStream.ofWithState(event.uuid(), event); }
/** * @param stream stream of events * @param <S> state type * @return event stream with a state set to <code>null</code> and a stream */ public static <S> EventStream<S> of(Stream<? extends Event> stream) { return new EventStream<>(null, stream); }