Search in sources :

Example 1 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class EventBusShould method store_an_event.

@Test
public void store_an_event() {
    final Command command = command(createProject());
    eventBus.register(new EBProjectCreatedNoOpSubscriber());
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> events = readEvents(eventBus);
    assertSize(1, events);
}
Also used : Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 2 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class EventBusShould method deliver_postponed_event_to_dispatcher_using_configured_executor.

@Test
public void deliver_postponed_event_to_dispatcher_using_configured_executor() {
    final BareDispatcher dispatcher = new BareDispatcher();
    eventBusWithPosponedExecution.register(dispatcher);
    final Event event = GivenEvent.projectCreated();
    eventBusWithPosponedExecution.post(event);
    final Set<EventEnvelope> postponedEvents = postponedDispatcherDelivery.getPostponedEvents();
    final EventEnvelope postponedEvent = postponedEvents.iterator().next();
    verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
    postponedDispatcherDelivery.deliverNow(postponedEvent, Consumers.idOf(dispatcher));
    assertTrue(dispatcher.isDispatchCalled());
    verify(delegateDispatcherExecutor).execute(any(Runnable.class));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 3 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class EventBusShould method store_multiple_messages_passing_filters.

/**
 * Ensures that events are stored when all of them pass the filters.
 *
 * <p> To filter the {@link EBTaskAdded} events the {@linkplain EventBus} has a custom filter.
 * The {@link TaskCreatedFilter} filters out {@link EBTaskAdded} events with
 * {@link Task#getDone()} set to {@code true}.
 *
 * <p> The {@link EBTaskAddedNoOpSubscriber} is registered so that the event would not get
 * filtered out by the {@link io.spine.server.bus.DeadMessageFilter}.
 */
@Test
public void store_multiple_messages_passing_filters() {
    eventBus.register(new EBTaskAddedNoOpSubscriber());
    final Command command = command(addTasks(newTask(false), newTask(false), newTask(false)));
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> storedEvents = readEvents(eventBus);
    assertSize(3, storedEvents);
}
Also used : Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 4 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class EventBusShould method pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_event.

@Test
public void pick_proper_consumer_by_consumer_id_when_delivering_to_delegates_of_same_event() {
    final FirstProjectCreatedDelegate first = new FirstProjectCreatedDelegate();
    final AnotherProjectCreatedDelegate second = new AnotherProjectCreatedDelegate();
    final DelegatingEventDispatcher<String> firstDispatcher = DelegatingEventDispatcher.of(first);
    final DelegatingEventDispatcher<String> secondDispatcher = DelegatingEventDispatcher.of(second);
    eventBusWithPosponedExecution.register(firstDispatcher);
    eventBusWithPosponedExecution.register(secondDispatcher);
    final Event event = GivenEvent.projectCreated();
    eventBusWithPosponedExecution.post(event);
    final Set<EventEnvelope> postponedEvents = postponedDispatcherDelivery.getPostponedEvents();
    final EventEnvelope postponedEvent = postponedEvents.iterator().next();
    verify(delegateDispatcherExecutor, never()).execute(any(Runnable.class));
    postponedDispatcherDelivery.deliverNow(postponedEvent, Consumers.idOf(firstDispatcher));
    assertTrue(first.isDispatchCalled());
    verify(delegateDispatcherExecutor).execute(any(Runnable.class));
    assertFalse(second.isDispatchCalled());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Example 5 with Event

use of io.spine.core.Event in project core-java by SpineEventEngine.

the class EventBusShould method store_only_events_passing_filters.

/**
 * Ensures that events which pass filters and the ones that don’t are treated independently when
 * sent in batch.
 *
 * <p> To filter the {@link EBTaskAdded} events the {@linkplain EventBus} has a custom filter.
 * The {@link TaskCreatedFilter} filters out {@link EBTaskAdded} events with
 * {@link Task#getDone()} set to {@code true}.
 *
 * <p> The {@link EBTaskAddedNoOpSubscriber} is registered so that the event would not get
 * filtered out by the {@link io.spine.server.bus.DeadMessageFilter}.
 */
@Test
public void store_only_events_passing_filters() {
    eventBus.register(new EBTaskAddedNoOpSubscriber());
    final Command command = command(addTasks(newTask(false), newTask(true), newTask(false), newTask(true), newTask(true)));
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> storedEvents = readEvents(eventBus);
    assertSize(2, storedEvents);
    for (Event event : storedEvents) {
        final EBTaskAdded contents = unpack(event.getMessage());
        final Task task = contents.getTask();
        assertFalse(task.getDone());
    }
}
Also used : EBTaskAdded(io.spine.test.event.EBTaskAdded) EventBusTestEnv.newTask(io.spine.server.event.given.EventBusTestEnv.newTask) Task(io.spine.test.event.Task) Command(io.spine.core.Command) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Test(org.junit.Test)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3