private void createFromSavedConfig(BlobStoreConfiguration configLoad) throws StorageException { List<BlobStoreInfo> blobStores2 = configLoad.getBlobStores(); for (BlobStoreInfo blobStoreConfig : blobStores2) { LockProvider lockProvider = new NoOpLockProvider(); blobStoreConfig.createInstance(dispatch, lockProvider); } }
@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()); }
@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()); }
@Test public void testSuitabilityOnStartup() throws Exception { // Default to EXISTING assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); 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 -> { // When this gets called we should be skipping suitability checks assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.NONE)); return subStore; }); configs.add(info); store = create(); verify(info).createInstance(Mockito.any(), Mockito.any()); // Should be back to default after startup. assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EXISTING)); }
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 testNonDefaultSuitabilityOnStartup() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(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 -> { // When this gets called we should be skipping suitability checks assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.NONE)); return subStore; }); configs.add(info); store = create(); verify(info).createInstance(Mockito.any(), Mockito.any()); // Should be back to default after startup. assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); }
store = config.createInstance(layers, lockProvider);