Java Code Examples for com.google.protobuf.util.Timestamps#fromMillis()

The following examples show how to use com.google.protobuf.util.Timestamps#fromMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufTimestampParserTest.java    From secor with Apache License 2.0 6 votes vote down vote up
@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(), null)));

    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(), null)));
}
 
Example 2
Source File: BuildEventServiceProtoUtilTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildEnqueued() {
  Timestamp expected = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.buildEnqueued(expected))
      .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(expected)
                              .setBuildEnqueued(BuildEnqueued.newBuilder())))
              .build());
}
 
Example 3
Source File: BuildEventServiceProtoUtilTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvocationAttemptStarted() {
  Timestamp expected = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.invocationStarted(expected))
      .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(expected)
                              .setInvocationAttemptStarted(
                                  InvocationAttemptStarted.newBuilder().setAttemptNumber(1))))
              .build());
}
 
Example 4
Source File: BuildEventServiceProtoUtilTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvocationAttemptFinished() {
  Timestamp expected = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.invocationFinished(expected, 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(expected)
                              .setInvocationAttemptFinished(
                                  InvocationAttemptFinished.newBuilder()
                                      .setInvocationStatus(
                                          BuildStatus.newBuilder()
                                              .setResult(Result.COMMAND_SUCCEEDED)))))
              .build());
}
 
Example 5
Source File: BuildEventServiceProtoUtilTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildFinished() {
  Timestamp expected = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.buildFinished(expected, 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(expected)
                              .setBuildFinished(
                                  BuildFinished.newBuilder()
                                      .setStatus(
                                          BuildStatus.newBuilder()
                                              .setResult(Result.COMMAND_SUCCEEDED)))))
              .build());
}
 
Example 6
Source File: Row.java    From feast with Apache License 2.0 5 votes vote down vote up
public static Row create() {
  Row row = new Row();
  row.entity_timestamp = Timestamps.fromMillis(System.currentTimeMillis());
  row.fields = new HashMap<>();
  row.fieldStatuses = new HashMap<>();
  return row;
}
 
Example 7
Source File: MatchStage.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
private OperationContext match(OperationContext operationContext) {
  Timestamp workerStartTimestamp = Timestamps.fromMillis(System.currentTimeMillis());

  ExecuteEntry executeEntry = operationContext.queueEntry.getExecuteEntry();
  // this may be superfluous - we can probably just set the name and action digest
  Operation operation =
      Operation.newBuilder()
          .setName(executeEntry.getOperationName())
          .setMetadata(
              Any.pack(
                  ExecuteOperationMetadata.newBuilder()
                      .setActionDigest(executeEntry.getActionDigest())
                      .setStage(QUEUED)
                      .setStdoutStreamName(executeEntry.getStdoutStreamName())
                      .setStderrStreamName(executeEntry.getStderrStreamName())
                      .build()))
          .build();

  OperationContext matchedOperationContext =
      operationContext.toBuilder().setOperation(operation).build();

  matchedOperationContext
      .executeResponse
      .getResultBuilder()
      .getExecutionMetadataBuilder()
      .setWorker(workerContext.getName())
      .setQueuedTimestamp(executeEntry.getQueuedTimestamp())
      .setWorkerStartTimestamp(workerStartTimestamp);
  return matchedOperationContext;
}
 
Example 8
Source File: PutOperationStage.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
OperationStageDurations getAverageOfLastPeriod() {
  // creating a Timestamp representing now to trigger stale data throwing away
  Timestamp now = Timestamps.fromMillis(System.currentTimeMillis());
  removeStaleData(now);

  // compute unweighted average of all buckets
  averageTimeCosts.reset();
  for (OperationStageDurations bucket : buckets) {
    averageTimeCosts.addOperations(bucket.computeAverage(bucket.operationCount));
  }
  averageTimeCosts = averageTimeCosts.computeAverage(buckets.length);
  averageTimeCosts.period = period;
  return averageTimeCosts;
}
 
Example 9
Source File: TimeUtil.java    From live-transcribe-speech-engine with Apache License 2.0 4 votes vote down vote up
public static Timestamp toTimestamp(Instant t) {
  return Timestamps.fromMillis(t.getMillis());
}
 
Example 10
Source File: MonitoringService.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 4 votes vote down vote up
private void flush() {
  HashMap<IMonitoringEvent, Long> flushEvents = null;
  synchronized (aggregateEvents) {
    flushEvents = new HashMap<>(aggregateEvents);
    aggregateEvents.clear();
  }

  try {
    Timestamp flushTime = Timestamps.fromMillis(System.currentTimeMillis());

    List<TimeSeries> timeSeriesList = new ArrayList<>();
    for (IMonitoringEvent event : monitoredEvents) {
      TimeInterval interval = TimeInterval.newBuilder()
          .setEndTime(flushTime)
          .build();
      TypedValue value = TypedValue.newBuilder()
          .setInt64Value(flushEvents.getOrDefault(event, 0L))
          .build();
      Point point = Point.newBuilder()
          .setInterval(interval)
          .setValue(value)
          .build();

      List<Point> pointList = new ArrayList<>();
      pointList.add(point);

      Metric metric = Metric.newBuilder()
          .setType(event.getMetricName())
          .build();

      TimeSeries timeSeries = TimeSeries.newBuilder()
          .setMetric(metric)
          .setMetricKind(MetricDescriptor.MetricKind.GAUGE)
          .setResource(monitoredResource)
          .addAllPoints(pointList)
          .build();

      timeSeriesList.add(timeSeries);
    }

    ProjectName projectName = ProjectName.of(projectId);
    CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder()
        .setName(projectName.toString())
        .addAllTimeSeries(timeSeriesList)
        .build();

    client.createTimeSeries(request);

    log.trace("Flushed {} non-zero time series", flushEvents.size());
    if (flushEvents.size() > 0) {
      log.info("Flushed: {}", flushEvents);
    }
  } catch (Throwable e) {
    log.error("Failed to flush time series", e);
  }
}
 
Example 11
Source File: Utils.java    From julongchain with Apache License 2.0 4 votes vote down vote up
public static Timestamp createUtcTimeStamp(){
    Timestamp timeStamp= Timestamps.fromMillis(new Date().getTime());
    return timeStamp;
}
 
Example 12
Source File: Row.java    From feast with Apache License 2.0 4 votes vote down vote up
public Row setEntityTimestamp(Instant timestamp) {
  entity_timestamp = Timestamps.fromMillis(timestamp.toEpochMilli());
  return this;
}
 
Example 13
Source File: Row.java    From feast with Apache License 2.0 4 votes vote down vote up
public Row setEntityTimestamp(String dateTime) {
  entity_timestamp = Timestamps.fromMillis(Instant.parse(dateTime).toEpochMilli());
  return this;
}
 
Example 14
Source File: BuildEventServiceUploader.java    From bazel with Apache License 2.0 4 votes vote down vote up
private Timestamp currentTime() {
  return Timestamps.fromMillis(clock.currentTimeMillis());
}
 
Example 15
Source File: BuildEventServiceProtoUtilTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamEvents() {
  Timestamp firstEventTimestamp = Timestamps.fromMillis(clock.advanceMillis(100));
  Any anything = Any.getDefaultInstance();
  assertThat(BES_PROTO_UTIL.bazelEvent(1, firstEventTimestamp, anything))
      .isEqualTo(
          PublishBuildToolEventStreamRequest.newBuilder()
              .addAllNotificationKeywords(EXPECTED_KEYWORDS)
              .setProjectId(PROJECT_ID)
              .setOrderedBuildEvent(
                  OrderedBuildEvent.newBuilder()
                      .setStreamId(
                          StreamId.newBuilder()
                              .setBuildId(BUILD_REQUEST_ID)
                              .setInvocationId(BUILD_INVOCATION_ID)
                              .setComponent(BuildComponent.TOOL))
                      .setSequenceNumber(1)
                      .setEvent(
                          BuildEvent.newBuilder()
                              .setEventTime(firstEventTimestamp)
                              .setBazelEvent(anything))
                      .build())
              .build());

  Timestamp secondEventTimestamp = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.bazelEvent(2, secondEventTimestamp, anything))
      .isEqualTo(
          PublishBuildToolEventStreamRequest.newBuilder()
              .setProjectId(PROJECT_ID)
              .setOrderedBuildEvent(
                  OrderedBuildEvent.newBuilder()
                      .setStreamId(
                          StreamId.newBuilder()
                              .setBuildId(BUILD_REQUEST_ID)
                              .setInvocationId(BUILD_INVOCATION_ID)
                              .setComponent(BuildComponent.TOOL))
                      .setSequenceNumber(2)
                      .setEvent(
                          BuildEvent.newBuilder()
                              .setEventTime(secondEventTimestamp)
                              .setBazelEvent(anything))
                      .build())
              .build());

  Timestamp thirdEventTimestamp = Timestamps.fromMillis(clock.advanceMillis(100));
  assertThat(BES_PROTO_UTIL.streamFinished(3, thirdEventTimestamp))
      .isEqualTo(
          PublishBuildToolEventStreamRequest.newBuilder()
              .setProjectId(PROJECT_ID)
              .setOrderedBuildEvent(
                  OrderedBuildEvent.newBuilder()
                      .setStreamId(
                          StreamId.newBuilder()
                              .setBuildId(BUILD_REQUEST_ID)
                              .setInvocationId(BUILD_INVOCATION_ID)
                              .setComponent(BuildComponent.TOOL))
                      .setSequenceNumber(3)
                      .setEvent(
                          BuildEvent.newBuilder()
                              .setEventTime(thirdEventTimestamp)
                              .setComponentStreamFinished(
                                  BuildComponentStreamFinished.newBuilder()
                                      .setType(FinishType.FINISHED)))
                      .build())
              .build());
}