本文整理汇总了Java中com.google.protobuf.util.Timestamps类的典型用法代码示例。如果您正苦于以下问题:Java Timestamps类的具体用法?Java Timestamps怎么用?Java Timestamps使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Timestamps类属于com.google.protobuf.util包,在下文中一共展示了Timestamps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: anyInMaps
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void anyInMaps() throws Exception {
TestAny.Builder testAny = TestAny.newBuilder();
testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build()));
testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build()));
testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z")));
testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s")));
testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz")));
Value numberValue = Value.newBuilder().setNumberValue(1.125).build();
Struct.Builder struct = Struct.newBuilder();
struct.putFields("number", numberValue);
testAny.putAnyMap("struct", Any.pack(struct.build()));
Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
testAny.putAnyMap(
"list_value",
Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build()));
testAny.putAnyMap("number_value", Any.pack(numberValue));
testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue)));
testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance()));
testAny.putAnyMap("default", Any.getDefaultInstance());
assertMatchesUpstream(testAny.build(), TestAllTypes.getDefaultInstance());
}
示例2: shouldContinue
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
private static boolean shouldContinue(StartRequest request) {
// If the test has been running for at least a minute, and we have been idle for a minute, we
// should stop.
if (System.currentTimeMillis() - Timestamps.toMillis(request.getStartTime()) > MAX_IDLE_MILLIS
&& System.currentTimeMillis() - task.getLastUpdateMillis() > MAX_IDLE_MILLIS) {
return false;
}
switch (request.getStopConditionsCase()) {
case TEST_DURATION:
return System.currentTimeMillis()
< (request.getStartTime().getSeconds()
+ request.getBurnInDuration().getSeconds()
+ request.getTestDuration().getSeconds())
* 1000;
case NUMBER_OF_MESSAGES:
return task.getNumberOfMessages() < request.getNumberOfMessages();
default:
return false;
}
}
示例3: printStats
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
private void printStats(Map<ClientType, Controller.LoadtestStats> results) {
long startMillis = Timestamps.toMillis(Timestamps.add(Client.startTime, Client.burnInDuration));
if (System.currentTimeMillis() < startMillis) {
log.info(
"Still under burn in time, will start in "
+ ((startMillis - System.currentTimeMillis()) / 1000)
+ " seconds.");
return;
}
log.info("===============================================");
results.forEach(
(type, stats) -> {
log.info("Results for " + type + ":");
log.info("50%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 50.0));
log.info("99%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 99.0));
log.info("99.9%: " + LatencyDistribution.getNthPercentile(stats.bucketValues, 99.9));
log.info(
"Average throughput: "
+ new DecimalFormat("#.##").format(stats.getQPS() * messageSize / 1000000.0)
+ " MB/s");
});
log.info("===============================================");
}
示例4: keep_multiple_filters_for_single_column
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void keep_multiple_filters_for_single_column() throws ParseException {
final String columnName = "time";
final EntityColumn column = mock(EntityColumn.class);
// Some valid Timestamp values
final Timestamp startTime = Timestamps.parse("2000-01-01T10:00:00.000-05:00");
final Timestamp deadline = Timestamps.parse("2017-01-01T10:00:00.000-05:00");
final ColumnFilter startTimeFilter = gt(columnName, startTime);
final ColumnFilter deadlineFilter = le(columnName, deadline);
final Multimap<EntityColumn, ColumnFilter> columnFilters =
ImmutableMultimap.<EntityColumn, ColumnFilter>builder()
.put(column, startTimeFilter)
.put(column, deadlineFilter)
.build();
final CompositeQueryParameter parameter = from(columnFilters, ALL);
final QueryParameters parameters = newBuilder().add(parameter)
.build();
final List<CompositeQueryParameter> aggregatingParameters = newArrayList(parameters);
assertSize(1, aggregatingParameters);
final Multimap<EntityColumn, ColumnFilter> actualColumnFilters = aggregatingParameters.get(0).getFilters();
final Collection<ColumnFilter> timeFilters = actualColumnFilters.get(column);
assertSize(2, timeFilters);
assertContainsAll(timeFilters, startTimeFilter, deadlineFilter);
}
示例5: sort_by_version_rather_then_by_timestamp
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void sort_by_version_rather_then_by_timestamp() {
final Project state = Project.getDefaultInstance();
final Version minVersion = zero();
final Version maxVersion = increment(minVersion);
final Timestamp minTimestamp = Timestamps.MIN_VALUE;
final Timestamp maxTimestamp = Timestamps.MAX_VALUE;
// The first event is an event, which is the oldest, i.e. with the minimal version.
final Event expectedFirst = eventFactory.createEvent(state, minVersion, maxTimestamp);
final Event expectedSecond = eventFactory.createEvent(state, maxVersion, minTimestamp);
storage.writeEvent(id, expectedSecond);
storage.writeEvent(id, expectedFirst);
final List<Event> events = storage.read(newReadRequest(id))
.get()
.getEventList();
assertTrue(events.indexOf(expectedFirst) < events.indexOf(expectedSecond));
}
示例6: testExtractNestedTimestampMillis
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void testExtractNestedTimestampMillis() throws Exception {
Map<String, String> classPerTopic = new HashMap<String, String>();
classPerTopic.put("*", TimestampedMessages.UnitTestTimestamp2.class.getName());
Mockito.when(mConfig.getMessageTimestampName()).thenReturn("internal.timestamp");
Mockito.when(mConfig.getProtobufMessageClassPerTopic()).thenReturn(classPerTopic);
ProtobufMessageParser parser = new ProtobufMessageParser(mConfig);
Timestamp timestamp = Timestamps.fromMillis(1405970352000L);
TimestampedMessages.UnitTestTimestamp2 message = TimestampedMessages.UnitTestTimestamp2.newBuilder()
.setInternal(TimestampedMessages.UnitTestTimestamp2.Internal.newBuilder().setTimestamp(timestamp).build()).build();
assertEquals(1405970352000l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
timestamp = Timestamps.fromMillis(1405970352123l);
message = TimestampedMessages.UnitTestTimestamp2.newBuilder()
.setInternal(TimestampedMessages.UnitTestTimestamp2.Internal.newBuilder().setTimestamp(timestamp).build()).build();
assertEquals(1405970352123l,
parser.extractTimestampMillis(new Message("test", 0, 0, null, message.toByteArray(), timestamp.getSeconds())));
}
示例7: publishBuildToolEventStreamRequest
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@VisibleForTesting
public PublishBuildToolEventStreamRequest publishBuildToolEventStreamRequest(
int sequenceNumber, BuildEvent.Builder besEvent) {
PublishBuildToolEventStreamRequest.Builder builder =
PublishBuildToolEventStreamRequest.newBuilder()
.setOrderedBuildEvent(
OrderedBuildEvent.newBuilder()
.setSequenceNumber(sequenceNumber)
.setEvent(
besEvent.setEventTime(Timestamps.fromMillis(clock.currentTimeMillis())))
.setStreamId(streamId(besEvent.getEventCase())));
if (sequenceNumber == 1) {
builder.addAllNotificationKeywords(getKeywords());
}
return builder.build();
}
示例8: testBuildEnqueued
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void testBuildEnqueued() {
long expected = clock.advanceMillis(100);
assertThat(besProtocol.buildEnqueued())
.isEqualTo(
PublishLifecycleEventRequest.newBuilder()
.setServiceLevel(ServiceLevel.INTERACTIVE)
.setProjectId(PROJECT_ID)
.setBuildEvent(
OrderedBuildEvent.newBuilder()
.setStreamId(
StreamId.newBuilder()
.setBuildId(BUILD_REQUEST_ID)
.setComponent(BuildComponent.CONTROLLER))
.setSequenceNumber(1)
.setEvent(
BuildEvent.newBuilder()
.setEventTime(Timestamps.fromMillis(expected))
.setBuildEnqueued(BuildEnqueued.newBuilder())))
.build());
}
示例9: testInvocationAttemptStarted
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void testInvocationAttemptStarted() {
long expected = clock.advanceMillis(100);
assertThat(besProtocol.invocationStarted())
.isEqualTo(
PublishLifecycleEventRequest.newBuilder()
.setServiceLevel(ServiceLevel.INTERACTIVE)
.setProjectId(PROJECT_ID)
.setBuildEvent(
OrderedBuildEvent.newBuilder()
.setStreamId(
StreamId.newBuilder()
.setBuildId(BUILD_REQUEST_ID)
.setInvocationId(BUILD_INVOCATION_ID)
.setComponent(BuildComponent.CONTROLLER))
.setSequenceNumber(1)
.setEvent(
BuildEvent.newBuilder()
.setEventTime(Timestamps.fromMillis(expected))
.setInvocationAttemptStarted(
InvocationAttemptStarted.newBuilder().setAttemptNumber(1))))
.build());
}
示例10: testInvocationAttemptFinished
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void testInvocationAttemptFinished() {
long expected = clock.advanceMillis(100);
assertThat(besProtocol.invocationFinished(Result.COMMAND_SUCCEEDED))
.isEqualTo(
PublishLifecycleEventRequest.newBuilder()
.setServiceLevel(ServiceLevel.INTERACTIVE)
.setProjectId(PROJECT_ID)
.setBuildEvent(
OrderedBuildEvent.newBuilder()
.setStreamId(
StreamId.newBuilder()
.setBuildId(BUILD_REQUEST_ID)
.setInvocationId(BUILD_INVOCATION_ID)
.setComponent(BuildComponent.CONTROLLER))
.setSequenceNumber(2)
.setEvent(
BuildEvent.newBuilder()
.setEventTime(Timestamps.fromMillis(expected))
.setInvocationAttemptFinished(
InvocationAttemptFinished.newBuilder()
.setInvocationStatus(
BuildStatus.newBuilder()
.setResult(Result.COMMAND_SUCCEEDED)))))
.build());
}
示例11: testBuildFinished
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Test
public void testBuildFinished() {
long expected = clock.advanceMillis(100);
assertThat(besProtocol.buildFinished(Result.COMMAND_SUCCEEDED))
.isEqualTo(
PublishLifecycleEventRequest.newBuilder()
.setServiceLevel(ServiceLevel.INTERACTIVE)
.setProjectId(PROJECT_ID)
.setBuildEvent(
OrderedBuildEvent.newBuilder()
.setStreamId(
StreamId.newBuilder()
.setBuildId(BUILD_REQUEST_ID)
.setComponent(BuildComponent.CONTROLLER))
.setSequenceNumber(2)
.setEvent(
BuildEvent.newBuilder()
.setEventTime(Timestamps.fromMillis(expected))
.setBuildFinished(
BuildFinished.newBuilder()
.setStatus(
BuildStatus.newBuilder()
.setResult(Result.COMMAND_SUCCEEDED)))))
.build());
}
示例12: generateLoadReport
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
/**
* Generate the report with the data recorded this LB stream since the last report.
*/
ClientStats generateLoadReport() {
ClientStats.Builder statsBuilder =
ClientStats.newBuilder()
.setTimestamp(Timestamps.fromMillis(time.currentTimeMillis()))
.setNumCallsStarted(callsStartedUpdater.getAndSet(this, 0))
.setNumCallsFinished(callsFinishedUpdater.getAndSet(this, 0))
.setNumCallsFinishedWithClientFailedToSend(callsFailedToSendUpdater.getAndSet(this, 0))
.setNumCallsFinishedKnownReceived(callsFinishedKnownReceivedUpdater.getAndSet(this, 0));
Map<String, LongHolder> localCallsDroppedPerToken = Collections.emptyMap();
synchronized (this) {
if (!callsDroppedPerToken.isEmpty()) {
localCallsDroppedPerToken = callsDroppedPerToken;
callsDroppedPerToken = new HashMap<String, LongHolder>(localCallsDroppedPerToken.size());
}
}
for (Entry<String, LongHolder> entry : localCallsDroppedPerToken.entrySet()) {
statsBuilder.addCallsFinishedWithDrop(
ClientStatsPerToken.newBuilder()
.setLoadBalanceToken(entry.getKey())
.setNumCalls(entry.getValue().num)
.build());
}
return statsBuilder.build();
}
示例13: valueToTimestamp
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Nullable
private String valueToTimestamp(Value v) {
boolean isTimestampValue = v.getValueTypeCase().equals(ValueTypeCase.TIMESTAMP_VALUE);
if (!isTimestampValue) {
return null;
}
return Timestamps.toString(v.getTimestampValue());
}
示例14: fromLocalDateTime
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
/** Converts a {@link LocalDateTime} to {@link Timestamp}. */
public static Timestamp fromLocalDateTime(LocalDateTime localDateTime, ZoneOffset zone) {
return Timestamps.fromNanos(
TimeUnit.SECONDS.toNanos(localDateTime.toEpochSecond(zone)) + localDateTime.getNano());
}
示例15: doMerge
import com.google.protobuf.util.Timestamps; //导入依赖的package包/类
@Override
public void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder)
throws IOException {
Timestamp.Builder builder = (Timestamp.Builder) messageBuilder;
try {
builder.mergeFrom(Timestamps.parse(ParseSupport.parseString(parser)));
} catch (ParseException e) {
throw new InvalidProtocolBufferException(
"Failed to readValue timestamp: " + parser.getText());
}
}