BlobStoreFixtureProvider { @Nullable public static BlobStoreFixture create(Options options) throws Exception{ BlobStoreOptions bsopts = options.getOptionBean(BlobStoreOptions.class); if (bsopts == null){ return null; } Type bsType = bsopts.getBlobStoreType(); if (bsType == Type.NONE){ return null; } Closer closer = Closer.create(); DataStore delegate; 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; } else if(bsType == Type.AZURE){ 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) { FileDataStore fakeDs = new DummyDataStore(); fakeDs.setPath(bsopts.getFakeDataStorePath()); fakeDs.init(null); delegate = fakeDs; } else { FileDataStore fds = new OakFileDataStore(); delegate = fds; if (bsopts.getFDSPath() != null) { fds.setPath(bsopts.getFDSPath()); } else { String cfgPath = bsopts.getFDSConfigPath(); Properties props = loadAndTransformProps(cfgPath); populate(delegate, asMap(props), true); } delegate.init(null); } DataStoreBlobStore blobStore = new DataStoreBlobStore(delegate); return new DataStoreFixture(blobStore, closer, (!options.getCommonOpts().isReadWrite() && !bsopts.isReadWrite())); }  @Nullable static BlobStoreFixture create(Options options);  }
@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 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) { } } }