Search in sources :

Example 1 with Timestamp

use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.

the class ITWriteTest method writeTimestampArray.

@Test
public void writeTimestampArray() {
    Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
    Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
    write(baseInsert().set("TimestampArrayValue").toTimestampArray(Arrays.asList(t1, null, t2)).build());
    Struct row = readLastRow("TimestampArrayValue");
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestampList(0)).containsExactly(t1, null, t2).inOrder();
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 2 with Timestamp

use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.

the class SessionImplTest method writeAtLeastOnce.

@Test
public void writeAtLeastOnce() throws ParseException {
    String timestampString = "2015-10-01T10:54:20.021Z";
    ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class);
    CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build();
    Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response);
    Timestamp timestamp = session.writeAtLeastOnce(Arrays.asList(Mutation.newInsertBuilder("T").set("C").to("x").build()));
    assertThat(timestamp.getSeconds()).isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20));
    assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21));
    CommitRequest request = commit.getValue();
    assertThat(request.getSingleUseTransaction()).isNotNull();
    assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull();
    com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder().setInsert(Write.newBuilder().setTable("T").addColumns("C").addValues(ListValue.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))).build();
    assertThat(request.getMutationsList()).containsExactly(mutation);
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) CommitResponse(com.google.spanner.v1.CommitResponse) ByteString(com.google.protobuf.ByteString) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 3 with Timestamp

use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.

the class TimestampBoundTest method readTimestamp.

@Test
public void readTimestamp() {
    Timestamp ts = Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0);
    TimestampBound bound = TimestampBound.ofReadTimestamp(ts);
    assertThat(bound.getMode()).isEqualTo(Mode.READ_TIMESTAMP);
    assertThat(bound.getReadTimestamp()).isEqualTo(ts);
    assertThat(bound.toString()).isEqualTo("exact_timestamp: " + TEST_TIME_ISO);
    assertProto(bound, "read_timestamp { seconds: " + TEST_TIME_SECONDS + " }");
}
Also used : Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 4 with Timestamp

use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.

the class TimestampBoundTest method minReadTimestamp.

@Test
public void minReadTimestamp() {
    Timestamp ts = Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0);
    TimestampBound bound = TimestampBound.ofMinReadTimestamp(ts);
    assertThat(bound.getMode()).isEqualTo(Mode.MIN_READ_TIMESTAMP);
    assertThat(bound.getMinReadTimestamp()).isEqualTo(ts);
    assertThat(bound.toString()).isEqualTo("min_read_timestamp: " + TEST_TIME_ISO);
    assertProto(bound, "min_read_timestamp { seconds: " + TEST_TIME_SECONDS + " }");
}
Also used : Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 5 with Timestamp

use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method testDefaultWriteOptionsHasExpectedDefaults.

@Test
public void testDefaultWriteOptionsHasExpectedDefaults() {
    logging.setFlushSeverity(Severity.ERROR);
    Capture<WriteOption> logNameArg = Capture.newInstance();
    Capture<WriteOption> resourceArg = Capture.newInstance();
    logging.write((Iterable<LogEntry>) anyObject(), capture(logNameArg), capture(resourceArg));
    expectLastCall().once();
    replay(logging);
    loggingAppender.start();
    Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
    LoggingEvent loggingEvent = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
    loggingAppender.doAppend(loggingEvent);
    Assert.assertTrue(logNameArg.getValue().equals(defaultWriteOptions[0]));
    Assert.assertTrue(resourceArg.getValue().equals(defaultWriteOptions[1]));
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Timestamp(com.google.cloud.Timestamp) LogEntry(com.google.cloud.logging.LogEntry) WriteOption(com.google.cloud.logging.Logging.WriteOption) Test(org.junit.Test)

Aggregations

Timestamp (com.google.cloud.Timestamp)22 Test (org.junit.Test)20 Struct (com.google.cloud.spanner.Struct)9 IntegrationTest (com.google.cloud.spanner.IntegrationTest)8 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)4 LogEntry (com.google.cloud.logging.LogEntry)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Date (com.google.cloud.Date)2 Mutation (com.google.cloud.spanner.Mutation)2 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)2 TimestampBound (com.google.cloud.spanner.TimestampBound)2 EqualsTester (com.google.common.testing.EqualsTester)2 TreeMap (java.util.TreeMap)2 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)1 WriteOption (com.google.cloud.logging.Logging.WriteOption)1 TransactionContext (com.google.cloud.spanner.TransactionContext)1 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1 TransactionCallable (com.google.cloud.spanner.TransactionRunner.TransactionCallable)1 ByteString (com.google.protobuf.ByteString)1 CommitRequest (com.google.spanner.v1.CommitRequest)1