@Test public void multiMinReadTimestamp() { // Cannot use bounded modes with multi-read transactions. expectedException.expect(IllegalArgumentException.class); client.readOnlyTransaction(TimestampBound.ofMinReadTimestamp(history.get(2).timestamp)); }
@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()); }
@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 + " }"); }
@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(); }
@Test public void serialization() throws Exception { reserializeAndAssert(TimestampBound.strong()); reserializeAndAssert(TimestampBound.ofExactStaleness(10, TimeUnit.NANOSECONDS)); reserializeAndAssert(TimestampBound.ofMaxStaleness(100, TimeUnit.DAYS)); reserializeAndAssert(TimestampBound.ofMinReadTimestamp(Timestamp.now())); reserializeAndAssert(TimestampBound.ofReadTimestamp(Timestamp.now())); }