@Override protected Collection<? extends BlobStoreInfo> getInfos(BlobStoreConfiguration config) throws Exception { return config.getBlobStores(); }
/** * Adds a blob store and returns the {@link BlobStoreConfiguration} to which the blob stores was * added. * * @param bs the blob store to add * @throws IllegalArgumentException if the given blob store can't be added to any configuration * managed by this blob store aggregator. */ public synchronized void addBlobStore(final BlobStoreInfo bs) throws IllegalArgumentException { for (BlobStoreConfiguration c : getConfigs()) { if (c.canSave(bs)) { c.addBlobStore(bs); return; } } throw new IllegalArgumentException("No configuration found capable of saving " + bs); }
/** * Adds a {@link BlobStoreConfigurationListener} to each {@link BlobStoreConfiguration} tracked * by this aggregator * * @param listener the listener */ public void addListener(BlobStoreConfigurationListener listener) { for (BlobStoreConfiguration c : getConfigs()) { c.addBlobStoreListener(listener); } }
/** * Finds out which {@link BlobStoreConfiguration} contains the given blob store, removes it, and * saves the configuration. * * @param blobStoreName the name of the blob store to remove * @return true if the blob store was removed, false if it was not found. */ public synchronized void removeBlobStore(final String blobStoreName) throws IllegalArgumentException { for (BlobStoreConfiguration config : getConfigs()) { if (config.containsBlobStore(blobStoreName)) { config.removeBlobStore(blobStoreName); return; } } throw new NoSuchElementException( "No configuration found containing blob store " + blobStoreName); } /**
@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 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 testRemoveListener() throws Exception { BlobStoreConfigurationListener listener1 = EasyMock.createMock("listener1", BlobStoreConfigurationListener.class); BlobStoreConfigurationListener listener2 = EasyMock.createMock("listener2", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener1); this.config.addBlobStoreListener(listener2); this.config.removeBlobStoreListener(listener1); BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); listener2.handleAddBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener1, listener2); this.addInfo(this.config, goodInfo); EasyMock.verify(listener1, listener2); }
@Test public void testListenerHearsModify() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); this.addInfo(this.config, goodInfo); BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); listener.handleModifyBlobStore(EasyMock.eq(goodInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.doModifyInfo(goodInfo, 2); this.config.modifyBlobStore(goodInfo); EasyMock.verify(listener); }
@Test public void testListenerHearsRename() throws Exception { BlobStoreInfo goodInfo = this.getGoodInfo("test", 1); BlobStoreInfo expectedInfo = this.getGoodInfo("newName", 1); this.addInfo(this.config, goodInfo); BlobStoreConfigurationListener listener = EasyMock.createMock("listener", BlobStoreConfigurationListener.class); this.config.addBlobStoreListener(listener); listener.handleRenameBlobStore(EasyMock.eq("test"), EasyMock.eq(expectedInfo)); EasyMock.expectLastCall().once(); EasyMock.replay(listener); this.config.renameBlobStore("test", "newName"); EasyMock.verify(listener); }
@Override protected Optional<BlobStoreInfo> getInfo(BlobStoreConfiguration config, String name) throws Exception { return config.getBlobStore(name); }
@Override protected void renameInfo(BlobStoreConfiguration config, String oldName, String newName) throws Exception { config.renameBlobStore(oldName, newName); }
@Override protected void addInfo(BlobStoreConfiguration config, BlobStoreInfo info) throws Exception { config.addBlobStore(info); }
/** * Retrieve a list of all {@link BlobStoreInfo} names for each configuration. * * @return A list of names that can be used to identify each of the {@link BlobStoreInfo}s * currently configured. */ public List<String> getBlobStoreNames() { List<String> names = new ArrayList<>(); for (BlobStoreConfiguration configuration : getConfigs()) { names.addAll(configuration.getBlobStoreNames()); } return names; }
@Override protected void modifyInfo(BlobStoreConfiguration config, BlobStoreInfo info) throws Exception { config.modifyBlobStore(info); }
/** * Removes a {@link BlobStoreConfigurationListener} from each {@link BlobStoreConfiguration} * tracked by this aggregator * * @param listener the listener */ public void removeListener(BlobStoreConfigurationListener listener) { for (BlobStoreConfiguration c : getConfigs()) { c.removeBlobStoreListener(listener); } }
@Override protected void removeInfo(BlobStoreConfiguration config, String name) throws Exception { config.removeBlobStore(name); }
expectLastCall().andThrow(new IOException("Supressing Exception")); control.replay(); config.addBlobStoreListener(listener1); config.addBlobStoreListener(listener2); config.addBlobStore(info1); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(IOException.class)); try { config.modifyBlobStore(info2); } finally { control.verify(); 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()); } }
/** * 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; }
/** * Renames an existing blob store. * * @param oldName The name of the existing blob store * @param newName The name to rename the blob store to * @throws IllegalArgumentException */ public synchronized void renameBlobStore(final String oldName, final String newName) throws NoSuchElementException, IllegalArgumentException { BlobStoreConfiguration config = getConfiguration(oldName); config.renameBlobStore(oldName, newName); // update layers for (TileLayer layer : layers.getLayerList()) { if (oldName.equals(layer.getBlobStoreId())) { layer.setBlobStoreId(newName); layers.modify(layer); } } }