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);
}
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();
}
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);
}
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));
}
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;
}
Aggregations