private void storeUpperLimit(long upperLimit) { DebugLogger.willStoreNewUpperLimit(upperLimit); store.storeUpperLimit(upperLimit); DebugLogger.didStoreNewUpperLimit(upperLimit); }
@Override public synchronized void storeUpperLimit(long limit) { failures.verifyWeShouldIssueMoreTimestamps(); throwIfInterrupted(); try { delegate.storeUpperLimit(limit); } catch (Throwable t) { throw failures.responseTo(t); } }
@Test public void canBackupAlreadyStoredBound() { timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_1); assertThat(backupRunner.backupExistingTimestamp()).isEqualTo(TIMESTAMP_1); }
private long getBoundAfterTakingOutOneMillionTimestamps() { TimestampBoundStore timestampBoundStore = CassandraTimestampBoundStore.create(kv); long newLimit = timestampBoundStore.getUpperLimit() + ONE_MILLION; timestampBoundStore.storeUpperLimit(newLimit); return newLimit; } }
@Test public void shouldNotChangeTheCurrentUpperLimitIfItFailsToPersist() { doThrow(RuntimeException.class).when(boundStore).storeUpperLimit(anyLong()); try { upperLimit.increaseToAtLeast(INITIAL_UPPER_LIMIT + 10); } catch (Exception e) { // We expect this to throw } assertThat(upperLimit.get(), is(INITIAL_UPPER_LIMIT)); }
@Test public void resilientToMultipleStoreUpperLimitBeforeGet() { TimestampBoundStore ts = CassandraTimestampBoundStore.create(kv); long limit = ts.getUpperLimit(); ts.storeUpperLimit(limit + 10); ts.storeUpperLimit(limit + 20); Assert.assertEquals(limit + 20, ts.getUpperLimit()); }
@Test public void testTimestampBoundStore() { long upperLimit1 = store.getUpperLimit(); long upperLimit2 = store.getUpperLimit(); Assert.assertEquals(upperLimit1, upperLimit2); store.storeUpperLimit(upperLimit2 + 1); long upperLimit3 = store.getUpperLimit(); Assert.assertEquals(upperLimit3, upperLimit2 + 1); } }
@Test public void shouldPersistAnIncreasedTimestamp() { upperLimit.increaseToAtLeast(TIMESTAMP); long biggerLimit = upperLimit.get() + 1000; upperLimit.increaseToAtLeast(biggerLimit); verify(boundStore).storeUpperLimit(biggerLimit + BUFFER); }
@Test public void testBounds() { TimestampBoundStore ts = CassandraTimestampBoundStore.create(kv); long limit = ts.getUpperLimit(); ts.storeUpperLimit(limit + 10); Assert.assertEquals(limit + 10, ts.getUpperLimit()); ts.storeUpperLimit(limit + 20); Assert.assertEquals(limit + 20, ts.getUpperLimit()); ts.storeUpperLimit(limit + 30); Assert.assertEquals(limit + 30, ts.getUpperLimit()); }
@Test public void canBackupAndRestoreTimestampTable() { TimestampBoundStore timestampBoundStore = CassandraTimestampBoundStore.create(kv); long limit = timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(limit + ONE_MILLION); invalidator.backupAndInvalidate(); invalidator.revalidateFromBackup(); assertThat(timestampBoundStore.getUpperLimit()).isEqualTo(limit + ONE_MILLION); }
@Test public void ignoresInvalidBackupIfDataAvailable() { timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_3); backupRunner.restoreFromBackup(); assertBoundEquals(TIMESTAMP_3); }
@Test public void backsUpKnownBoundIfExists() { timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_1); backupRunner.backupExistingTimestamp(); backupRunner.restoreFromBackup(); assertBoundEquals(TIMESTAMP_1); }
long limit = ts.getUpperLimit(); Assert.assertEquals(limit, ts2.getUpperLimit()); ts.storeUpperLimit(limit + 10); Assert.assertEquals(limit + 10, ts.getUpperLimit()); Assert.assertEquals(limit + 10, ts2.getUpperLimit()); ts.storeUpperLimit(limit + 20); try { ts2.storeUpperLimit(limit + 20); Assert.fail(); } catch (MultipleRunningTimestampServiceError e) { Assert.assertEquals(limit + 20, ts2.getUpperLimit()); ts.storeUpperLimit(limit + 30); Assert.assertEquals(limit + 30, ts.getUpperLimit()); ts2.storeUpperLimit(limit + 40); Assert.fail(); } catch (MultipleRunningTimestampServiceError e) {
@Test public void stateIsWellDefinedEvenUnderConcurrentBackupsAndRestores() { timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_3); CassandraTestTools.executeInParallelOnExecutorService(() -> { CassandraTimestampBackupRunner runner = new CassandraTimestampBackupRunner(kv); try { if (ThreadLocalRandom.current().nextBoolean()) { runner.backupExistingTimestamp(); } else { runner.restoreFromBackup(); } } catch (IllegalStateException exception) { // This is possible under concurrent backup *and* restore. // The point of this test is to ensure that the table is in a well defined state at the end. } }); backupRunner.restoreFromBackup(); assertThat(timestampBoundStore.getUpperLimit()).isEqualTo(TIMESTAMP_3); }
@Test public void multipleRestoresDoNotMakeUsGoBackInTime() { backupRunner.backupExistingTimestamp(); backupRunner.restoreFromBackup(); timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_2); backupRunner.restoreFromBackup(); assertBoundEquals(TIMESTAMP_2); // in particular, not TIMESTAMP_1 }
@Test public void canBackupAndRestoreMultipleTimes() { timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_1); backupRunner.backupExistingTimestamp(); assertBoundNotReadable(); backupRunner.restoreFromBackup(); assertBoundEquals(TIMESTAMP_1); timestampBoundStore.getUpperLimit(); timestampBoundStore.storeUpperLimit(TIMESTAMP_2); backupRunner.backupExistingTimestamp(); assertBoundNotReadable(); backupRunner.restoreFromBackup(); assertBoundEquals(TIMESTAMP_2); }
private void storeUpperLimit(long upperLimit) { DebugLogger.willStoreNewUpperLimit(upperLimit); store.storeUpperLimit(upperLimit); DebugLogger.didStoreNewUpperLimit(upperLimit); }
@Override public synchronized void storeUpperLimit(long limit) { failures.verifyWeShouldIssueMoreTimestamps(); throwIfInterrupted(); try { delegate.storeUpperLimit(limit); } catch (Throwable t) { throw failures.responseTo(t); } }
@Test public void testTimestampBoundStore() { long upperLimit1 = store.getUpperLimit(); long upperLimit2 = store.getUpperLimit(); Assert.assertEquals(upperLimit1, upperLimit2); store.storeUpperLimit(upperLimit2 + 1); long upperLimit3 = store.getUpperLimit(); Assert.assertEquals(upperLimit3, upperLimit2 + 1); } }