use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class MessageMismatch method unpackExpected.
/**
* Obtains expected value as a {@code Message} from the passed mismatch.
*
* @throws RuntimeException if the passed instance represent a mismatch of
* non-{@code Message} values
*/
public static Message unpackExpected(ValueMismatch mismatch) {
checkNotNull(mismatch);
final Any any = mismatch.getExpected();
final Message result = unpack(any);
return result;
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class Rejections method toRejection.
/**
* Converts this {@code ThrowableMessage} into {@link Rejection}.
*
* @param command the command which caused the rejection
*/
public static Rejection toRejection(ThrowableMessage throwable, Command command) {
checkNotNull(throwable);
checkNotNull(command);
final Message rejectionMessage = throwable.getMessageThrown();
final Any packedState = pack(rejectionMessage);
final RejectionContext context = createContext(throwable, command);
final RejectionId id = generateId(command.getId());
final Rejection.Builder builder = Rejection.newBuilder().setId(id).setMessage(packedState).setContext(context);
return builder.build();
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class Targets method composeTarget.
static Target composeTarget(Class<? extends Message> entityClass, @Nullable Set<? extends Message> ids, @Nullable Set<CompositeColumnFilter> columnFilters) {
final boolean includeAll = (ids == null && columnFilters == null);
final Set<? extends Message> entityIds = nullToEmpty(ids);
final Set<CompositeColumnFilter> entityColumnValues = nullToEmpty(columnFilters);
final EntityIdFilter.Builder idFilterBuilder = EntityIdFilter.newBuilder();
if (!includeAll) {
for (Message rawId : entityIds) {
final Any packedId = AnyPacker.pack(rawId);
final EntityId entityId = EntityId.newBuilder().setId(packedId).build();
idFilterBuilder.addIds(entityId);
}
}
final EntityIdFilter idFilter = idFilterBuilder.build();
final EntityFilters filters = EntityFilters.newBuilder().setIdFilter(idFilter).addAllFilter(entityColumnValues).build();
final String typeUrl = TypeUrl.of(entityClass).value();
final Target.Builder builder = Target.newBuilder().setType(typeUrl);
if (includeAll) {
builder.setIncludeAll(true);
} else {
builder.setFilters(filters);
}
return builder.build();
}
use of com.google.protobuf.Message in project hive by apache.
the class TestAsyncPbRpcProxy method testSingleInvocationPerNode.
@Test(timeout = 5000)
public void testSingleInvocationPerNode() throws Exception {
RequestManagerForTest requestManager = new RequestManagerForTest(1);
LlapNodeId nodeId1 = LlapNodeId.getInstance("host1", 1025);
Message mockMessage = mock(Message.class);
LlapProtocolClientProxy.ExecuteRequestCallback mockExecuteRequestCallback = mock(LlapProtocolClientProxy.ExecuteRequestCallback.class);
// First request for host.
requestManager.queueRequest(new CallableRequestForTest(nodeId1, mockMessage, mockExecuteRequestCallback));
requestManager.process();
assertEquals(1, requestManager.numSubmissionsCounters);
assertNotNull(requestManager.numInvocationsPerNode.get(nodeId1));
Assert.assertEquals(1, requestManager.numInvocationsPerNode.get(nodeId1).getValue().intValue());
assertEquals(0, requestManager.currentLoopSkippedRequests.size());
// Second request for host. Single invocation since the last has not completed.
requestManager.queueRequest(new CallableRequestForTest(nodeId1, mockMessage, mockExecuteRequestCallback));
requestManager.process();
assertEquals(1, requestManager.numSubmissionsCounters);
assertNotNull(requestManager.numInvocationsPerNode.get(nodeId1));
Assert.assertEquals(1, requestManager.numInvocationsPerNode.get(nodeId1).getValue().intValue());
assertEquals(1, requestManager.currentLoopSkippedRequests.size());
assertEquals(1, requestManager.currentLoopDisabledNodes.size());
assertTrue(requestManager.currentLoopDisabledNodes.contains(nodeId1));
// Complete first request. Second pending request should go through.
requestManager.requestFinished(nodeId1);
requestManager.process();
assertEquals(2, requestManager.numSubmissionsCounters);
assertNotNull(requestManager.numInvocationsPerNode.get(nodeId1));
Assert.assertEquals(2, requestManager.numInvocationsPerNode.get(nodeId1).getValue().intValue());
assertEquals(0, requestManager.currentLoopSkippedRequests.size());
assertEquals(0, requestManager.currentLoopDisabledNodes.size());
assertFalse(requestManager.currentLoopDisabledNodes.contains(nodeId1));
}
use of com.google.protobuf.Message in project core-java by SpineEventEngine.
the class CommandRouterOnErrorShould method throw_IllegalStateException_when_caught_error_when_posting.
@Test(expected = IllegalStateException.class)
public void throw_IllegalStateException_when_caught_error_when_posting() {
final BoundedContext boundedContext = BoundedContext.newBuilder().build();
final CommandBus commandBus = boundedContext.getCommandBus();
// Register dispatcher for `StringValue` message type.
// Fails each time of dispatch().
commandBus.register(new CommandDispatcher<Message>() {
@Override
public Set<CommandClass> getMessageClasses() {
return CommandClass.setOf(StringValue.class);
}
@Override
public Message dispatch(CommandEnvelope envelope) {
throw new IllegalStateException("I am faulty!");
}
@Override
public void onError(CommandEnvelope envelope, RuntimeException exception) {
// Do nothing.
}
});
final StringValue sourceMessage = toMessage(getClass().getSimpleName());
final CommandContext sourceContext = getRequestFactory().createCommandContext();
final CommandRouter router = createRouter(commandBus, sourceMessage, sourceContext);
router.addAll(getMessages());
router.routeAll();
}
Aggregations