@Bean public TileLayerDispatcher tileLayerDispatcher() throws GeoWebCacheException { TileLayerDispatcher tileLayerDispatcher = mock(TileLayerDispatcher.class); TileLayer tileLayer = mock(TileLayer.class); when(tileLayer.getBlobStoreId()).thenReturn("mbtiles-store"); when(tileLayerDispatcher.getTileLayer("europe")).thenReturn(tileLayer); return tileLayerDispatcher; }
/** * @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; }
/** * 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); } } }
@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); }
@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); }
@Test public void testRenameBlobStoreChangesLayer() throws GeoWebCacheException { TileLayer layer = tileLayerDispatcher.getLayerList().iterator().next(); BlobStoreInfo blobStore = blobStoreAggregator.getBlobStore(layer.getBlobStoreId()); assertNotNull(blobStore); blobStoreAggregator.renameBlobStore(blobStore.getName(), "foobarbaz"); layer = tileLayerDispatcher.getLayerList().iterator().next(); assertEquals("foobarbaz", layer.getBlobStoreId()); } }
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
private SqliteBlobStore getBlobStoreForLayer(String layerName) throws Exception { // let's find layer associated store String blobStoreId = tileLayerDispatcher.getTileLayer(layerName).getBlobStoreId(); BlobStoreInfo blobStoreConfig = null; for (BlobStoreInfo candidateBlobStoreConfig : blobConfiguration.getBlobStores()) { if (blobStoreId == null) { // we need to find the default configuration if (candidateBlobStoreConfig.isDefault()) { // this is the default configuration, we are done blobStoreConfig = candidateBlobStoreConfig; break; } } if (candidateBlobStoreConfig.getName().equals(blobStoreId)) { // we need to find a specific store by is id blobStoreConfig = candidateBlobStoreConfig; break; } } if (blobStoreConfig == null || !(blobStoreConfig instanceof SqliteInfo)) { // no store found or the store is not an sqlite store return null; } // returning an instance of found store return (SqliteBlobStore) blobStoreConfig.createInstance( tileLayerDispatcher, gwcConfiguration.getLockProvider()); } }
@Test public void getTileDisabledStore() throws Exception { boolean isEnabled = false; configs.add( config("store1", false, isEnabled, tmpFolder.newFolder().getAbsolutePath(), 1024)); store = create(); when(defaultLayer.getBlobStoreId()).thenReturn("store1"); TileObject tile = queryTile(0, 0, 0); ex.expect(StorageException.class); ex.expectMessage("Attempted to use a blob store that's disabled"); store.get(tile); }
@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)); }
assertThat(layer.getBlobStoreId(), is(updatedStoreId));