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();
}
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());
}
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);
}
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();
}
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();
}
Aggregations