use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeTimestamp.
@Test
public void writeTimestamp() {
Timestamp timestamp = Timestamp.parseTimestamp("2016-09-15T00:00:00.111111Z");
write(baseInsert().set("TimestampValue").to(timestamp).build());
Struct row = readLastRow("TimestampValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestamp(0)).isEqualTo(timestamp);
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindTimestampArray.
@Test
public void bindTimestampArray() {
Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(Arrays.asList(t1, t2, null)), Type.array(Type.timestamp()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestampList(0)).containsExactly(t1, t2, null).inOrder();
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindTimestampNull.
@Test
public void bindTimestampNull() {
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to((Timestamp) null), Type.timestamp());
assertThat(row.isNull(0)).isTrue();
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindTimestamp.
@Test
public void bindTimestamp() {
Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp());
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestamp(0)).isEqualTo(t);
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITReadOnlyTxnTest method singleMaxStaleness.
@Test
public void singleMaxStaleness() {
History minimum = history.get(2);
NavigableMap<Timestamp, String> possibleValues = new TreeMap<>();
for (History item : history.subList(2, history.size())) {
possibleValues.put(item.timestamp, item.value);
}
// Pick a staleness that cannot precede the second write (which, in practice, is the staleness
// that exceeds the minimum commit time for the subsequent write).
long stalenessNanos = System.nanoTime() - history.get(3).minCommitNanoTime;
TimestampBound bound = TimestampBound.ofMaxStaleness(stalenessNanos, TimeUnit.NANOSECONDS);
ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound);
Struct row = readRow(readContext);
assertThat(row).isNotNull();
assertThat(readContext.getReadTimestamp()).isAtLeast(minimum.timestamp);
assertThat(row.getString(0)).isEqualTo(possibleValues.floorEntry(readContext.getReadTimestamp()).getValue());
row = readRow(client.singleUse(bound));
assertThat(row).isNotNull();
assertThat(row.getString(0)).isIn(possibleValues.values());
}
Aggregations