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