Search in sources :

Example 66 with Event

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

the class ExternalEventSubscriber method dispatch.

@Override
public Set<String> dispatch(ExternalMessageEnvelope envelope) {
    final ExternalMessage externalMessage = envelope.getOuterObject();
    final Message unpacked = AnyPacker.unpack(externalMessage.getOriginalMessage());
    if (!(unpacked instanceof Event)) {
        throw newIllegalStateException("Unexpected object %s while dispatching " + "the external event to the event subscriber.", Stringifiers.toString(unpacked));
    }
    final Event event = (Event) unpacked;
    checkArgument(isExternal(event.getContext()), "External event expected, but got %s", Stringifiers.toString(event));
    return delegate.dispatch(EventEnvelope.of(event));
}
Also used : Message(com.google.protobuf.Message) Event(io.spine.core.Event)

Example 67 with Event

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

the class EventPlayingEntityShould method delegate_applying_events_to_tx_when_playing.

@Test
public void delegate_applying_events_to_tx_when_playing() {
    final EventPlayingEntity entity = entityWithActiveTx(false);
    final Transaction txMock = entity.getTransaction();
    assertNotNull(txMock);
    final Event firstEvent = eventFactory.createEvent(newUuidValue());
    final Event secondEvent = eventFactory.createEvent(newUuidValue());
    entity.play(newArrayList(firstEvent, secondEvent));
    verifyEventApplied(txMock, firstEvent);
    verifyEventApplied(txMock, secondEvent);
}
Also used : Event(io.spine.core.Event) Test(org.junit.Test)

Example 68 with Event

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

the class TransactionShould method propagate_phase_failure_exception_as_ISE.

@Test(expected = IllegalStateException.class)
public void propagate_phase_failure_exception_as_ISE() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessageThatFailsInHandler());
    applyEvent(tx, event);
}
Also used : Event(io.spine.core.Event) Test(org.junit.Test)

Example 69 with Event

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

the class TransactionShould method rollback_automatically_if_phase_failed.

@Test
public void rollback_automatically_if_phase_failed() {
    final E entity = createEntity();
    final S originalState = entity.getState();
    final Version originalVersion = entity.getVersion();
    final Transaction<I, E, S, B> tx = createTx(entity);
    final Event event = createEvent(createEventMessageThatFailsInHandler());
    try {
        applyEvent(tx, event);
        fail("Expected an `Exception` due to a failed phase execution.");
    } catch (final Exception e) {
        checkRollback(entity, originalState, originalVersion);
    }
}
Also used : Versions.newVersion(io.spine.core.Versions.newVersion) Version(io.spine.core.Version) Event(io.spine.core.Event) ValidationException(io.spine.validate.ValidationException) Test(org.junit.Test)

Example 70 with Event

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

the class DelegatingEventDispatcherShould method expose_external_dispatcher_that_delegates_onError.

@Test
public void expose_external_dispatcher_that_delegates_onError() {
    final ExternalMessageDispatcher<String> extMessageDispatcher = delegatingDispatcher.getExternalDispatcher();
    final TestEventFactory factory = TestEventFactory.newInstance(getClass());
    final StringValue eventMsg = newUuidValue();
    final Event event = factory.createEvent(eventMsg);
    final ExternalMessage externalMessage = ExternalMessages.of(event, BoundedContext.newName(getClass().getName()));
    final ExternalMessageEnvelope externalMessageEnvelope = ExternalMessageEnvelope.of(externalMessage, eventMsg);
    final RuntimeException exception = new RuntimeException("test external dispatcher delegating onError");
    extMessageDispatcher.onError(externalMessageEnvelope, exception);
    assertTrue(delegate.onErrorCalled());
}
Also used : TestEventFactory(io.spine.server.command.TestEventFactory) Event(io.spine.core.Event) ExternalMessageEnvelope(io.spine.server.integration.ExternalMessageEnvelope) ExternalMessage(io.spine.server.integration.ExternalMessage) StringValue(com.google.protobuf.StringValue) 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