Search in sources :

Example 11 with StoreConfig

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));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) StoreConfig(com.github.ambry.config.StoreConfig) Test(org.junit.Test)

Example 12 with StoreConfig

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.
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) StoreConfig(com.github.ambry.config.StoreConfig) Test(org.junit.Test)

Example 13 with StoreConfig

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();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) StoreConfig(com.github.ambry.config.StoreConfig) Test(org.junit.Test)

Example 14 with StoreConfig

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());
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ArrayList(java.util.ArrayList) MockTime(com.github.ambry.utils.MockTime) Time(com.github.ambry.utils.Time) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) StoreConfig(com.github.ambry.config.StoreConfig) MockTime(com.github.ambry.utils.MockTime) Pair(com.github.ambry.utils.Pair) Test(org.junit.Test)

Example 15 with StoreConfig

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) StoreConfig(com.github.ambry.config.StoreConfig) Pair(com.github.ambry.utils.Pair)

Aggregations

StoreConfig (com.github.ambry.config.StoreConfig)60 VerifiableProperties (com.github.ambry.config.VerifiableProperties)50 MetricRegistry (com.codahale.metrics.MetricRegistry)34 Test (org.junit.Test)29 File (java.io.File)18 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)17 ArrayList (java.util.ArrayList)15 Properties (java.util.Properties)15 ClusterMap (com.github.ambry.clustermap.ClusterMap)10 BlobIdFactory (com.github.ambry.commons.BlobIdFactory)9 InMemAccountService (com.github.ambry.account.InMemAccountService)8 DataNodeId (com.github.ambry.clustermap.DataNodeId)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 MockTime (com.github.ambry.utils.MockTime)7 HashSet (java.util.HashSet)7 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)6 ReplicaId (com.github.ambry.clustermap.ReplicaId)6 ReplicaStatusDelegate (com.github.ambry.clustermap.ReplicaStatusDelegate)6 DiskManagerConfig (com.github.ambry.config.DiskManagerConfig)6 ReplicationConfig (com.github.ambry.config.ReplicationConfig)6