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;
}
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;
}
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();
}
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());
}
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));
}
Aggregations