use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITReadOnlyTxnTest method writeNewValue.
private static void writeNewValue(DatabaseClient client, int i, @Nullable ImmutableList.Builder<History> historyBuilder) {
String value = "v" + i;
Mutation m = Mutation.newInsertOrUpdateBuilder(TABLE_NAME).set("StringValue").to(value).build();
long minCommitNanoTime = System.nanoTime();
Timestamp timestamp = client.writeAtLeastOnce(Arrays.asList(m));
if (historyBuilder != null) {
historyBuilder.add(new History(timestamp, value, minCommitNanoTime));
}
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITReadOnlyTxnTest method singleMinReadTimestamp.
@Test
public void singleMinReadTimestamp() {
int minimumIndex = 2;
History minimum = history.get(minimumIndex);
NavigableMap<Timestamp, String> possibleValues = new TreeMap<>();
for (History item : history.subList(minimumIndex, history.size())) {
possibleValues.put(item.timestamp, item.value);
}
TimestampBound bound = TimestampBound.ofMinReadTimestamp(minimum.timestamp);
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());
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindTimestampArrayEmpty.
@Test
public void bindTimestampArrayEmpty() {
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(Arrays.<Timestamp>asList()), Type.array(Type.timestamp()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestampList(0)).containsExactly();
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class TimestampBoundTest method equalsAndHashCode.
@Test
public void equalsAndHashCode() {
Timestamp ts = Timestamp.ofTimeSecondsAndNanos(1444662894L, 0);
Timestamp ts2 = Timestamp.ofTimeSecondsAndNanos(1444662895L, 0);
int staleness = 5;
EqualsTester tester = new EqualsTester();
tester.addEqualityGroup(TimestampBound.strong(), TimestampBound.strong());
tester.addEqualityGroup(TimestampBound.ofReadTimestamp(ts), TimestampBound.ofReadTimestamp(ts));
tester.addEqualityGroup(TimestampBound.ofReadTimestamp(ts2));
tester.addEqualityGroup(TimestampBound.ofMinReadTimestamp(ts), TimestampBound.ofMinReadTimestamp(ts));
tester.addEqualityGroup(TimestampBound.ofMinReadTimestamp(ts2));
tester.addEqualityGroup(TimestampBound.ofExactStaleness(staleness, TimeUnit.SECONDS), TimestampBound.ofExactStaleness(staleness, TimeUnit.SECONDS));
tester.addEqualityGroup(TimestampBound.ofExactStaleness(staleness, TimeUnit.MILLISECONDS));
tester.addEqualityGroup(TimestampBound.ofMaxStaleness(staleness, TimeUnit.SECONDS), TimestampBound.ofMaxStaleness(staleness, TimeUnit.SECONDS));
tester.addEqualityGroup(TimestampBound.ofMaxStaleness(staleness, TimeUnit.MILLISECONDS));
tester.testEquals();
}
use of com.google.cloud.Timestamp in project google-cloud-java by GoogleCloudPlatform.
the class ValueTest method timestamp.
@Test
public void timestamp() {
String timestamp = "2016-09-15T00:00:00Z";
Timestamp t = Timestamp.parseTimestamp(timestamp);
Value v = Value.timestamp(t);
assertThat(v.getType()).isEqualTo(Type.timestamp());
assertThat(v.isNull()).isFalse();
assertThat(v.getTimestamp()).isSameAs(t);
assertThat(v.toString()).isEqualTo(timestamp);
}
Aggregations