Search in sources :

Example 1 with PropertiesWriter

use of org.apache.distributedlog.common.config.PropertiesWriter in project bookkeeper by apache.

the class TestDynamicConfigurationFeatureProvider method testReloadFeaturesFromOverlay.

@Test(timeout = 60000)
public void testReloadFeaturesFromOverlay() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    PropertiesWriter overlayWriter = new PropertiesWriter();
    overlayWriter.setProperty("feature_2", "6000");
    overlayWriter.setProperty("feature_4", "6000");
    overlayWriter.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath()).setFileFeatureProviderOverlayConfigPath(overlayWriter.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(6000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("feature_4");
    assertTrue(feature4.isAvailable());
    assertEquals(6000, feature4.availability());
    Feature feature5 = provider.getFeature("unknown_feature");
    assertFalse(feature5.isAvailable());
    assertEquals(0, feature5.availability());
    // dynamic load config
    provider.getFeatureConf().setProperty("feature_1", 3000);
    provider.getFeatureConf().setProperty("feature_2", 7000);
    provider.getFeatureConf().setProperty("feature_3", 8000);
    provider.getFeatureConf().setProperty("feature_4", 9000);
    provider.onReload(provider.getFeatureConf());
    feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(3000, feature1.availability());
    feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(7000, feature2.availability());
    feature3 = provider.getFeature("feature_3");
    assertTrue(feature3.isAvailable());
    assertEquals(8000, feature3.availability());
    feature4 = provider.getFeature("feature_4");
    assertTrue(feature4.isAvailable());
    assertEquals(9000, feature4.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

Example 2 with PropertiesWriter

use of org.apache.distributedlog.common.config.PropertiesWriter in project bookkeeper by apache.

the class TestDynamicConfigurationFactory method testGetDynamicConfigBasics.

@Test(timeout = 60000)
public void testGetDynamicConfigBasics() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    DynamicConfigurationFactory factory = getConfigFactory(writer.getFile());
    Optional<DynamicDistributedLogConfiguration> conf = factory.getDynamicConfiguration(writer.getFile().getPath());
    assertEquals(DistributedLogConfiguration.BKDL_RETENTION_PERIOD_IN_HOURS_DEFAULT, conf.get().getRetentionPeriodHours());
    writer.setProperty(DistributedLogConfiguration.BKDL_RETENTION_PERIOD_IN_HOURS, "1");
    writer.save();
    waitForConfig(conf.get(), 1);
    assertEquals(1, conf.get().getRetentionPeriodHours());
}
Also used : PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Test(org.junit.Test)

Example 3 with PropertiesWriter

use of org.apache.distributedlog.common.config.PropertiesWriter in project bookkeeper by apache.

the class TestDynamicConfigurationFactory method testGetDynamicConfigIsSingleton.

@Test(timeout = 60000)
public void testGetDynamicConfigIsSingleton() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    DynamicConfigurationFactory factory = getConfigFactory(writer.getFile());
    String configPath = writer.getFile().getPath();
    Optional<DynamicDistributedLogConfiguration> conf1 = factory.getDynamicConfiguration(configPath);
    Optional<DynamicDistributedLogConfiguration> conf2 = factory.getDynamicConfiguration(configPath);
    assertEquals(conf1, conf2);
}
Also used : PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Test(org.junit.Test)

Example 4 with PropertiesWriter

use of org.apache.distributedlog.common.config.PropertiesWriter in project bookkeeper by apache.

the class TestDynamicConfigurationFeatureProvider method testLoadFeaturesFromOverlay.

/**
 * {@link https://issues.apache.org/jira/browse/DL-40}.
 */
@DistributedLogAnnotations.FlakyTest
@Ignore
@Test(timeout = 60000)
public void testLoadFeaturesFromOverlay() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    PropertiesWriter overlayWriter = new PropertiesWriter();
    overlayWriter.setProperty("feature_2", "6000");
    overlayWriter.setProperty("feature_4", "6000");
    overlayWriter.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath()).setFileFeatureProviderOverlayConfigPath(overlayWriter.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(6000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("feature_4");
    assertTrue(feature4.isAvailable());
    assertEquals(6000, feature4.availability());
    Feature feature5 = provider.getFeature("unknown_feature");
    assertFalse(feature5.isAvailable());
    assertEquals(0, feature5.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PropertiesWriter

use of org.apache.distributedlog.common.config.PropertiesWriter in project bookkeeper by apache.

the class TestDynamicConfigurationFeatureProvider method testLoadFeaturesFromBase.

@Test(timeout = 60000)
public void testLoadFeaturesFromBase() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty("feature_1", "10000");
    writer.setProperty("feature_2", "5000");
    writer.save();
    DistributedLogConfiguration conf = new DistributedLogConfiguration().setDynamicConfigReloadIntervalSec(Integer.MAX_VALUE).setFileFeatureProviderBaseConfigPath(writer.getFile().toURI().toURL().getPath());
    DynamicConfigurationFeatureProvider provider = new DynamicConfigurationFeatureProvider("", conf, NullStatsLogger.INSTANCE);
    provider.start();
    ensureConfigReloaded();
    Feature feature1 = provider.getFeature("feature_1");
    assertTrue(feature1.isAvailable());
    assertEquals(10000, feature1.availability());
    Feature feature2 = provider.getFeature("feature_2");
    assertTrue(feature2.isAvailable());
    assertEquals(5000, feature2.availability());
    Feature feature3 = provider.getFeature("feature_3");
    assertFalse(feature3.isAvailable());
    assertEquals(0, feature3.availability());
    Feature feature4 = provider.getFeature("unknown_feature");
    assertFalse(feature4.isAvailable());
    assertEquals(0, feature4.availability());
    provider.stop();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) PropertiesWriter(org.apache.distributedlog.common.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

Aggregations

PropertiesWriter (org.apache.distributedlog.common.config.PropertiesWriter)6 Test (org.junit.Test)6 Feature (org.apache.bookkeeper.feature.Feature)3 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)3 File (java.io.File)1 Ignore (org.junit.Ignore)1