Search in sources :

Example 1 with InMemoryTransportFactory

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());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) BoundedContextName(io.spine.core.BoundedContextName) Test(org.junit.Test)

Example 2 with InMemoryTransportFactory

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());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) Test(org.junit.Test)

Example 3 with InMemoryTransportFactory

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());
}
Also used : Rejection(io.spine.core.Rejection) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) BoundedContext(io.spine.server.BoundedContext) RejectionBus(io.spine.server.rejection.RejectionBus) ProjectRejectionsExtSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectRejectionsExtSubscriber) Test(org.junit.Test)

Example 4 with InMemoryTransportFactory

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());
}
Also used : ProjectStartedExtSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber) InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) EventBus(io.spine.server.event.EventBus) ProjectEventsSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber) Test(org.junit.Test)

Example 5 with InMemoryTransportFactory

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());
}
Also used : InMemoryTransportFactory(io.spine.server.integration.memory.InMemoryTransportFactory) Event(io.spine.core.Event) BoundedContext(io.spine.server.BoundedContext) EventBus(io.spine.server.event.EventBus) ProjectEventsSubscriber(io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber) Test(org.junit.Test)

Aggregations

BoundedContext (io.spine.server.BoundedContext)12 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)12 Test (org.junit.Test)12 Event (io.spine.core.Event)9 Rejection (io.spine.core.Rejection)3 EventBus (io.spine.server.event.EventBus)3 Message (com.google.protobuf.Message)2 BoundedContextName (io.spine.core.BoundedContextName)2 ProjectEventsSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectEventsSubscriber)2 Error (io.spine.base.Error)1 Ack (io.spine.core.Ack)1 ExternalMismatchSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ExternalMismatchSubscriber)1 ProjectRejectionsExtSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectRejectionsExtSubscriber)1 ProjectStartedExtSubscriber (io.spine.server.integration.given.IntegrationBusTestEnv.ProjectStartedExtSubscriber)1 RejectionBus (io.spine.server.rejection.RejectionBus)1 RejectionSubscriber (io.spine.server.rejection.RejectionSubscriber)1