Search in sources :

Example 11 with EventEnvelope

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

the class ProjectionRepositoryShould method log_error_if_dispatch_unknown_event.

@Test
public void log_error_if_dispatch_unknown_event() {
    final StringValue unknownEventMessage = StringValue.getDefaultInstance();
    final Event event = GivenEvent.withMessage(unknownEventMessage);
    repository().dispatch(EventEnvelope.of(event));
    TestProjectionRepository testRepo = (TestProjectionRepository) repository();
    assertTrue(testRepo.getLastErrorEnvelope() instanceof EventEnvelope);
    assertEquals(Events.getMessage(event), testRepo.getLastErrorEnvelope().getMessage());
    assertEquals(event, testRepo.getLastErrorEnvelope().getOuterObject());
    // It must be "illegal argument type" since projections of this repository
    // do not handle such events.
    assertTrue(testRepo.getLastException() instanceof IllegalArgumentException);
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) GivenEvent(io.spine.core.given.GivenEvent) Event(io.spine.core.Event) StringValue(com.google.protobuf.StringValue) TestProjectionRepository(io.spine.server.projection.given.ProjectionRepositoryTestEnv.TestProjectionRepository) Test(org.junit.Test)

Example 12 with EventEnvelope

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

the class TransactionShould method advance_version_from_event.

@Test
public void advance_version_from_event() {
    final E entity = createEntity();
    final Transaction<I, E, S, B> tx = createTx(entity);
    assertEquals(entity.getVersion(), tx.getVersion());
    final Event event = createEvent(createEventMessage());
    final EventEnvelope envelope = EventEnvelope.of(event);
    tx.apply(envelope);
    assertEquals(event.getContext().getVersion(), tx.getVersion());
    tx.commit();
    assertEquals(event.getContext().getVersion(), entity.getVersion());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Event(io.spine.core.Event) Test(org.junit.Test)

Example 13 with EventEnvelope

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

the class DelegatingEventDispatcherShould method delegate_onError.

@Test
public void delegate_onError() {
    final TestEventFactory factory = TestEventFactory.newInstance(getClass());
    final EventEnvelope envelope = EventEnvelope.of(factory.createEvent(newUuidValue()));
    final RuntimeException exception = new RuntimeException("test delegating onError");
    delegatingDispatcher.onError(envelope, exception);
    assertTrue(delegate.onErrorCalled());
    assertEquals(exception, delegate.getLastException());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) TestEventFactory(io.spine.server.command.TestEventFactory) Test(org.junit.Test)

Example 14 with EventEnvelope

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

the class AggregateRepositoryShould method log_error_when_event_reaction_fails.

@Test
public void log_error_when_event_reaction_fails() {
    final FailingAggregateRepository repository = new FailingAggregateRepository();
    boundedContext.register(repository);
    final TestEventFactory factory = TestEventFactory.newInstance(getClass());
    // Passing negative float value should cause an exception.
    final EventEnvelope envelope = EventEnvelope.of(factory.createEvent(FloatValue.newBuilder().setValue(-412.0f).build()));
    boundedContext.getEventBus().post(envelope.getOuterObject());
    assertTrue(repository.isErrorLogged());
    final RuntimeException lastException = repository.getLastException();
    assertTrue(lastException instanceof HandlerMethodFailedException);
    final HandlerMethodFailedException methodFailedException = (HandlerMethodFailedException) lastException;
    assertEquals(envelope.getMessage(), methodFailedException.getDispatchedMessage());
    assertEquals(envelope.getEventContext(), methodFailedException.getMessageContext());
    final MessageEnvelope lastErrorEnvelope = repository.getLastErrorEnvelope();
    assertNotNull(lastErrorEnvelope);
    assertTrue(lastErrorEnvelope instanceof EventEnvelope);
    assertEquals(envelope.getMessage(), lastErrorEnvelope.getMessage());
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) FailingAggregateRepository(io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository) TestEventFactory(io.spine.server.command.TestEventFactory) HandlerMethodFailedException(io.spine.server.model.HandlerMethodFailedException) MessageEnvelope(io.spine.core.MessageEnvelope) Test(org.junit.Test)

Example 15 with EventEnvelope

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

the class ProjectionEndpoint method getTargets.

@Override
protected Set<I> getTargets() {
    final EventEnvelope event = envelope();
    final Set<I> ids = repository().eventRouting().apply(event.getMessage(), event.getEventContext());
    return ids;
}
Also used : EventEnvelope(io.spine.core.EventEnvelope)

Aggregations

EventEnvelope (io.spine.core.EventEnvelope)24 Test (org.junit.Test)19 Event (io.spine.core.Event)9 StringValue (com.google.protobuf.StringValue)3 TestEventFactory (io.spine.server.command.TestEventFactory)3 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)2 FailingSubscriber (io.spine.server.event.given.EventSubscriberTestEnv.FailingSubscriber)2 FloatValue (com.google.protobuf.FloatValue)1 Message (com.google.protobuf.Message)1 Command (io.spine.core.Command)1 EventClass (io.spine.core.EventClass)1 MessageEnvelope (io.spine.core.MessageEnvelope)1 GivenEvent (io.spine.core.given.GivenEvent)1 PostponingEventDelivery (io.spine.server.aggregate.given.AggregateMessageDeliveryTestEnv.PostponingEventDelivery)1 FailingAggregateRepository (io.spine.server.aggregate.given.AggregateRepositoryTestEnv.FailingAggregateRepository)1 EventCatcher (io.spine.server.event.given.CommandHandlerTestEnv.EventCatcher)1 GivenEvent (io.spine.server.event.given.EventEnricherTestEnv.GivenEvent)1 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)1 ExternalMessageDispatcher (io.spine.server.integration.ExternalMessageDispatcher)1 ExternalMessageEnvelope (io.spine.server.integration.ExternalMessageEnvelope)1