@Before public void setUp() { this.factory = new InMemoryCacheFactory(); }
@After public void tearDown() { if (this.factory != null) { this.factory.close(); this.factory = null; } }
@Override protected Cache createCache(String cacheId) { return this.factory.getCache(cacheId); } }
TestContext() { this.cacheFactory = new InMemoryCacheFactory(); this.cacheManager = new CacheManager(CachePolicy.INFINITE, executorService()); this.segment = new SegmentMock(executorService()); this.index = new ContainerKeyIndex(CONTAINER_ID, this.cacheFactory, this.cacheManager, executorService()); this.timer = new TimeoutTimer(TIMEOUT); this.random = new Random(0); }
@Override public void close() { this.index.close(); this.cacheManager.close(); this.cacheFactory.close(); } }
TestContext(KeyHasher hasher) { this.hasher = hasher; this.container = new MockSegmentContainer(() -> new SegmentMock(createSegmentMetadata(), executorService())); this.cacheFactory = new InMemoryCacheFactory(); this.cacheManager = new CacheManager(CachePolicy.INFINITE, executorService()); this.ext = createExtension(); this.random = new Random(0); }
@Override public void close() { this.ext.close(); this.cacheManager.close(); this.cacheFactory.close(); this.container.close(); }
/** * Tests the {@link ContainerKeyCache#includeUpdateBatch} method for inserts. */ @Test public void testBatchInsert() { @Cleanup val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory); val rnd = new Random(0); val expectedResult = new HashMap<TestKey, CacheBucketOffset>(); long highestOffset = batchInsert(0L, keyCache, expectedResult, rnd); checkCache(expectedResult, keyCache); // Update all Segment Index Offsets to the max value, which should trigger a migration from the tail cache to // the index cache. updateSegmentIndexOffsets(keyCache, highestOffset); checkNoTailHashes(keyCache); checkCache(expectedResult, keyCache); }
@Override public void close() { this.index.close(); this.cacheManager.close(); this.cacheFactory.close(); this.storage.close(); this.memoryStorage.close(); }
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); }
final long segmentId = 1L; @Cleanup val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory);
public void testIncludeExistingKey() { @Cleanup val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory);
public void testBatchRemove() { @Cleanup val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory);
public void testBatchUpdate() { @Cleanup val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory);
val cacheFactory = new InMemoryCacheFactory(); @Cleanup val keyCache = new ContainerKeyCache(CONTAINER_ID, cacheFactory);
/** * 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())); }
InMemoryCacheFactory cacheFactory = new InMemoryCacheFactory(); @Cleanup CacheManager cacheManager = new CacheManager(CachePolicy.INFINITE, executorService());
TestContext(AttributeIndexConfig config, CachePolicy cachePolicy) { this.memoryStorage = new InMemoryStorage(); this.memoryStorage.initialize(1); this.storage = new TestContext.TestStorage(new RollingStorage(this.memoryStorage, config.getAttributeSegmentRollingPolicy()), executorService()); this.containerMetadata = new MetadataBuilder(CONTAINER_ID).build(); this.cacheFactory = new InMemoryCacheFactory(); this.cacheManager = new TestCacheManager(cachePolicy, executorService()); val factory = new ContainerAttributeIndexFactoryImpl(config, this.cacheFactory, this.cacheManager, executorService()); this.index = factory.createContainerAttributeIndex(this.containerMetadata, this.storage); }
InMemoryCacheFactory cacheFactory = new InMemoryCacheFactory(); @Cleanup CacheManager cacheManager = new CacheManager(CachePolicy.INFINITE, executorService());
TestContext() { this.cacheFactory = new InMemoryCacheFactory(); this.storage = InMemoryStorageFactory.newStorage(executorService()); this.storage.initialize(1); this.metadata = new MetadataBuilder(CONTAINER_ID).build(); ReadIndexConfig readIndexConfig = ReadIndexConfig.builder().with(ReadIndexConfig.STORAGE_READ_ALIGNMENT, 1024).build(); this.cacheManager = new CacheManager(CachePolicy.INFINITE, executorService()); this.readIndex = new ContainerReadIndex(readIndexConfig, this.metadata, this.cacheFactory, this.storage, this.cacheManager, executorService()); this.memoryLog = new SequencedItemList<>(); this.stateUpdater = new MemoryStateUpdater(this.memoryLog, this.readIndex, Runnables.doNothing()); }