Search in sources :

Example 1 with TaskAdded

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskAdded(io.spine.test.event.TaskAdded) EventStreamQuery(io.spine.server.event.EventStreamQuery) Event(io.spine.base.Event) Duration(com.google.protobuf.Duration) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 2 with TaskAdded

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskAdded(io.spine.test.event.TaskAdded) EventStreamQuery(io.spine.server.event.EventStreamQuery) Event(io.spine.base.Event) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (com.google.protobuf.Timestamp)2 Event (io.spine.base.Event)2 EventStreamQuery (io.spine.server.event.EventStreamQuery)2 TaskAdded (io.spine.test.event.TaskAdded)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Test (org.junit.Test)2 Duration (com.google.protobuf.Duration)1