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