@Override protected BlobStoreInfo getGoodInfo(String id, int rand) throws Exception { FileBlobStoreInfo info = new FileBlobStoreInfo(id); info.setEnabled(false); info.setDefault(false); info.setBaseDirectory("/tmp/defaultCache"); info.setFileSystemBlockSize(rand); return info; }
FileBlobStoreInfo config = new FileBlobStoreInfo(); config.setEnabled(true); config.setDefault(true); config.setBaseDirectory(defaultStorageFinder.getDefaultPath()); BlobStore store; store = new FileBlobStore(config.getBaseDirectory());
@Test public void testCreateInstance() throws StorageException { config.setId("myblobstore"); config.setEnabled(true); File root = tmp.getRoot(); Preconditions.checkState(root.exists() && root.isDirectory()); config.setBaseDirectory(root.getAbsolutePath()); BlobStore store = config.createInstance(layers, lockProvider); assertNotNull(store); } }
FileBlobStoreInfo blobStore = new FileBlobStoreInfo(BLOBSTORE_FILE_DEFAULT); blobStore.setEnabled(false); blobStore.setBaseDirectory("/tmp/defaultCache"); blobStore.setFileSystemBlockSize(4096); null, true); wmsLayer.setBlobStoreId(blobStore.getName()); tileLayerConfiguration.addLayer(wmsLayer);
@Test public void testCreateInstanceNotEnabled() throws StorageException { config.setId("myblobstore"); config.setEnabled(false); ex.expect(IllegalStateException.class); ex.expectMessage("store is not enabled"); config.createInstance(layers, lockProvider); }
@Test public void noStoresDefinedCreatesLegacyDefaultStore() throws Exception { store = create(); assertEquals(1, store.blobStores.size()); LiveStore liveStore = store.blobStores.get(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID); assertNotNull(liveStore); assertTrue(liveStore.config instanceof FileBlobStoreInfo); FileBlobStoreInfo config = (FileBlobStoreInfo) liveStore.config; assertTrue(config.isEnabled()); assertTrue(config.isDefault()); assertEquals(tmpFolder.getRoot().getAbsolutePath(), config.getBaseDirectory()); }
@Test public void testBlobStoreConfigIsLoaded() throws Exception { // get the blobstores from the config (from test resource geowebcache_190.xml) final List<BlobStoreInfo> blobStores = config.getBlobStores(); assertEquals( "Unexpected number of BlobStoreInfo elements configured", 1, blobStores.size()); // get the 1 configured BlobStoreInfo BlobStoreInfo info = blobStores.get(0); assertFalse("Unexpected BlobStoreInfo default setting", info.isDefault()); assertFalse("Unexpected BlobStoreInfo enabled setting", info.isEnabled()); assertTrue( "Unexpected BlobeStoreInfo class type", FileBlobStoreInfo.class.isAssignableFrom(info.getClass())); // cast the info to a FileBlobStoreInfo final FileBlobStoreInfo fileInfo = FileBlobStoreInfo.class.cast(info); assertEquals( "Unexpected FileBlobStoreInfo filesystem block size", 4096, fileInfo.getFileSystemBlockSize()); assertEquals( "Unexpected FileBlobStoreInfo location value", "/tmp/defaultCache", fileInfo.getBaseDirectory()); }
@Override protected BlobStoreInfo getBadInfo(String id, int rand) throws Exception { FileBlobStoreInfo info = new FileBlobStoreInfo(id) { @Override public String getName() { return null; } }; return info; }
/** @see BlobStoreInfo#getLocation() */ @Override public String getLocation() { return getBaseDirectory(); } }
@Test public void testModifySetDefault() throws IOException, GeoWebCacheException { testAdd(); FileBlobStoreInfo info = (FileBlobStoreInfo) blobStoreAggregator.getBlobStore("newFileBlobStore"); info.setDefault(true); blobStoreAggregator.modifyBlobStore(info); assertTrue(compositeBlobStore.blobStores.containsKey("newFileBlobStore")); assertEquals( compositeBlobStore.blobStores.get("newFileBlobStore"), compositeBlobStore.blobStores.get(CompositeBlobStore.DEFAULT_STORE_DEFAULT_ID)); }
@Override public boolean matches(Object item) { return item instanceof FileBlobStoreInfo && (Objects.equals( ((FileBlobStoreInfo) item).getFileSystemBlockSize(), expected)); } };
@Test public void testCreateInstanceNoId() throws StorageException { ex.expect(IllegalStateException.class); ex.expectMessage("id not set"); config.createInstance(layers, lockProvider); }
@Test public void testCreateInstanceIllegalBlockSize() throws StorageException { config.setId("myblobstore"); config.setEnabled(true); config.setFileSystemBlockSize(-2048); config.setBaseDirectory(tmp.getRoot().getAbsolutePath()); ex.expect(IllegalStateException.class); ex.expectMessage("must be a positive integer"); config.createInstance(layers, lockProvider); }
@Test public void testCreateInstanceNoBaseDirectory() throws StorageException { config.setId("myblobstore"); config.setEnabled(true); ex.expect(IllegalStateException.class); ex.expectMessage("baseDirectory not provided"); config.createInstance(layers, lockProvider); }
@Before public void before() { config = new FileBlobStoreInfo(); layers = mock(TileLayerDispatcher.class); lockProvider = mock(LockProvider.class); }
private FileBlobStoreInfo config( String id, boolean isDefault, boolean isEnabled, String baseDirectory, int fileSystemBlockSize) { FileBlobStoreInfo c = new FileBlobStoreInfo(id); c.setDefault(isDefault); c.setEnabled(isEnabled); c.setBaseDirectory(baseDirectory); c.setFileSystemBlockSize(fileSystemBlockSize); return c; }
/** @see BlobStoreInfo#createInstance(TileLayerDispatcher, LockProvider) */ @Override public BlobStore createInstance(TileLayerDispatcher layers, LockProvider lockProvider) throws StorageException { checkState(getName() != null, "id not set"); checkState( isEnabled(), "Can't call FileBlobStoreConfig.createInstance() is blob store is not enabled"); checkState(baseDirectory != null, "baseDirectory not provided"); checkState( fileSystemBlockSize >= 0, "fileSystemBlockSize must be a positive integer: %s", fileSystemBlockSize); FileBlobStore fileBlobStore = new FileBlobStore(baseDirectory); if (fileSystemBlockSize > 0) { fileBlobStore.setBlockSize(fileSystemBlockSize); } return fileBlobStore; }
private FileBlobStoreInfo createInfo( String id, boolean isDefault, boolean isEnabled, String baseDirectory, int fileSystemBlockSize) { FileBlobStoreInfo c = new FileBlobStoreInfo(id); c.setDefault(isDefault); c.setEnabled(isEnabled); c.setBaseDirectory(baseDirectory); c.setFileSystemBlockSize(fileSystemBlockSize); return c; }
@Test public void testSaveBlobStores() throws Exception { FileBlobStoreInfo store1 = new FileBlobStoreInfo(); store1.setName("store1"); store1.setDefault(true); store1.setEnabled(true); store1.setFileSystemBlockSize(8096); store1.setBaseDirectory("/tmp/test"); FileBlobStoreInfo store2 = new FileBlobStoreInfo(); store2.setName("store2"); store2.setDefault(false); store2.setEnabled(false); store2.setFileSystemBlockSize(512); store2.setBaseDirectory("/tmp/test2");