Search in sources :

Example 31 with Timestamp

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

the class Timestamps2Should method return_true_if_timestamp_is_between_two_timestamps.

@Test
public void return_true_if_timestamp_is_between_two_timestamps() {
    final Timestamp start = getCurrentTime();
    final Timestamp timeBetween = add(start, TEN_SECONDS);
    final Timestamp finish = add(timeBetween, TEN_SECONDS);
    final boolean isBetween = isBetween(timeBetween, start, finish);
    assertTrue(isBetween);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 32 with Timestamp

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

the class Timestamps2Should method compare_two_timestamps_return_positive_int_if_first_greater_than_second_one.

@Test
public void compare_two_timestamps_return_positive_int_if_first_greater_than_second_one() {
    final Timestamp currentTime = getCurrentTime();
    final Timestamp timeAfterCurrent = add(currentTime, TEN_SECONDS);
    final int result = compare(timeAfterCurrent, currentTime);
    assertTrue(result > 0);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 33 with Timestamp

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

the class Timestamps2Should method compare_two_timestamps_return_negative_int_if_first_less_than_second_one.

@Test
public void compare_two_timestamps_return_negative_int_if_first_less_than_second_one() {
    final Timestamp time1 = getCurrentTime();
    final Timestamp time2 = add(time1, TEN_SECONDS);
    final int result = compare(time1, time2);
    assertTrue(result < 0);
}
Also used : Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 34 with Timestamp

use of com.google.protobuf.Timestamp 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.base.Command) Timestamp(com.google.protobuf.Timestamp) Test(org.junit.Test)

Example 35 with Timestamp

use of com.google.protobuf.Timestamp in project beam by apache.

the class PubsubGrpcClient method pull.

@Override
public List<IncomingMessage> pull(long requestTimeMsSinceEpoch, SubscriptionPath subscription, int batchSize, boolean returnImmediately) throws IOException {
    PullRequest request = PullRequest.newBuilder().setSubscription(subscription.getPath()).setReturnImmediately(returnImmediately).setMaxMessages(batchSize).build();
    PullResponse response = subscriberStub().pull(request);
    if (response.getReceivedMessagesCount() == 0) {
        return ImmutableList.of();
    }
    List<IncomingMessage> incomingMessages = new ArrayList<>(response.getReceivedMessagesCount());
    for (ReceivedMessage message : response.getReceivedMessagesList()) {
        PubsubMessage pubsubMessage = message.getMessage();
        @Nullable Map<String, String> attributes = pubsubMessage.getAttributes();
        // Payload.
        byte[] elementBytes = pubsubMessage.getData().toByteArray();
        // Timestamp.
        String pubsubTimestampString = null;
        Timestamp timestampProto = pubsubMessage.getPublishTime();
        if (timestampProto != null) {
            pubsubTimestampString = String.valueOf(timestampProto.getSeconds() + timestampProto.getNanos() / 1000L);
        }
        long timestampMsSinceEpoch = extractTimestamp(timestampAttribute, pubsubTimestampString, attributes);
        // Ack id.
        String ackId = message.getAckId();
        checkState(!Strings.isNullOrEmpty(ackId));
        // Record id, if any.
        @Nullable String recordId = null;
        if (idAttribute != null && attributes != null) {
            recordId = attributes.get(idAttribute);
        }
        if (Strings.isNullOrEmpty(recordId)) {
            // Fall back to the Pubsub provided message id.
            recordId = pubsubMessage.getMessageId();
        }
        incomingMessages.add(new IncomingMessage(elementBytes, attributes, timestampMsSinceEpoch, requestTimeMsSinceEpoch, ackId, recordId));
    }
    return incomingMessages;
}
Also used : PullRequest(com.google.pubsub.v1.PullRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ReceivedMessage(com.google.pubsub.v1.ReceivedMessage) Timestamp(com.google.protobuf.Timestamp) PubsubMessage(com.google.pubsub.v1.PubsubMessage) PullResponse(com.google.pubsub.v1.PullResponse) Nullable(javax.annotation.Nullable)

Aggregations

Timestamp (com.google.protobuf.Timestamp)89 Test (org.junit.Test)66 Duration (com.google.protobuf.Duration)19 Interval (io.spine.time.Interval)11 Command (io.spine.base.Command)8 AbstractZonedTimeTest (io.spine.time.AbstractZonedTimeTest)8 LocalTime (io.spine.time.LocalTime)8 Message (com.google.protobuf.Message)4 StringValue (com.google.protobuf.StringValue)4 EventStreamQuery (io.spine.server.event.EventStreamQuery)4 TimeTests (io.spine.test.TimeTests)4 Nullable (javax.annotation.Nullable)4 Event (io.spine.base.Event)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Predicate (com.google.common.base.Predicate)2 ByteString (com.google.protobuf.ByteString)2 PubsubMessage (com.google.pubsub.v1.PubsubMessage)2 PullRequest (com.google.pubsub.v1.PullRequest)2 PullResponse (com.google.pubsub.v1.PullResponse)2 ReceivedMessage (com.google.pubsub.v1.ReceivedMessage)2