Java Code Examples for com.google.cloud.Timestamp#now()

The following examples show how to use com.google.cloud.Timestamp#now() . 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: LoadTest.java    From beam with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the load test, collects and publishes test results to various data store and/or console.
 */
public PipelineResult run() throws IOException {
  final Timestamp timestamp = Timestamp.now();

  loadTest();

  final PipelineResult pipelineResult = pipeline.run();
  pipelineResult.waitUntilFinish(Duration.standardMinutes(options.getLoadTestTimeout()));

  final String testId = UUID.randomUUID().toString();
  final List<NamedTestResult> metrics = readMetrics(timestamp, pipelineResult, testId);

  ConsoleResultPublisher.publish(metrics, testId, timestamp.toString());

  handleFailure(pipelineResult, metrics);

  if (options.getPublishToBigQuery()) {
    publishResultsToBigQuery(metrics);
  }

  if (options.getPublishToInfluxDB()) {
    InfluxDBPublisher.publishWithSettings(metrics, settings);
  }

  return pipelineResult;
}
 
Example 2
Source File: GoogleJobStore.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
private Entity createNewEntity(UUID jobId, Map<String, Object> data) throws IOException {
  Timestamp createdTime = Timestamp.now();

  return GoogleCloudUtils.createEntityBuilder(getJobKey(jobId), data)
      .set(CREATED_FIELD, createdTime)
      .set(LAST_UPDATE_FIELD, createdTime)
      .build();
}
 
Example 3
Source File: TransactionThreadTest.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public <T> T run(TransactionCallable<T> callable) {
  T res = null;
  try {
    for (int i = 0; i < runs; i++) {
      mock.clearMutations();
      res = callable.run(mock.createTransactionContextMock());
    }
    commitTimestamp = Timestamp.now();
  } catch (Exception e) {
    throw new RuntimeException(e.getMessage(), e);
  }
  return res;
}
 
Example 4
Source File: ZonedDateTimeMapperTest.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Test
public void testToModel_Now() {
  Timestamp now = Timestamp.now();
  TimestampValue v = TimestampValue.newBuilder(now).build();
  ZonedDateTimeMapper mapper = new ZonedDateTimeMapper();
  ZonedDateTime output = (ZonedDateTime) mapper.toModel(v);
  assertEquals(now.getSeconds(), output.toEpochSecond());
  assertEquals(now.getNanos(), output.getNano());
}
 
Example 5
Source File: TextIOIT.java    From beam with Apache License 2.0 5 votes vote down vote up
private void collectAndPublishMetrics(PipelineResult result) {
  String uuid = UUID.randomUUID().toString();
  Timestamp timestamp = Timestamp.now();

  Set<Function<MetricsReader, NamedTestResult>> metricSuppliers =
      fillMetricSuppliers(uuid, timestamp.toString());

  final IOITMetrics metrics =
      new IOITMetrics(metricSuppliers, result, FILEIOIT_NAMESPACE, uuid, timestamp.toString());
  metrics.publish(bigQueryDataset, bigQueryTable);
  metrics.publishToInflux(settings);
}
 
Example 6
Source File: SpannerConvertersTest.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Test
public void dateConversionTest() {
	Timestamp timestamp = Timestamp.now();
	assertThat(SpannerConverters.DATE_TIMESTAMP_CONVERTER
			.convert(SpannerConverters.TIMESTAMP_DATE_CONVERTER.convert(timestamp))).isEqualTo(timestamp);
}
 
Example 7
Source File: SpannerGroupWrite.java    From java-docs-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  Options options = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
  Pipeline p = Pipeline.create(options);

  String instanceId = options.getInstanceId();
  String databaseId = options.getDatabaseId();

  String usersIdFile = options.getSuspiciousUsersFile();

  PCollection<String> suspiciousUserIds = p.apply(TextIO.read().from(usersIdFile));

  final Timestamp timestamp = Timestamp.now();

  // [START spanner_dataflow_writegroup]
  PCollection<MutationGroup> mutations = suspiciousUserIds
      .apply(MapElements.via(new SimpleFunction<String, MutationGroup>() {

        @Override
        public MutationGroup apply(String userId) {
          // Immediately block the user.
          Mutation userMutation = Mutation.newUpdateBuilder("Users")
              .set("id").to(userId)
              .set("state").to("BLOCKED")
              .build();
          long generatedId = Hashing.sha1().newHasher()
              .putString(userId, Charsets.UTF_8)
              .putLong(timestamp.getSeconds())
              .putLong(timestamp.getNanos())
              .hash()
              .asLong();

          // Add an entry to pending review requests.
          Mutation pendingReview = Mutation.newInsertOrUpdateBuilder("PendingReviews")
              .set("id").to(generatedId)  // Must be deterministically generated.
              .set("userId").to(userId)
              .set("action").to("REVIEW ACCOUNT")
              .set("note").to("Suspicious activity detected.")
              .build();

          return MutationGroup.create(userMutation, pendingReview);
        }
      }));

  mutations.apply(SpannerIO.write()
      .withInstanceId(instanceId)
      .withDatabaseId(databaseId)
      .grouped());
  // [END spanner_dataflow_writegroup]

  p.run().waitUntilFinish();

}