Search in sources :

Example 71 with Message

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;
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 72 with Message

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();
}
Also used : ThrowableMessage(io.spine.base.ThrowableMessage) Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 73 with Message

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();
}
Also used : Message(com.google.protobuf.Message) Any(com.google.protobuf.Any)

Example 74 with Message

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));
}
Also used : LlapNodeId(org.apache.hadoop.hive.llap.LlapNodeId) Message(com.google.protobuf.Message) LlapProtocolClientProxy(org.apache.hadoop.hive.llap.tez.LlapProtocolClientProxy) Test(org.junit.Test)

Example 75 with Message

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();
}
Also used : Set(java.util.Set) Message(com.google.protobuf.Message) TypeConverter.toMessage(io.spine.protobuf.TypeConverter.toMessage) CommandContext(io.spine.core.CommandContext) CommandEnvelope(io.spine.core.CommandEnvelope) BoundedContext(io.spine.server.BoundedContext) CommandBus(io.spine.server.commandbus.CommandBus) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Aggregations

Message (com.google.protobuf.Message)185 Test (org.junit.Test)62 Any (com.google.protobuf.Any)30 Command (io.spine.core.Command)14 EntityRecord (io.spine.server.entity.EntityRecord)10 ByteString (com.google.protobuf.ByteString)9 Event (io.spine.core.Event)8 Event (io.spine.base.Event)7 CommandEnvelope (io.spine.core.CommandEnvelope)7 TypeUrl (io.spine.type.TypeUrl)7 IOException (java.io.IOException)7 Timestamp (com.google.protobuf.Timestamp)5 Error (io.spine.base.Error)5 Rejection (io.spine.core.Rejection)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 FieldMask (com.google.protobuf.FieldMask)4 GeneratedMessage (com.google.protobuf.GeneratedMessage)4 ThrowableMessage (io.spine.base.ThrowableMessage)4 EntityFilters (io.spine.client.EntityFilters)4