@Override protected void addInfo(BlobStoreConfiguration config, BlobStoreInfo info) throws Exception { config.addBlobStore(info); }
@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))); } }
/** * 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); }
@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()); } }
blobStore.setFileSystemBlockSize(4096); blobStoreConfiguration.addBlobStore(blobStore);
config.addBlobStoreListener(listener1); config.addBlobStoreListener(listener2); config.addBlobStore(info1); exception.expect(instanceOf(ConfigurationPersistenceException.class)); exception.expectCause(instanceOf(IOException.class));