use of io.spine.test.event.TaskAdded in project core-java by SpineEventEngine.
the class EventStoreShould method read_events_by_time_and_type.
@Test
public void read_events_by_time_and_type() {
final Duration delta = Durations2.seconds(111);
final Timestamp present = getCurrentTime();
final Timestamp past = subtract(present, delta);
final Timestamp future = add(present, delta);
final Event eventInPast = taskAdded(past);
final Event eventInPresent = projectCreated(present);
final Event eventInFuture = taskAdded(future);
eventStore.append(eventInPast);
eventStore.append(eventInPresent);
eventStore.append(eventInFuture);
final EventFilter taskAddedType = EventFilter.newBuilder().setEventType(of(TaskAdded.class).value()).build();
final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(past).addFilter(taskAddedType).build();
final AtomicBoolean done = new AtomicBoolean(false);
final Collection<Event> resultEvents = newConcurrentHashSet();
eventStore.read(query, new ResponseObserver(resultEvents, done));
if (!done.get()) {
fail("Please use the MoreExecutors.directExecutor in EventStore for tests.");
}
assertSize(1, resultEvents);
final Event event = resultEvents.iterator().next();
assertEquals(eventInFuture, event);
}
use of io.spine.test.event.TaskAdded in project core-java by SpineEventEngine.
the class EventStoreShould method read_events_by_type.
@Test
public void read_events_by_type() {
final Timestamp now = getCurrentTime();
final Event taskAdded1 = taskAdded(now);
final Event projectCreated = projectCreated(now);
final Event teasAdded2 = taskAdded(now);
eventStore.append(taskAdded1);
eventStore.append(projectCreated);
eventStore.append(teasAdded2);
final EventFilter taskAddedType = EventFilter.newBuilder().setEventType(of(TaskAdded.class).value()).build();
final EventStreamQuery query = EventStreamQuery.newBuilder().addFilter(taskAddedType).build();
final AtomicBoolean done = new AtomicBoolean(false);
final Collection<Event> resultEvents = newConcurrentHashSet();
eventStore.read(query, new ResponseObserver(resultEvents, done));
if (!done.get()) {
fail("Please use the MoreExecutors.directExecutor in EventStore for tests.");
}
assertSize(2, resultEvents);
assertContainsAll(resultEvents, taskAdded1, teasAdded2);
}
Aggregations