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