CompositeBlobStore.checkSuitability(rootPath, exists, empty);
public static void checkSuitability(String location, final boolean exists, boolean empty) throws UnsuitableStorageException { switch (CompositeBlobStore.getStoreSuitabilityCheck()) { case EXISTING: if (exists) { break; } case EMPTY: if (!empty) { throw new UnsuitableStorageException( "Attempted to create Blob Store in " + location + " but it was not empty"); } case NONE: } } }
private CompositeBlobStore create() throws StorageException, ConfigurationException { return new CompositeBlobStore(layers, defaultStorageFinder, configuration, bsa); }
@Override public void handleAddBlobStore(BlobStoreInfo newBlobStore) throws ConfigurationException, StorageException { if (newBlobStore.isDefault()) { loadBlobStoreOverwritingDefault(blobStores, newBlobStore); } else { loadBlobStore(blobStores, newBlobStore); } }
@Test public void testSuitabilityOnAdd() throws Exception { final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); return subStore; }); store = create(); store.handleAddBlobStore(info); verify(info).createInstance(Mockito.any(), Mockito.any()); }
loadBlobStore(stores, config); destroy(stores); throw e;
@Test public void getTileDefaultsToDefaultBlobStore() throws Exception { store = create(); LiveStore liveStore = store.blobStores.get(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID); liveStore.liveInstance = spy(liveStore.liveInstance); when(defaultLayer.getBlobStoreId()).thenReturn(null); TileObject tile = queryTile(0, 0, 0); store.get(tile); verify(liveStore.liveInstance).get(tile); }
@Override public synchronized void destroy() { destroy(blobStores); }
/** * @throws StorageException if the blobstore is not enabled or does not exist * @throws GeoWebCacheException if the layer is not found */ private LiveStore forLayer(String layerName) throws StorageException, GeoWebCacheException { TileLayer layer; try { layer = layers.getTileLayer(layerName); } catch (GeoWebCacheException e) { throw e; } String storeId = layer.getBlobStoreId(); LiveStore store; if (null == storeId) { store = defaultStore(); } else { store = blobStores.get(storeId); } if (store == null) { throw new StorageException("No BlobStore with id '" + storeId + "' found"); } return store; }
try { stores.remove(DEFAULT_STORE_DEFAULT_ID); loadBlobStore(stores, config);
private BlobStore store(String layerId) throws StorageException { LiveStore store; try { store = forLayer(layerId); } catch (GeoWebCacheException e) { throw new StorageException(e.getMessage(), e); } if (!store.config.isEnabled()) { throw new StorageException( "Attempted to use a blob store that's disabled: " + store.config.getName()); } return store.liveInstance; }
@Test public void testNonDefaultSuitabilityOnAdd() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); return subStore; }); store = create(); store.handleAddBlobStore(info); verify(info).createInstance(Mockito.any(), Mockito.any()); }
loadBlobStore(blobStores, modifiedBlobStore); } catch (StorageException | ConfigurationException e) { blobStores.get(DEFAULT_STORE_DEFAULT_ID).config = oldConfig; loadBlobStoreOverwritingDefault(blobStores, modifiedBlobStore); loadBlobStore(blobStores, modifiedBlobStore);
@Test public void getTileInvalidLayer() throws Exception { store = create(); LiveStore liveStore = store.blobStores.get(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID); liveStore.liveInstance = spy(liveStore.liveInstance); when(defaultLayer.getBlobStoreId()).thenReturn(null); TileObject tile = queryTile("someLayer", DEFAULT_GRIDSET, DEFAULT_FORMAT, 0, 0, 0); ex.expect(StorageException.class); ex.expectMessage("layer not found"); store.get(tile); }
CompositeBlobStore.checkSuitability(configuration.getRootDirectory(), exists, empty);
/** * Throws UnsuitableStorageException if the specified storage does not meet the current * suitability check level * * @param location Location of the storage for heuman readable error messages * @param exists The storage is already a GWC cache * @param empty The storage is empty * @throws UnsuitableStorageException */ public static void checkSuitability(String location, final boolean exists, boolean empty) throws UnsuitableStorageException { switch (getStoreSuitabilityCheck()) { case EXISTING: if (exists) { break; } case EMPTY: if (!empty) { throw new UnsuitableStorageException( "Attempted to create Blob Store in " + location + " but it was not empty"); } case NONE: } } }
@Override public void handleModifyBlobStore(BlobStoreInfo modifiedBlobStore) throws ConfigurationException, StorageException { LiveStore removedStore = blobStores.remove(modifiedBlobStore.getName()); try { if (modifiedBlobStore.isDefault() && !modifiedBlobStore .getName() .equals(blobStores.get(DEFAULT_STORE_DEFAULT_ID).config.getName())) { loadBlobStoreOverwritingDefault(blobStores, modifiedBlobStore); } else { loadBlobStore(blobStores, modifiedBlobStore); } } catch (StorageException | ConfigurationException e) { blobStores.put(modifiedBlobStore.getName(), removedStore); throw e; } }
@Test public void getTileInvalidBlobStore() throws Exception { configs.add(config("default", true, true, tmpFolder.newFolder().getAbsolutePath(), 1024)); store = create(); when(defaultLayer.getBlobStoreId()).thenReturn("nonExistentStore"); ex.expect(StorageException.class); ex.expectMessage("No BlobStore with id 'nonExistentStore' found"); store.get(queryTile(0, 0, 0)); }
@Override @Before public void setUpTest() throws Exception { super.setUpTest(); compositeBlobStore = new CompositeBlobStore( tileLayerDispatcher, new DefaultStorageFinder(context.getContextProvider()), testSupport.getServerConfiguration(), blobStoreAggregator); }
CompositeBlobStore.checkSuitability(configuration.getRootDirectory(), exists, empty);