use of com.github.ambry.config.StoreConfig in project ambry by linkedin.
the class CompactionManagerTest method testEnableDisable.
/**
* Tests the enabling and disabling of the {@link CompactionManager} with and without compaction enabled.
*/
@Test
public void testEnableDisable() {
// without compaction enabled.
compactionManager.enable();
// functions should work ok
assertNull("Compaction thread should not be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
assertFalse("Compaction Executor should not be running", compactionManager.isCompactionExecutorRunning());
assertFalse("Compactions should not be scheduled after termination", compactionManager.scheduleNextForCompaction(blobStore));
compactionManager.disable();
compactionManager.awaitTermination();
// with compaction enabled.
properties.setProperty("store.compaction.triggers", ALL_COMPACTION_TRIGGERS);
config = new StoreConfig(new VerifiableProperties(properties));
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
compactionManager = new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
compactionManager.enable();
assertNotNull("Compaction thread should be created", TestUtils.getThreadByThisName(CompactionManager.THREAD_NAME_PREFIX));
compactionManager.disable();
compactionManager.awaitTermination();
assertFalse("Compaction thread should not be running", compactionManager.isCompactionExecutorRunning());
assertFalse("Compactions should not be scheduled after termination", compactionManager.scheduleNextForCompaction(blobStore));
}
use of com.github.ambry.config.StoreConfig in project ambry by linkedin.
the class CompactionManagerTest method testConstructorBadArgs.
/**
* Tests construction failure on bad input.
*/
@Test
public void testConstructorBadArgs() {
properties.setProperty("store.compaction.triggers", "@@BAD_TRIGGER@@");
config = new StoreConfig(new VerifiableProperties(properties));
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
try {
new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
fail("Construction should have failed because one of the trigger values is invalid");
} catch (IllegalArgumentException e) {
// expected. Nothing to do.
}
}
use of com.github.ambry.config.StoreConfig in project ambry by linkedin.
the class CompactionManagerTest method testControlCompactionForBlobStore.
/**
* Tests for cases where compaction is disabled or enabled on a given BlobStore
*/
@Test
public void testControlCompactionForBlobStore() {
// without compaction enabled.
compactionManager.enable();
// Disable compaction on BlobStore when compaction executor is not instantiated
compactionManager.controlCompactionForBlobStore(blobStore, false);
compactionManager.disable();
compactionManager.awaitTermination();
// with compaction enabled.
properties.setProperty("store.compaction.triggers", ALL_COMPACTION_TRIGGERS);
config = new StoreConfig(new VerifiableProperties(properties));
StorageManagerMetrics metrics = new StorageManagerMetrics(new MetricRegistry());
compactionManager = new CompactionManager(MOUNT_PATH, config, Collections.singleton(blobStore), metrics, time);
compactionManager.enable();
compactionManager.controlCompactionForBlobStore(blobStore, false);
assertFalse("BlobStore should not be scheduled after compaction is disabled on it", compactionManager.scheduleNextForCompaction(blobStore));
compactionManager.controlCompactionForBlobStore(blobStore, true);
assertTrue("BlobStore should be scheduled after compaction is enabled on it", compactionManager.scheduleNextForCompaction(blobStore));
compactionManager.disable();
compactionManager.awaitTermination();
}
use of com.github.ambry.config.StoreConfig in project ambry by linkedin.
the class CompactionPolicyFactoryTest method testCompactionPolicyFactory.
/**
* Tests {@link CompactionPolicyFactory}
* @throws Exception
*/
@Test
public void testCompactionPolicyFactory() throws Exception {
List<Pair<String, String>> validCompactionPolicyInfos = new ArrayList<>();
validCompactionPolicyInfos.add(new Pair<>("com.github.ambry.store.StatsBasedCompactionPolicyFactory", "com.github.ambry.store.StatsBasedCompactionPolicy"));
validCompactionPolicyInfos.add(new Pair<>("com.github.ambry.store.CompactAllPolicyFactory", "com.github.ambry.store.CompactAllPolicy"));
for (Pair<String, String> validCompactionPolicyInfo : validCompactionPolicyInfos) {
Properties properties = new Properties();
properties.setProperty("store.compaction.policy.factory", validCompactionPolicyInfo.getFirst());
StoreConfig config = new StoreConfig(new VerifiableProperties(properties));
Time time = new MockTime();
CompactionPolicyFactory compactionPolicyFactory = Utils.getObj(config.storeCompactionPolicyFactory, config, time);
Assert.assertEquals("Did not receive expected CompactionPolicy instance", validCompactionPolicyInfo.getFirst(), compactionPolicyFactory.getClass().getCanonicalName());
CompactionPolicy compactionPolicy = compactionPolicyFactory.getCompactionPolicy();
Assert.assertEquals("Did not receive expected CompactionPolicy instance", validCompactionPolicyInfo.getSecond(), compactionPolicy.getClass().getCanonicalName());
}
}
use of com.github.ambry.config.StoreConfig in project ambry by linkedin.
the class MockBlobStoreStats method initializeBlobStore.
// helper methods
/**
* Initializes {@link BlobStore}
* @param minLogSizeToTriggerCompactionInPercentage Property value to be set for
* {@link StoreConfig#storeMinUsedCapacityToTriggerCompactionInPercentage}
* @param messageRetentionInHours Property value to be set for {@link StoreConfig#storeDeletedMessageRetentionHours
* @throws InterruptedException
*/
static Pair<MockBlobStore, StoreConfig> initializeBlobStore(Properties properties, Time time, int minLogSizeToTriggerCompactionInPercentage, int messageRetentionInHours, long maxBlobSize) throws InterruptedException {
if (minLogSizeToTriggerCompactionInPercentage != -1) {
properties.setProperty("store.min.log.size.to.trigger.compaction.in.percent", String.valueOf(minLogSizeToTriggerCompactionInPercentage));
}
if (messageRetentionInHours != -1) {
properties.setProperty("store.deleted.message.retention.hours", String.valueOf(messageRetentionInHours));
}
StoreConfig config = new StoreConfig(new VerifiableProperties(properties));
time.sleep(10 * TimeUnit.HOURS.toMillis(config.storeDeletedMessageRetentionHours));
MetricRegistry metricRegistry = new MetricRegistry();
StoreMetrics metrics = new StoreMetrics(metricRegistry);
MockBlobStoreStats mockBlobStoreStats = new MockBlobStoreStats(maxBlobSize);
MockBlobStore blobStore = new MockBlobStore(config, metrics, time, CAPACITY_IN_BYTES, SEGMENT_CAPACITY_IN_BYTES, SEGMENT_HEADER_SIZE, DEFAULT_USED_CAPACITY_IN_BYTES, mockBlobStoreStats);
return new Pair<>(blobStore, config);
}
Aggregations