private ServiceBuilder attachDataLogFactory(ServiceBuilder builder) { if (this.config.getBookieCount() > 0) { // We were instructed to start at least one Bookie. this.zkClient = CuratorFrameworkFactory .builder() .connectString("localhost:" + this.config.getZkPort()) .namespace("pravega") .retryPolicy(new ExponentialBackoffRetry(1000, 5)) .sessionTimeoutMs(5000) .connectionTimeoutMs(5000) .build(); this.zkClient.start(); return builder.withDataLogFactory(setup -> { BookKeeperConfig bkConfig = setup.getConfig(BookKeeperConfig::builder); return new BookKeeperLogFactory(bkConfig, this.zkClient, setup.getCoreExecutor()); }); } else { // No Bookies -> InMemory Tier1. return builder.withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor())); } }
@After public void tearDown() { if (this.factory != null) { this.factory.close(); this.factory = null; } }
/** * Creates a new TestDurableDataLog backed by an InMemoryDurableDataLog. * * @param containerId The Id of the container. * @param maxAppendSize The maximum append size for the log. * @param appendDelayMillis The amount of delay, in milliseconds, for each append operation. * @param executorService An executor to use for async operations. * @return The newly created log. */ public static TestDurableDataLog create(int containerId, int maxAppendSize, int appendDelayMillis, ScheduledExecutorService executorService) { try (InMemoryDurableDataLogFactory factory = new InMemoryDurableDataLogFactory(maxAppendSize, executorService)) { if (appendDelayMillis > 0) { Duration delay = Duration.ofMillis(appendDelayMillis); factory.setAppendDelayProvider(() -> delay); } DurableDataLog log = factory.createDurableDataLog(containerId); return create(log); } }
@Override protected DurableDataLog createDurableDataLog() { return this.factory.createDurableDataLog(this.nextContainerId.get()); }
private void attachDataLogFactory(ServiceBuilder builder) { builder.withDataLogFactory(setup -> { switch (this.serviceConfig.getDataLogTypeImplementation()) { case BOOKKEEPER: return new BookKeeperLogFactory(setup.getConfig(BookKeeperConfig::builder), this.zkClient, setup.getCoreExecutor()); case INMEMORY: return new InMemoryDurableDataLogFactory(setup.getCoreExecutor()); default: throw new IllegalStateException("Unsupported storage implementation: " + this.serviceConfig.getDataLogTypeImplementation()); } }); }
@After public void tearDown() { if (this.durableDataLogFactory != null) { this.durableDataLogFactory.close(); this.durableDataLogFactory = null; } if (this.storageFactory != null) { this.storageFactory.close(); this.storageFactory = null; } }
@Before public void setUp() { this.factory = new InMemoryDurableDataLogFactory(executorService()); }
@After public void tearDown() { if (this.durableDataLogFactory != null) { this.durableDataLogFactory.close(); this.durableDataLogFactory = null; } if (this.storageFactory != null) { this.storageFactory.close(); this.storageFactory = null; } }
ContainerSetup(ScheduledExecutorService executorService) { this.dataLog = new AtomicReference<>(); this.executorService = executorService; this.dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, this.executorService), this.dataLog::set); this.metadata = new MetadataBuilder(CONTAINER_ID).build(); this.cacheFactory = new InMemoryCacheFactory(); this.storage = InMemoryStorageFactory.newStorage(executorService); this.storage.initialize(1); this.cacheManager = new CacheManager(CachePolicy.INFINITE, this.executorService); this.readIndex = new ContainerReadIndex(DEFAULT_READ_INDEX_CONFIG, metadata, this.cacheFactory, this.storage, this.cacheManager, this.executorService); }
/** * Creates a new instance of the ServiceBuilder class which is contained in memory. Any data added to this service will * be lost when the object is garbage collected or the process terminates. * * @param builderConfig The ServiceBuilderConfig to use. * @param executorBuilder A Function that, given a thread count and a pool name, creates a ScheduledExecutorService * with the given number of threads that have the given name as prefix. */ @VisibleForTesting public static ServiceBuilder newInMemoryBuilder(ServiceBuilderConfig builderConfig, ExecutorBuilder executorBuilder) { ServiceConfig serviceConfig = builderConfig.getConfig(ServiceConfig::builder); ServiceBuilder builder; if (serviceConfig.isReadOnlySegmentStore()) { // Only components required for ReadOnly SegmentStore. builder = new ReadOnlyServiceBuilder(builderConfig, serviceConfig, executorBuilder); } else { // Components that are required for general SegmentStore. builder = new ServiceBuilder(builderConfig, serviceConfig, executorBuilder) .withCacheFactory(setup -> new InMemoryCacheFactory()); } // Components that are required for all types of SegmentStore. return builder .withDataLogFactory(setup -> new InMemoryDurableDataLogFactory(setup.getCoreExecutor())) .withContainerManager(setup -> new LocalSegmentContainerManager( setup.getContainerRegistry(), setup.getSegmentToContainerMapper())) .withStorageFactory(setup -> new InMemoryStorageFactory(setup.getStorageExecutor())) .withStreamSegmentStore(setup -> new StreamSegmentService(setup.getContainerRegistry(), setup.getSegmentToContainerMapper())); }
AtomicReference<Boolean> truncationOccurred = new AtomicReference<>(); @Cleanup TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService()), dataLog::set); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
AtomicReference<Boolean> truncationOccurred = new AtomicReference<>(); @Cleanup TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService()), dataLog::set); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
TestContext(ContainerConfig config, SegmentContainerFactory.CreateExtensions createAdditionalExtensions) { this.storageFactory = new WatchableInMemoryStorageFactory(executorService()); this.dataLogFactory = new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService()); this.operationLogFactory = new DurableLogFactory(DEFAULT_DURABLE_LOG_CONFIG, dataLogFactory, executorService()); this.cacheFactory = new InMemoryCacheFactory(); this.cacheManager = new CacheManager(CachePolicy.INFINITE, executorService()); this.readIndexFactory = new ContainerReadIndexFactory(DEFAULT_READ_INDEX_CONFIG, this.cacheFactory, this.cacheManager, executorService()); this.attributeIndexFactory = new ContainerAttributeIndexFactoryImpl(DEFAULT_ATTRIBUTE_INDEX_CONFIG, this.cacheFactory, this.cacheManager, executorService()); this.writerFactory = new StorageWriterFactory(DEFAULT_WRITER_CONFIG, executorService()); this.containerFactory = new StreamSegmentContainerFactory(config, this.operationLogFactory, this.readIndexFactory, this.attributeIndexFactory, this.writerFactory, this.storageFactory, createExtensions(createAdditionalExtensions), executorService()); this.container = this.containerFactory.createStreamSegmentContainer(CONTAINER_ID); this.storage = this.storageFactory.createStorageAdapter(); }
TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService())); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService()), dataLog::set); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
AtomicReference<TestDurableDataLog> dataLog = new AtomicReference<>(); @Cleanup TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService()), dataLog::set); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService())); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());
TestDurableDataLogFactory dataLogFactory = new TestDurableDataLogFactory(new InMemoryDurableDataLogFactory(MAX_DATA_LOG_APPEND_SIZE, executorService())); @Cleanup Storage storage = InMemoryStorageFactory.newStorage(executorService());