@Override protected Optional<BlobStoreInfo> getInfo(BlobStoreConfiguration config, String name) throws Exception { return config.getBlobStore(name); }
/** * Indicates if this configurations contains a {@link BlobStoreInfo) identified by a given name. * @param blobStoreInfoName the name of a {@link BlobStoreInfo} for which existence is desired. * @return True if a {@link BlobStoreInfo} currently exists with the unique name provided, false otherwise. */ public boolean blobStoreExists(final String blobStoreInfoName) { for (BlobStoreConfiguration configuration : getConfigs()) { Optional<BlobStoreInfo> blob = configuration.getBlobStore(blobStoreInfoName); if (blob.isPresent()) { return true; } } return false; }
/** * Returns the blob store info named after the {@code blobStoreName} parameter. * * @throws GeoWebCacheException if no such blob store info exists */ public BlobStoreInfo getBlobStore(final String blobStoreName) throws GeoWebCacheException { Objects.requireNonNull(blobStoreName, "blobStoreName is null"); return getConfigs() .stream() .map(c -> c.getBlobStore(blobStoreName)) .filter(Optional::isPresent) .map(Optional::get) .findFirst() .orElseThrow( () -> new GeoWebCacheException( "Thread " + Thread.currentThread().getId() + " Unknown blob store " + blobStoreName + ". Check the logfiles," + " it may not have loaded properly.")); }
@Test public void testRollBackOnUnsuitableStorageExceptionInAddHandler() throws Exception { BlobStoreInfo info = getGoodInfo("test", 1); BlobStoreConfigurationListener listener = createMock(BlobStoreConfigurationListener.class); listener.handleAddBlobStore(info); expectLastCall().andThrow(new UnsuitableStorageException("TEST")); EasyMock.replay(listener); config.addBlobStoreListener(listener); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(UnsuitableStorageException.class)); try { config.addBlobStore(info); } finally { verify(listener); assertThat(config.getBlobStore("test"), notPresent()); } }
@Test public void testRollBackOnUnsuitableStorageExceptionInModifyHandler() throws Exception { BlobStoreInfo info1 = getGoodInfo("test", 1); BlobStoreInfo info2 = getGoodInfo("test", 2); BlobStoreConfigurationListener listener = createMock(BlobStoreConfigurationListener.class); listener.handleAddBlobStore(info1); expectLastCall(); listener.handleModifyBlobStore(info2); expectLastCall().andThrow(new UnsuitableStorageException("TEST")); EasyMock.replay(listener); config.addBlobStoreListener(listener); config.addBlobStore(info1); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(UnsuitableStorageException.class)); try { config.modifyBlobStore(info2); } finally { verify(listener); assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1))); } }
@Test public void testRollBackOnSupressedUnsuitableStorageExceptionInAddHandler() throws Exception { BlobStoreInfo info1 = getGoodInfo("test", 1); IMocksControl control = EasyMock.createControl(); BlobStoreConfigurationListener listener1 = control.createMock(BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = control.createMock(BlobStoreConfigurationListener.class); control.checkOrder(true); listener1.handleAddBlobStore(info1); expectLastCall().andThrow(new UnsuitableStorageException("TEST")); listener2.handleAddBlobStore(info1); expectLastCall().andThrow(new IOException("Supressing Exception")); control.replay(); config.addBlobStoreListener(listener1); config.addBlobStoreListener(listener2); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(IOException.class)); try { config.addBlobStore(info1); } finally { control.verify(); assertThat(config.getBlobStore("test"), notPresent()); } }
} finally { control.verify(); assertThat(config.getBlobStore("test"), isPresent(infoEquals(info1)));