OnDiskSnapshotsStore implements SnapshotsStore { public List<SnapshotMetadata> getAllSnapshotsFromLatestToOldest() throws StorageException { checkInitialized(); return getMatchingOrderedSnapshots(MATCH_EVERYTHING_PREDICATE); } OnDiskSnapshotsStore(DBI dbi, String snapshotsDirectory); void initialize(); void teardown(); @Override ExtendedSnapshotWriter newSnapshotWriter(); @SuppressWarnings("ConstantConditions") @Override void storeSnapshot(ExtendedSnapshotWriter snapshotWriter); @Override @Nullable ExtendedSnapshot getLatestSnapshot(); List<SnapshotMetadata> getAllSnapshotsFromLatestToOldest(); void pruneSnapshots(final int numSnapshotsToKeep); void reconcileSnapshots();  }
@Test public void shouldReturnSnapshotsInDescendingTimestampOrder() throws InterruptedException, StorageException, IOException { int numSnapshots = 20; createSnapshots(numSnapshots); List<SnapshotMetadata> snapshots = snapshotsStore.getAllSnapshotsFromLatestToOldest(); assertThat(snapshots, hasSize(numSnapshots)); checkSnapshotsExistOnFilesystem(snapshots); long prevTimestamp = Long.MAX_VALUE; for (SnapshotMetadata metadata : snapshots) { assertThat(prevTimestamp, greaterThan(metadata.getTimestamp())); prevTimestamp = metadata.getTimestamp(); } }
@Test public void shouldReturnEmptyListWhenNoSnapshotsExist() throws InterruptedException, StorageException, IOException { List<SnapshotMetadata> snapshots = snapshotsStore.getAllSnapshotsFromLatestToOldest(); assertThat(snapshots, empty()); }
@Test public void shouldThrowStorageExceptionIfDatabaseCallFailsInCallToGetAllSnapshots() throws Exception { throwWhenDAOMethodCalled(new SnapshotStoreMethodCallable() { @Override public void setup(OnDiskSnapshotsStore onDiskSnapshotsStore, SnapshotsDAO mockDAO, Throwable toThrow) throws Exception { when(mockDAO.getAllSnapshotsFromLatestToOldest()).thenThrow(toThrow); } @Override public void runThrowingMethod(OnDiskSnapshotsStore onDiskSnapshotsStore) throws Exception { onDiskSnapshotsStore.getAllSnapshotsFromLatestToOldest(); } }); }
@Test public void shouldThrowStorageExceptionIfExceptionThrownInCallToGetAllSnapshots() throws Exception { throwOnDBIOpen(new SnapshotStoreMethodSimpleCallable() { @Override public void setup(OnDiskSnapshotsStore onDiskSnapshotsStore) throws Exception { } @Override public void runThrowingMethod(OnDiskSnapshotsStore onDiskSnapshotsStore) throws Exception { onDiskSnapshotsStore.getAllSnapshotsFromLatestToOldest(); } }); }