Search in sources :

Example 6 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class AggregateCommandEndpointShould method setUp.

@Before
public void setUp() {
    projectId = ProjectId.newBuilder().setId(Identifiers.newUuid()).build();
    final CommandStore commandStore = mock(CommandStore.class);
    final CommandBus.Builder commandBus = CommandBus.newBuilder().setMultitenant(true).setCommandStore(commandStore);
    final BoundedContext boundedContext = newBoundedContext(commandBus);
    subscriber = new Subscriber();
    boundedContext.getEventBus().register(subscriber);
    repository = new ProjectAggregateRepository(boundedContext);
    repositorySpy = spy(repository);
}
Also used : EventSubscriber(io.spine.server.event.EventSubscriber) CommandStore(io.spine.server.commandstore.CommandStore) MultiTenant.newBoundedContext(io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext) BoundedContext(io.spine.server.BoundedContext) CommandBus(io.spine.server.commandbus.CommandBus) Before(org.junit.Before)

Example 7 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class CommandService method post.

@SuppressWarnings("MethodDoesntCallSuperMethod")
// as we override default implementation with `unimplemented` status.
@Override
public void post(Command request, StreamObserver<Response> responseObserver) {
    final CommandClass commandClass = CommandClass.of(request);
    final BoundedContext boundedContext = boundedContextMap.get(commandClass);
    if (boundedContext == null) {
        handleUnsupported(request, responseObserver);
    } else {
        final CommandBus commandBus = boundedContext.getCommandBus();
        commandBus.post(request, responseObserver);
    }
}
Also used : CommandClass(io.spine.type.CommandClass) CommandBus(io.spine.server.commandbus.CommandBus)

Example 8 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class MultiTenantCommandBusShould method have_failure_bus_if_no_custom_set.

@Test
public void have_failure_bus_if_no_custom_set() {
    final CommandBus bus = CommandBus.newBuilder().setCommandStore(commandStore).build();
    assertNotNull(bus.failureBus());
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) Test(org.junit.Test)

Example 9 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class MultiTenantCommandBusShould method allow_to_specify_failure_bus_via_builder.

@Test
public void allow_to_specify_failure_bus_via_builder() {
    final FailureBus expectedFailureBus = mock(FailureBus.class);
    final CommandBus commandBus = CommandBus.newBuilder().setCommandStore(commandStore).setFailureBus(expectedFailureBus).build();
    assertNotNull(commandBus);
    final FailureBus actualFailureBus = commandBus.failureBus();
    assertEquals(expectedFailureBus, actualFailureBus);
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus) FailureBus(io.spine.server.failure.FailureBus) Test(org.junit.Test)

Example 10 with CommandBus

use of io.spine.server.commandbus.CommandBus in project core-java by SpineEventEngine.

the class ProcessManager method newRouterFor.

/**
     * Creates a new {@link CommandRouter}.
     *
     * <p>A {@code CommandRouter} allows to create and post one or more commands
     * in response to a command received by the {@code ProcessManager}.
     *
     * <p>A typical usage looks like this:
     *
     * <pre>
     *     {@literal @}Assign
     *     CommandRouted on(MyCommand message, CommandContext context) {
     *         // Create new command messages here.
     *         return newRouterFor(message, context)
     *                  .add(messageOne)
     *                  .add(messageTwo)
     *                  .routeAll();
     *     }
     * </pre>
     *
     * <p>The routed commands are created on behalf of the actor of the original command.
     * That is, the {@code actor} and {@code zoneOffset} fields of created {@code CommandContext}
     * instances will be the same as in the incoming command.
     *
     * @param commandMessage the source command message
     * @param commandContext the context of the source command
     * @return new {@code CommandRouter}
     */
protected CommandRouter newRouterFor(Message commandMessage, CommandContext commandContext) {
    checkNotNull(commandMessage);
    checkNotNull(commandContext);
    final CommandBus commandBus = ensureCommandBus();
    final CommandRouter router = new CommandRouter(commandBus, commandMessage, commandContext);
    return router;
}
Also used : CommandBus(io.spine.server.commandbus.CommandBus)

Aggregations

CommandBus (io.spine.server.commandbus.CommandBus)10 BoundedContext (io.spine.server.BoundedContext)2 Before (org.junit.Before)2 Test (org.junit.Test)2 StringValue (com.google.protobuf.StringValue)1 StreamObserver (io.grpc.stub.StreamObserver)1 Command (io.spine.base.Command)1 Response (io.spine.base.Response)1 CommandEnvelope (io.spine.envelope.CommandEnvelope)1 CommandDispatcher (io.spine.server.commandbus.CommandDispatcher)1 CommandStore (io.spine.server.commandstore.CommandStore)1 EventSubscriber (io.spine.server.event.EventSubscriber)1 FailureBus (io.spine.server.failure.FailureBus)1 CommandRouter (io.spine.server.procman.CommandRouter)1 MultiTenant.newBoundedContext (io.spine.testdata.TestBoundedContextFactory.MultiTenant.newBoundedContext)1 CommandClass (io.spine.type.CommandClass)1 Set (java.util.Set)1 CheckReturnValue (javax.annotation.CheckReturnValue)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1