Search in sources :

Example 31 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class PackingIterator method next.

/**
     * Takes the message from the source iterator, wraps it into {@code Any}
     * and returns.
     *
     * <p>If the source iterator returns {@code null} message, the default instance
     * of {@code Any} will be returned.
     *
     * @return the packed message or default {@code Any}
     */
@Override
public Any next() {
    final Message next = source.next();
    final Any result = next != null ? AnyPacker.pack(next) : Any.getDefaultInstance();
    return result;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 32 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class TypeConverter method toAny.

/**
     * Performs the {@link Object} to {@link Any} mapping.
     *
     * @param value the {@link Object} value to convert
     * @param <T>   the converted object type
     * @return the packed value
     */
public static <T> Any toAny(T value) {
    checkNotNull(value);
    // Must be checked at runtime
    @SuppressWarnings("unchecked") final Class<T> srcClass = (Class<T>) value.getClass();
    final AnyCaster<T> caster = AnyCaster.forType(srcClass);
    final Message message = caster.reverse().convert(value);
    checkNotNull(message);
    final Any result = AnyPacker.pack(message);
    return result;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 33 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class Validator method validate.

/**
     * Validates a command checking that its required fields are valid and
     * validates a command message according to Spine custom protobuf options.
     *
     * @param envelope a command to validate
     * @return constraint violations found
     */
List<ConstraintViolation> validate(CommandEnvelope envelope) {
    final ImmutableList.Builder<ConstraintViolation> result = ImmutableList.builder();
    final Message message = envelope.getMessage();
    final CommandContext context = envelope.getCommandContext();
    final CommandId id = envelope.getCommandId();
    validateCommandId(id, result);
    validateMessage(message, result);
    validateContext(context, result);
    validateTargetId(message, result);
    return result.build();
}
Also used : Message(com.google.protobuf.Message) CommandContext(io.spine.base.CommandContext) ImmutableList(com.google.common.collect.ImmutableList) ConstraintViolation(io.spine.validate.ConstraintViolation) CommandId(io.spine.base.CommandId)

Example 34 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class CommandStoreShould method set_command_status_to_failure_when_handler_throws_failure.

@Test
public void set_command_status_to_failure_when_handler_throws_failure() {
    final TestFailure failure = new TestFailure();
    final Command command = givenThrowingHandler(failure);
    final CommandId commandId = command.getId();
    final Message commandMessage = getMessage(command);
    commandBus.post(command, responseObserver);
    // Check that the logging was called.
    verify(log).failureHandling(eq(failure), eq(commandMessage), eq(commandId));
    // Check that the status has the correct code,
    // and the failure matches the thrown failure.
    final TenantId tenantId = command.getContext().getActorContext().getTenantId();
    final ProcessingStatus status = getStatus(commandId, tenantId);
    assertEquals(CommandStatus.FAILURE, status.getCode());
    assertEquals(failure.toFailure(command).getMessage(), status.getFailure().getMessage());
}
Also used : TenantId(io.spine.users.TenantId) Commands.getMessage(io.spine.base.Commands.getMessage) CommandMessage.createProjectMessage(io.spine.server.commandbus.Given.CommandMessage.createProjectMessage) Message(com.google.protobuf.Message) Command(io.spine.base.Command) CommandId(io.spine.base.CommandId) Test(org.junit.Test)

Example 35 with Message

use of com.google.protobuf.Message in project core-java by SpineEventEngine.

the class ProjectionRepositoryShould method perform_bulk_catch_up_if_required.

// Due to mockito matcher usage
@SuppressWarnings("unchecked")
@Test
public void perform_bulk_catch_up_if_required() {
    final ProjectId projectId = ProjectId.newBuilder().setId("mock-project-id").build();
    final Message eventMessage = ProjectCreated.newBuilder().setProjectId(projectId).build();
    final Event event = createEvent(pack(projectId), eventMessage);
    appendEvent(boundedContext.getEventBus().getEventStore(), event);
    // Set up repository
    final Duration duration = Durations2.seconds(10L);
    final ProjectionRepository repository = spy(new ManualCatchupProjectionRepository(boundedContext, duration));
    repository.initStorage(storageFactory());
    repository.catchUp();
    // Check bulk write
    verify(repository).store(any(Collection.class));
    verify(repository, never()).store(any(TestProjection.class));
}
Also used : Message(com.google.protobuf.Message) ProjectId(io.spine.test.projection.ProjectId) Event(io.spine.base.Event) ImmutableCollection(com.google.common.collect.ImmutableCollection) Collection(java.util.Collection) Duration(com.google.protobuf.Duration) Test(org.junit.Test)

Aggregations

Message (com.google.protobuf.Message)266 Test (org.junit.Test)84 Any (com.google.protobuf.Any)30 ByteString (com.google.protobuf.ByteString)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Command (io.spine.core.Command)14 DynamicMessage (com.google.protobuf.DynamicMessage)13 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)10 EntityRecord (io.spine.server.entity.EntityRecord)10 Test (org.junit.jupiter.api.Test)9 HeronTuples (com.twitter.heron.proto.system.HeronTuples)8 Event (io.spine.core.Event)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Method (java.lang.reflect.Method)8 Event (io.spine.base.Event)7 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)7 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)7 Descriptor (com.google.protobuf.Descriptors.Descriptor)6 Builder (com.google.protobuf.Message.Builder)5