Search in sources :

Example 91 with Message

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

the class EntityQueryMatcherShould method match_ids.

@Test
public void match_ids() {
    final Message genericId = Sample.messageOfType(ProjectId.class);
    final Collection<Object> idFilter = Collections.<Object>singleton(genericId);
    final Any entityId = AnyPacker.pack(genericId);
    final EntityQuery<?> query = createQuery(idFilter, defaultQueryParameters());
    final EntityQueryMatcher<?> matcher = new EntityQueryMatcher<>(query);
    final EntityRecord matching = EntityRecord.newBuilder().setEntityId(entityId).build();
    final Any otherEntityId = AnyPacker.pack(Sample.messageOfType(ProjectId.class));
    final EntityRecord nonMatching = EntityRecord.newBuilder().setEntityId(otherEntityId).build();
    final EntityRecordWithColumns matchingRecord = of(matching);
    final EntityRecordWithColumns nonMatchingRecord = of(nonMatching);
    assertTrue(matcher.apply(matchingRecord));
    assertFalse(matcher.apply(nonMatchingRecord));
}
Also used : EntityRecord(io.spine.server.entity.EntityRecord) Message(com.google.protobuf.Message) ProjectId(io.spine.test.entity.ProjectId) Any(com.google.protobuf.Any) EntityRecordWithColumns(io.spine.server.entity.storage.EntityRecordWithColumns) Test(org.junit.Test)

Example 92 with Message

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

the class PairShould method return_Empty_for_absent_Optional_in_iterator.

@Test
public void return_Empty_for_absent_Optional_in_iterator() {
    StringValue a = TestValues.newUuidValue();
    Pair<StringValue, Optional<BoolValue>> pair = Pair.withNullable(a, null);
    final Iterator<Message> iterator = pair.iterator();
    assertEquals(a, iterator.next());
    assertEquals(Empty.getDefaultInstance(), iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : Optional(com.google.common.base.Optional) Message(com.google.protobuf.Message) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Example 93 with Message

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

the class CommandTestShould method create_different_command_with_timestamp.

@Test
public void create_different_command_with_timestamp() {
    final Message anotherCommandMsg = Time.getCurrentTime();
    final Timestamp timestamp = TimeTests.Past.minutesAgo(30);
    final Command anotherCommand = commandTest.createDifferentCommand(anotherCommandMsg, timestamp);
    assertEquals(anotherCommandMsg, Commands.getMessage(anotherCommand));
    assertEquals(timestamp, anotherCommand.getContext().getActorContext().getTimestamp());
}
Also used : Message(com.google.protobuf.Message) Command(io.spine.core.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 94 with Message

use of com.google.protobuf.Message in project hbase by apache.

the class HBaseAdmin method coprocessorService.

@Override
public // Coprocessor Endpoint against the Master.
CoprocessorRpcChannel coprocessorService() {
    return new SyncCoprocessorRpcChannel() {

        @Override
        protected Message callExecService(final RpcController controller, final Descriptors.MethodDescriptor method, final Message request, final Message responsePrototype) throws IOException {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Call: " + method.getName() + ", " + request.toString());
            }
            // Try-with-resources so close gets called when we are done.
            try (MasterCallable<CoprocessorServiceResponse> callable = new MasterCallable<CoprocessorServiceResponse>(connection, connection.getRpcControllerFactory()) {

                @Override
                protected CoprocessorServiceResponse rpcCall() throws Exception {
                    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
                    return this.master.execMasterService(getRpcController(), csr);
                }
            }) {
                // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller
                callable.prepare(false);
                int operationTimeout = connection.getConnectionConfiguration().getOperationTimeout();
                CoprocessorServiceResponse result = callable.call(operationTimeout);
                return CoprocessorRpcUtils.getResponse(result, responsePrototype);
            }
        }
    };
}
Also used : RpcController(com.google.protobuf.RpcController) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) Message(com.google.protobuf.Message) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse)

Example 95 with Message

use of com.google.protobuf.Message in project hbase by apache.

the class CoprocessorRpcUtils method getResponse.

public static Message getResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse result, com.google.protobuf.Message responsePrototype) throws IOException {
    Message response;
    if (result.getValue().hasValue()) {
        Message.Builder builder = responsePrototype.newBuilderForType();
        builder.mergeFrom(result.getValue().getValue().newInput());
        response = builder.build();
    } else {
        response = responsePrototype.getDefaultInstanceForType();
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Master Result is value=" + response);
    }
    return response;
}
Also used : Message(com.google.protobuf.Message)

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