SegmentFactory segmentFactory = new MappedSegmentFactory();
/**
* DynamicArrayStore only grows its capacity/length after the store has been created.
*/
ArrayStore store = StoreFactory.createDynamicArrayStore(
homeDir,
initialLength,
segmentFileSizeMB,
segmentFactory);
assertEquals(initialLength, store.length());
assertEquals(initialLength, store.capacity());
assertEquals(0, store.getIndexStart());
store.clear();
store.close();
// Smaller length has no impact
int smallerLength = initialLength - 500;
store = StoreFactory.createDynamicArrayStore(
homeDir,
smallerLength,
batchSize,
numSyncBatches,
segmentFileSizeMB,
segmentFactory);
assertEquals(initialLength, store.length());
assertEquals(initialLength, store.capacity());
assertEquals(0, store.getIndexStart());
store.clear();
store.close();
// Larger length caused the store to grow capacity
int largerLength = initialLength + 500;
int expectedLength = initialLength + DynamicConstants.SUB_ARRAY_SIZE;
store = StoreFactory.createDynamicArrayStore(
homeDir,
largerLength,
batchSize,
numSyncBatches,
segmentFileSizeMB,
segmentFactory,
segmentCompactFactor);
assertEquals(expectedLength, store.length());
assertEquals(expectedLength, store.capacity());
assertEquals(0, store.getIndexStart());
store.clear();
store.close();
// Use StoreConfig
StoreConfig config = new StoreConfig(homeDir, initialLength);
config.setBatchSize(batchSize);
config.setNumSyncBatches(numSyncBatches);
config.setSegmentFileSizeMB(segmentFileSizeMB);
config.setSegmentFactory(segmentFactory);
config.setSegmentCompactFactor(segmentCompactFactor);
store = StoreFactory.createDynamicArrayStore(config);
assertEquals(expectedLength, store.length());
assertEquals(expectedLength, store.capacity());
assertEquals(0, store.getIndexStart());
store.clear();
store.close();
FileUtils.deleteDirectory(homeDir);
}