Search in sources :

Example 6 with Event

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

the class EventBusShould method not_store_an_invalid_event.

@Test
public void not_store_an_invalid_event() {
    final Command command = command(invalidArchiveProject());
    eventBus.register(new EBProjectArchivedSubscriber());
    commandBus.post(command, StreamObservers.<Ack>noOpObserver());
    final List<Event> events = readEvents(eventBus);
    assertSize(0, 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 7 with Event

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

the class EventBusShould method store_filters_regarding_possible_concurrent_modifications.

/**
 * Tests the concurrent access to the {@linkplain io.spine.server.bus.BusFilter bus filters}.
 *
 * <p>The {@linkplain io.spine.server.bus.FilterChain filter chain} is a queue of the filters
 * which are sequentially applied to the posted message. The first {@code Bus.post()} call
 * invokes the filters lazy initialization. In the concurrent environment (which is natural for
 * a {@link io.spine.server.bus.Bus Bus}), the initialization may be performed multiple times.
 * Thus, some unexpected issues may appear when accessing the non-synchronously initialized
 * filter chain.
 *
 * <p>To make sure that the chain works fine (i.e. produces no exceptions), we invoke the
 * initialization multiple times from several threads.
 */
// OK for such test case.
@SuppressWarnings("MethodWithMultipleLoops")
// This test is used only to diagnose EventBus malfunctions in concurrent environment.
@Ignore
// Please see build log to find out if there were some errors during the test execution.
@Test
public void store_filters_regarding_possible_concurrent_modifications() throws InterruptedException {
    final int threadCount = 50;
    // "Random" more or less valid Event.
    final Event event = Event.newBuilder().setId(EventId.newBuilder().setValue("123-1")).setMessage(pack(Int32Value.newBuilder().setValue(42).build())).build();
    final StorageFactory storageFactory = StorageFactorySwitch.newInstance(newName("baz"), false).get();
    final ExecutorService executor = Executors.newFixedThreadPool(threadCount);
    // Catch non-easily reproducible bugs.
    for (int i = 0; i < 300; i++) {
        final EventBus eventBus = EventBus.newBuilder().setStorageFactory(storageFactory).build();
        for (int j = 0; j < threadCount; j++) {
            executor.execute(new Runnable() {

                @Override
                public void run() {
                    eventBus.post(event);
                }
            });
        }
        // Let the system destroy all the native threads, clean up, etc.
        Thread.sleep(100);
    }
    executor.shutdownNow();
}
Also used : StorageFactory(io.spine.server.storage.StorageFactory) ExecutorService(java.util.concurrent.ExecutorService) GivenEvent(io.spine.server.event.given.EventBusTestEnv.GivenEvent) Event(io.spine.core.Event) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Event

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

the class EventBusShould method store_a_dead_event.

@Test
public void store_a_dead_event() {
    final Command command = command(createProject());
    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 9 with Event

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

the class EventEnricherShould method confirm_that_event_can_not_be_enriched_if_enrichment_disabled.

@Test
public void confirm_that_event_can_not_be_enriched_if_enrichment_disabled() {
    final Event event = createEvent(toMessage(newUuid()));
    final EventEnvelope notEnrichableEvent = EventEnvelope.of(event.toBuilder().setContext(event.getContext().toBuilder().setEnrichment(event.getContext().getEnrichment().toBuilder().setDoNotEnrich(true))).build());
    assertFalse(enricher.canBeEnriched(notEnrichableEvent));
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Event(io.spine.core.Event) GivenEvent(io.spine.server.event.given.EventEnricherTestEnv.GivenEvent) Test(org.junit.Test)

Example 10 with Event

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

the class EventEnricherShould method createEvent.

private static Event createEvent(Message msg) {
    final TestEventFactory eventFactory = newInstance(EventEnricherShould.class);
    final Event event = eventFactory.createEvent(msg);
    return event;
}
Also used : TestEventFactory(io.spine.server.command.TestEventFactory) Event(io.spine.core.Event) GivenEvent(io.spine.server.event.given.EventEnricherTestEnv.GivenEvent)

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