use of io.pravega.segmentstore.storage.noop.NoOpStorageFactory in project pravega by pravega.
the class StorageLoader method load.
public StorageFactory load(ConfigSetup setup, String storageImplementation, StorageLayoutType storageLayoutType, ScheduledExecutorService executor) {
ServiceLoader<StorageFactoryCreator> loader = ServiceLoader.load(StorageFactoryCreator.class);
StorageExtraConfig noOpConfig = setup.getConfig(StorageExtraConfig::builder);
for (StorageFactoryCreator factoryCreator : loader) {
val factories = factoryCreator.getStorageFactories();
for (val factoryInfo : factories) {
log.info("Loading {}, trying {}", storageImplementation, factoryInfo);
if (factoryInfo.getName().equals(storageImplementation) && factoryInfo.getStorageLayoutType() == storageLayoutType) {
StorageFactory factory = factoryCreator.createFactory(factoryInfo, setup, executor);
if (!noOpConfig.isStorageNoOpMode()) {
return factory;
} else {
// The specified storage implementation is in No-Op mode.
log.warn("{} IS IN NO-OP MODE: DATA LOSS WILL HAPPEN! MAKE SURE IT IS BY FULL INTENTION FOR TESTING PURPOSE!", storageImplementation);
return new NoOpStorageFactory(noOpConfig, executor, factory, null);
}
}
}
}
return null;
}
use of io.pravega.segmentstore.storage.noop.NoOpStorageFactory in project pravega by pravega.
the class StorageLoaderTest method testNoOpWithInMemoryStorage.
@Test
public void testNoOpWithInMemoryStorage() throws Exception {
@Cleanup("shutdownNow") ScheduledExecutorService executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
ServiceBuilderConfig.Builder configBuilder = ServiceBuilderConfig.builder().include(StorageExtraConfig.builder().with(StorageExtraConfig.STORAGE_NO_OP_MODE, true)).include(ServiceConfig.builder().with(ServiceConfig.CONTAINER_COUNT, 1).with(ServiceConfig.STORAGE_IMPLEMENTATION, ServiceConfig.StorageType.INMEMORY.name()));
ServiceBuilder builder = ServiceBuilder.newInMemoryBuilder(configBuilder.build()).withStorageFactory(setup -> {
StorageLoader loader = new StorageLoader();
expectedFactory = loader.load(setup, "INMEMORY", StorageLayoutType.ROLLING_STORAGE, executor);
return expectedFactory;
});
builder.initialize();
assertTrue(expectedFactory instanceof NoOpStorageFactory);
builder.close();
configBuilder.include(StorageExtraConfig.builder().with(StorageExtraConfig.STORAGE_NO_OP_MODE, false));
builder = ServiceBuilder.newInMemoryBuilder(configBuilder.build()).withStorageFactory(setup -> {
StorageLoader loader = new StorageLoader();
expectedFactory = loader.load(setup, "INMEMORY", StorageLayoutType.ROLLING_STORAGE, executor);
return expectedFactory;
});
builder.initialize();
assertTrue(expectedFactory instanceof InMemoryStorageFactory);
builder.close();
}
Aggregations