Search in sources :

Example 6 with Failure

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

the class FailureClass method of.

/**
     * Creates a new instance of the failure class by passed failure instance.
     *
     * <p>If an instance of {@link Failure} (which implements {@code Message}) is passed to this
     * method, enclosing failure message will be un-wrapped to determine the class of the failure.
     *
     * @param failure a failure instance
     * @return new instance
     */
public static FailureClass of(Message failure) {
    final Message message = checkNotNull(failure);
    if (message instanceof Failure) {
        final Failure failureRecord = (Failure) failure;
        final Message enclosed = Failures.getMessage(failureRecord);
        return of(enclosed.getClass());
    }
    final FailureClass result = of(message.getClass());
    return result;
}
Also used : Message(com.google.protobuf.Message) Failure(io.spine.base.Failure)

Example 7 with Failure

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

the class SingleTenantCommandBusShould method propagate_failures_to_failure_bus.

@Test
public void propagate_failures_to_failure_bus() {
    final FaultyHandler faultyHandler = new FaultyHandler(eventBus);
    commandBus.register(faultyHandler);
    final Command addTaskCommand = clearTenantId(addTask());
    commandBus.post(addTaskCommand, StreamObservers.<Response>noOpObserver());
    final InvalidProjectName failureThrowable = faultyHandler.getThrowable();
    final Failure expectedFailure = failureThrowable.toFailure(addTaskCommand);
    verify(failureBus).post(eq(expectedFailure), ArgumentMatchers.<StreamObserver<Response>>any());
}
Also used : Response(io.spine.base.Response) Command(io.spine.base.Command) InvalidProjectName(io.spine.test.failure.InvalidProjectName) Failure(io.spine.base.Failure) Test(org.junit.Test)

Example 8 with Failure

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

the class StorageShould method set_failure_command_status.

// We get right after we update status.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void set_failure_command_status() {
    givenNewRecord();
    final Failure failure = newFailure();
    storage.updateStatus(id, failure);
    final CommandRecord actual = read(id).get();
    assertEquals(FAILURE, actual.getStatus().getCode());
    assertEquals(failure, actual.getStatus().getFailure());
}
Also used : CommandRecord(io.spine.server.commandbus.CommandRecord) Failure(io.spine.base.Failure) TenantAwareTest(io.spine.server.tenant.TenantAwareTest) Test(org.junit.Test)

Aggregations

Failure (io.spine.base.Failure)8 Test (org.junit.Test)6 Message (com.google.protobuf.Message)1 Command (io.spine.base.Command)1 Response (io.spine.base.Response)1 FailureEnvelope (io.spine.envelope.FailureEnvelope)1 CommandRecord (io.spine.server.commandbus.CommandRecord)1 TenantAwareTest (io.spine.server.tenant.TenantAwareTest)1 InvalidProjectName (io.spine.test.failure.InvalidProjectName)1 Before (org.junit.Before)1