static Properties loadConfig(String cfgPath) throws IOException { String extension = FilenameUtils.getExtension(cfgPath); Properties props; if ("config".equals(extension)){ props = loadAndTransformProps(cfgPath); } else { props = new Properties(); try(InputStream is = FileUtils.openInputStream(new File(cfgPath))){ props.load(is); } } return props; }
if (bsType == Type.S3){ S3DataStore s3ds = new S3DataStore(); Properties props = loadConfig(bsopts.getS3ConfigPath()); s3ds.setProperties(props); File homeDir = Files.createTempDir(); closer.register(asCloseable(homeDir)); populate(s3ds, asMap(props), false); s3ds.init(homeDir.getAbsolutePath()); delegate = s3ds; AzureDataStore azureds = new AzureDataStore(); String cfgPath = bsopts.getAzureConfigPath(); Properties props = loadConfig(cfgPath); azureds.setProperties(props); File homeDir = Files.createTempDir(); populate(azureds, asMap(props), false); azureds.init(homeDir.getAbsolutePath()); closer.register(asCloseable(homeDir)); delegate = azureds; } else if (bsType == Type.FAKE) { } else { String cfgPath = bsopts.getFDSConfigPath(); Properties props = loadAndTransformProps(cfgPath); populate(delegate, asMap(props), true);
@Test public void fileDataStore() throws Exception{ String[] args = {"--fds-path", temporaryFolder.getRoot().getAbsolutePath(), "--read-write"}; try (BlobStoreFixture fixture = BlobStoreFixtureProvider.create(createFDSOptions(args))){ String blobId = fixture.getBlobStore().writeBlob(new ByteArrayInputStream("foo".getBytes())); assertNotNull(blobId); } }
@Test public void configLoading() throws Exception { Properties p = new Properties(); p.put("foo", "bar"); p.put("a", "b"); File config = new File(temporaryFolder.getRoot(), "test.cfg"); try (OutputStream os = FileUtils.openOutputStream(config)) { p.store(os, null); } Properties p2 = BlobStoreFixtureProvider.loadConfig(config.getAbsolutePath()); assertEquals("bar", p2.getProperty("foo")); }
if (bsType == Type.S3){ S3DataStore s3ds = new S3DataStore(); Properties props = loadConfig(bsopts.getS3ConfigPath()); s3ds.setProperties(props); File homeDir = Files.createTempDir(); closer.register(asCloseable(homeDir)); populate(s3ds, asMap(props), false); s3ds.init(homeDir.getAbsolutePath()); delegate = s3ds; AzureDataStore azureds = new AzureDataStore(); String cfgPath = bsopts.getAzureConfigPath(); Properties props = loadConfig(cfgPath); azureds.setProperties(props); File homeDir = Files.createTempDir(); populate(azureds, asMap(props), false); azureds.init(homeDir.getAbsolutePath()); closer.register(asCloseable(homeDir)); delegate = azureds; } else if (bsType == Type.FAKE) { } else { String cfgPath = bsopts.getFDSConfigPath(); Properties props = loadAndTransformProps(cfgPath); populate(delegate, asMap(props), true);
@Test public void readOnlyFileDataStore() throws Exception{ String[] args = {"--fds-path", temporaryFolder.getRoot().getAbsolutePath()}; try (BlobStoreFixture fixture = BlobStoreFixtureProvider.create(createFDSOptions(args))){ try { BlobStore blobStore = fixture.getBlobStore(); assertThat(blobStore, instanceOf(GarbageCollectableBlobStore.class)); assertThat(blobStore, instanceOf(TypedDataStore.class)); assertThat(blobStore, instanceOf(BlobTrackingStore.class)); fixture.getBlobStore().writeBlob(new ByteArrayInputStream("foo".getBytes())); fail(); } catch (Exception ignore) { } } }
@Test public void configLoading_OSGi() throws Exception { Dictionary<String, Object> p = new Hashtable<String, Object>(); p.put("foo", "bar"); p.put("a", 1); p.put("b", new int[]{1, 2}); File config = new File(temporaryFolder.getRoot(), "test.config"); try (OutputStream os = FileUtils.openOutputStream(config)) { ConfigurationHandler.write(os, p); } Properties p2 = BlobStoreFixtureProvider.loadConfig(config.getAbsolutePath()); assertEquals("bar", p2.getProperty("foo")); assertEquals(1, p2.get("a")); assertArrayEquals(new int[]{1, 2}, (int[]) p2.get("b")); }
Closer closer = Closer.create(); Whiteboard wb = new ClosingWhiteboard(options.getWhiteboard(), closer); BlobStoreFixture blobFixture = BlobStoreFixtureProvider.create(options); BlobStore blobStore = null; if (blobFixture != null) {
static Properties loadConfig(String cfgPath) throws IOException { String extension = FilenameUtils.getExtension(cfgPath); Properties props; if ("config".equals(extension)){ props = loadAndTransformProps(cfgPath); } else { props = new Properties(); try(InputStream is = FileUtils.openInputStream(new File(cfgPath))){ props.load(is); } } return props; }
Closer closer = Closer.create(); Whiteboard wb = new ClosingWhiteboard(options.getWhiteboard(), closer); BlobStoreFixture blobFixture = BlobStoreFixtureProvider.create(options); BlobStore blobStore = null; if (blobFixture != null) {