@Test public void shouldThrowStorageExceptionIfExceptionThrownInCallToInitialize() { DBI brokenDBI = mock(DBI.class); OnDiskSnapshotsStore brokenSnapshotStore = new OnDiskSnapshotsStore(brokenDBI, snapshotsDirectory.getAbsolutePath()); IllegalArgumentException failure = new IllegalArgumentException("failed!"); when(brokenDBI.open()).thenThrow(failure); when(brokenDBI.withHandle(any(HandleCallback.class))).thenCallRealMethod(); boolean exceptionThrown = false; try { brokenSnapshotStore.initialize(); } catch (StorageException e) { exceptionThrown = true; assertThat(e.getCause(), Matchers.<Throwable>sameInstance(failure)); } assertThat(exceptionThrown, is(true)); }
public void initialize() throws StorageException { checkState(!initialized, "store already initialized"); try { dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { SnapshotsDAO dao = handle.attach(SnapshotsDAO.class); dao.createSnapshotsTableWithIndex(); return null; } }); initialized = true; } catch (CallbackFailedException e) { throw new StorageException("fail create snapshots table", e.getCause()); } catch (Exception e) { throw new StorageException("fail create snapshots table", e); } }
OnDiskSnapshotsStore implements SnapshotsStore { public void initialize() throws StorageException { checkState(!initialized, "store already initialized"); try { dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { SnapshotsDAO dao = handle.attach(SnapshotsDAO.class); dao.createSnapshotsTableWithIndex(); return null; } }); initialized = true; } catch (CallbackFailedException e) { throw new StorageException("fail create snapshots table", e.getCause()); } catch (Exception e) { throw new StorageException("fail create snapshots table", e); } } }
OnDiskSnapshotsStore implements SnapshotsStore { public void initialize() throws StorageException { checkState(!initialized, "store already initialized"); try { dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { SnapshotsDAO dao = handle.attach(SnapshotsDAO.class); dao.createSnapshotsTableWithIndex(); return null; } }); initialized = true; } catch (CallbackFailedException e) { throw new StorageException("fail create snapshots table", e.getCause()); } catch (Exception e) { throw new StorageException("fail create snapshots table", e); } } OnDiskSnapshotsStore(DBI dbi, String snapshotsDirectory); }
OnDiskSnapshotsStore implements SnapshotsStore { public void initialize() throws StorageException { checkState(!initialized, "store already initialized"); try { dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { SnapshotsDAO dao = handle.attach(SnapshotsDAO.class); dao.createSnapshotsTableWithIndex(); return null; } }); initialized = true; } catch (CallbackFailedException e) { throw new StorageException("fail create snapshots table", e.getCause()); } catch (Exception e) { throw new StorageException("fail create snapshots table", e); } } 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(); }
OnDiskSnapshotsStore implements SnapshotsStore { public void initialize() throws StorageException { checkState(!initialized, "store already initialized"); try { dbi.withHandle(new HandleCallback<Void>() { @Override public Void withHandle(Handle handle) throws Exception { SnapshotsDAO dao = handle.attach(SnapshotsDAO.class); dao.createSnapshotsTableWithIndex(); return null; } }); initialized = true; } catch (CallbackFailedException e) { throw new StorageException("fail create snapshots table", e.getCause()); } catch (Exception e) { throw new StorageException("fail create snapshots table", e); } } 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();  }