Search in sources :

Example 1 with Feature

use of org.apache.bookkeeper.feature.Feature in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Feature

use of org.apache.bookkeeper.feature.Feature in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

Example 3 with Feature

use of org.apache.bookkeeper.feature.Feature in project distributedlog by twitter.

the class TestConfigurationFeatureProvider method testConfigurationFeatureProvider.

@Test(timeout = 60000)
public void testConfigurationFeatureProvider() throws Exception {
    String rootScope = "dl";
    ConcurrentBaseConfiguration featureConf = new ConcurrentBaseConfiguration();
    ConcurrentMap<String, SettableFeature> features = new ConcurrentHashMap<String, SettableFeature>();
    ConfigurationFeatureProvider featureProvider = new ConfigurationFeatureProvider(rootScope, featureConf, features);
    String featureName1 = "feature1";
    String fullFeatureName1 = rootScope + "." + featureName1;
    int availability1 = 1234;
    featureConf.setProperty(fullFeatureName1, availability1);
    Feature feature1 = featureProvider.getFeature(featureName1);
    assertEquals(availability1, feature1.availability());
    assertTrue(features.containsKey(fullFeatureName1));
    assertTrue(feature1 == features.get(fullFeatureName1));
    String subScope = "subscope";
    String featureName2 = "feature2";
    String fullFeatureName2 = rootScope + "." + subScope + "." + featureName2;
    int availability2 = 4321;
    featureConf.setProperty(fullFeatureName2, availability2);
    Feature feature2 = featureProvider.scope(subScope).getFeature(featureName2);
    assertEquals(availability2, feature2.availability());
    assertTrue(features.containsKey(fullFeatureName2));
    assertTrue(feature2 == features.get(fullFeatureName2));
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Feature(org.apache.bookkeeper.feature.Feature) ConcurrentBaseConfiguration(com.twitter.distributedlog.config.ConcurrentBaseConfiguration) Test(org.junit.Test)

Example 4 with Feature

use of org.apache.bookkeeper.feature.Feature in project distributedlog by twitter.

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(com.twitter.distributedlog.DistributedLogConfiguration) PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) Feature(org.apache.bookkeeper.feature.Feature) Test(org.junit.Test)

Aggregations

Feature (org.apache.bookkeeper.feature.Feature)4 Test (org.junit.Test)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 PropertiesWriter (com.twitter.distributedlog.config.PropertiesWriter)3 ConcurrentBaseConfiguration (com.twitter.distributedlog.config.ConcurrentBaseConfiguration)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)1 Ignore (org.junit.Ignore)1