assertThat(row1).isLessThan(row2); assertThat(row2).isGreaterThan(row1);
@Test public void multiExactStaleness() { setUpPrivateDatabase(); // See singleExactStaleness() for why we pick this timestamp. We expect to see no value. long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1); long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime; try (ReadOnlyTransaction readContext = client.readOnlyTransaction( TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS))) { Struct row = readRow(readContext); assertThat(row).isNull(); assertThat(readContext.getReadTimestamp().toSqlTimestamp()) .isLessThan(history.get(0).timestamp.toSqlTimestamp()); insertAndReadAgain(readContext, readContext.getReadTimestamp(), null); } }
@Test public void singleExactStaleness() { // TODO(user): Use a shorter deadline (when supported) and pass on the call to Cloud Spanner. long deadlineNanoTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(1); // The only exact staleness values that can be tested reliably are before the first item or // later than the last item: we choose the former. // // Pick a staleness that is "guaranteed" not to observe the first write. Note that this // guarantee doesn't strictly hold in the absence of enforced read deadlines, but we use a // deadline large enough to make it practically true. long stalenessNanos = 1 + deadlineNanoTime - history.get(0).minCommitNanoTime; TimestampBound bound = TimestampBound.ofExactStaleness(stalenessNanos, TimeUnit.NANOSECONDS); ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound); Struct row = readRow(readContext); assertThat(row).isNull(); assertThat(readContext.getReadTimestamp().toSqlTimestamp()) .isLessThan(history.get(0).timestamp.toSqlTimestamp()); row = readRow(client.singleUse(bound)); assertThat(row).isNull(); }
@Test public void comparable() { assertThat(Timestamp.MIN_VALUE).isLessThan(Timestamp.MAX_VALUE); assertThat(Timestamp.MAX_VALUE).isGreaterThan(Timestamp.MIN_VALUE); assertThat(Timestamp.ofTimeSecondsAndNanos(100, 0)) .isAtLeast(Timestamp.ofTimeSecondsAndNanos(100, 0)); assertThat(Timestamp.ofTimeSecondsAndNanos(100, 0)) .isAtMost(Timestamp.ofTimeSecondsAndNanos(100, 0)); assertThat(Timestamp.ofTimeSecondsAndNanos(100, 1000)) .isLessThan(Timestamp.ofTimeSecondsAndNanos(101, 0)); assertThat(Timestamp.ofTimeSecondsAndNanos(100, 1000)) .isAtMost(Timestamp.ofTimeSecondsAndNanos(101, 0)); assertThat(Timestamp.ofTimeSecondsAndNanos(101, 0)) .isGreaterThan(Timestamp.ofTimeSecondsAndNanos(100, 1000)); assertThat(Timestamp.ofTimeSecondsAndNanos(101, 0)) .isAtLeast(Timestamp.ofTimeSecondsAndNanos(100, 1000)); }
@Test public void testComparableComparesByPrice() { assertThat(sku1).isGreaterThan(sku2); assertThat(sku1).isGreaterThan(sku3); assertThat(sku3).isLessThan(sku2); assertThat(sku3).isLessThan(sku1); }