use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.
the class IntegrationBusShould method dispatch_events_from_one_BC_to_entities_with_ext_subscribers_of_multiple_BCs.
@Test
public void dispatch_events_from_one_BC_to_entities_with_ext_subscribers_of_multiple_BCs() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final Set<BoundedContextName> destinationNames = newHashSet();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
for (int i = 0; i < 42; i++) {
final BoundedContext destinationCtx = contextWithContextAwareEntitySubscriber(transportFactory);
final BoundedContextName name = destinationCtx.getName();
destinationNames.add(name);
}
assertTrue(ContextAwareProjectDetails.getExternalContexts().isEmpty());
final Event event = projectCreated();
sourceContext.getEventBus().post(event);
assertEquals(destinationNames.size(), ContextAwareProjectDetails.getExternalContexts().size());
assertEquals(destinationNames.size(), ContextAwareProjectDetails.getExternalEvents().size());
}
use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.
the class IntegrationBusShould method avoid_dispatching_events_from_one_BC_to_domestic_standalone_subscribers_of_another_BC.
@Test
public void avoid_dispatching_events_from_one_BC_to_domestic_standalone_subscribers_of_another_BC() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
final BoundedContext destContext = contextWithExternalSubscribers(transportFactory);
assertNull(ProjectEventsSubscriber.getDomesticEvent());
final Event event = projectStarted();
sourceContext.getEventBus().post(event);
assertNotEquals(AnyPacker.unpack(event.getMessage()), ProjectEventsSubscriber.getDomesticEvent());
assertNull(ProjectEventsSubscriber.getDomesticEvent());
destContext.getEventBus().post(event);
assertEquals(AnyPacker.unpack(event.getMessage()), ProjectEventsSubscriber.getDomesticEvent());
}
use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.
the class IntegrationBusShould method not_dispatch_rejections_to_domestic_subscribers_if_they_requested_external.
@Test
public void not_dispatch_rejections_to_domestic_subscribers_if_they_requested_external() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithExtEntitySubscribers(transportFactory);
final ProjectRejectionsExtSubscriber standaloneSubscriber = new ProjectRejectionsExtSubscriber();
final RejectionBus rejectionBus = sourceContext.getRejectionBus();
rejectionBus.register(standaloneSubscriber);
assertNull(ProjectRejectionsExtSubscriber.getExternalRejection());
assertNull(ProjectWizard.getExternalRejection());
assertNull(ProjectCountAggregate.getExternalRejection());
final Rejection rejection = cannotStartArchivedProject();
rejectionBus.post(rejection);
assertNull(ProjectRejectionsExtSubscriber.getExternalRejection());
assertNull(ProjectWizard.getExternalRejection());
assertNull(ProjectCountAggregate.getExternalRejection());
}
use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.
the class IntegrationBusShould method update_local_subscriptions_upon_repeated_RequestedMessageTypes.
@Test
public void update_local_subscriptions_upon_repeated_RequestedMessageTypes() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext sourceContext = contextWithTransport(transportFactory);
final BoundedContext destinationCtx = contextWithTransport(transportFactory);
// Prepare two external subscribers for the different events in the the `destinationCtx`.
final ProjectEventsSubscriber projectCreatedSubscriber = new ProjectEventsSubscriber();
final ProjectStartedExtSubscriber projectStartedSubscriber = new ProjectStartedExtSubscriber();
// Before anything happens, there were no events received by those.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Both events are prepared along with the `EventBus` of the source bounded context.
final EventBus sourceEventBus = sourceContext.getEventBus();
final Event eventA = projectCreated();
final Event eventB = projectStarted();
// Both events are emitted, `ProjectCreated` subscriber only is present.
destinationCtx.getIntegrationBus().register(projectCreatedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// Only `ProjectCreated` should have been dispatched.
assertEquals(AnyPacker.unpack(eventA.getMessage()), ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Clear before the next round starts.
ProjectStartedExtSubscriber.clear();
ProjectEventsSubscriber.clear();
// Both events are emitted, No external subscribers at all.
destinationCtx.getIntegrationBus().unregister(projectCreatedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// No events should have been dispatched.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectStartedExtSubscriber.getExternalEvent());
// Both events are emitted, `ProjectStarted` subscriber only is present
destinationCtx.getIntegrationBus().register(projectStartedSubscriber);
sourceEventBus.post(eventA);
sourceEventBus.post(eventB);
// This time `ProjectStarted` event should only have been dispatched.
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertEquals(AnyPacker.unpack(eventB.getMessage()), ProjectStartedExtSubscriber.getExternalEvent());
}
use of io.spine.server.integration.memory.InMemoryTransportFactory in project core-java by SpineEventEngine.
the class IntegrationBusShould method not_dispatch_events_to_domestic_subscribers_if_they_requested_external.
@Test
public void not_dispatch_events_to_domestic_subscribers_if_they_requested_external() {
final InMemoryTransportFactory transportFactory = InMemoryTransportFactory.newInstance();
final BoundedContext context = contextWithExtEntitySubscribers(transportFactory);
final ProjectEventsSubscriber eventSubscriber = new ProjectEventsSubscriber();
final EventBus eventBus = context.getEventBus();
eventBus.register(eventSubscriber);
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectDetails.getExternalEvent());
assertNull(ProjectWizard.getExternalEvent());
assertNull(ProjectCountAggregate.getExternalEvent());
final Event projectCreated = projectCreated();
eventBus.post(projectCreated);
assertNull(ProjectEventsSubscriber.getExternalEvent());
assertNull(ProjectDetails.getExternalEvent());
assertNull(ProjectWizard.getExternalEvent());
assertNull(ProjectCountAggregate.getExternalEvent());
}
Aggregations