Search in sources :

Example 1 with PropertiesWriter

use of com.twitter.distributedlog.config.PropertiesWriter 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 2 with PropertiesWriter

use of com.twitter.distributedlog.config.PropertiesWriter 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 3 with PropertiesWriter

use of com.twitter.distributedlog.config.PropertiesWriter in project distributedlog by twitter.

the class TestStreamConfigProvider method testServiceProviderWithDefaultConfigPath.

@Test(timeout = 60000)
public void testServiceProviderWithDefaultConfigPath() throws Exception {
    // Default config with property set.
    PropertiesWriter writer1 = new PropertiesWriter();
    writer1.setProperty("rpsStreamAcquireServiceLimit", "191919");
    writer1.save();
    String fallbackConfPath1 = writer1.getFile().getPath();
    StreamConfigProvider provider1 = getServiceProvider(new IdentityStreamPartitionConverter(), DEFAULT_CONFIG_DIR, fallbackConfPath1);
    Optional<DynamicDistributedLogConfiguration> config1 = provider1.getDynamicStreamConfig("stream1");
    // Empty default config.
    PropertiesWriter writer2 = new PropertiesWriter();
    writer2.save();
    String fallbackConfPath2 = writer2.getFile().getPath();
    StreamConfigProvider provider2 = getServiceProvider(new IdentityStreamPartitionConverter(), DEFAULT_CONFIG_DIR, fallbackConfPath2);
    Optional<DynamicDistributedLogConfiguration> config2 = provider2.getDynamicStreamConfig("stream1");
    assertEquals(191919, config1.get().getRpsStreamAcquireServiceLimit());
    assertEquals(-1, config2.get().getRpsStreamAcquireServiceLimit());
}
Also used : IdentityStreamPartitionConverter(com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter) PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) Test(org.junit.Test)

Example 4 with PropertiesWriter

use of com.twitter.distributedlog.config.PropertiesWriter in project distributedlog by twitter.

the class TestStreamConfigProvider method testDefaultProvider.

@Test(timeout = 60000)
public void testDefaultProvider() throws Exception {
    PropertiesWriter writer = new PropertiesWriter();
    writer.setProperty(BKDL_RETENTION_PERIOD_IN_HOURS, "99");
    writer.save();
    StreamConfigProvider provider = getDefaultProvider(writer.getFile().getPath());
    Optional<DynamicDistributedLogConfiguration> config1 = provider.getDynamicStreamConfig("stream1");
    Optional<DynamicDistributedLogConfiguration> config2 = provider.getDynamicStreamConfig("stream2");
    assertTrue(config1.isPresent());
    assertTrue(config1.get() == config2.get());
    assertEquals(99, config1.get().getRetentionPeriodHours());
}
Also used : PropertiesWriter(com.twitter.distributedlog.config.PropertiesWriter) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) Test(org.junit.Test)

Example 5 with PropertiesWriter

use of com.twitter.distributedlog.config.PropertiesWriter 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

PropertiesWriter (com.twitter.distributedlog.config.PropertiesWriter)5 Test (org.junit.Test)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 Feature (org.apache.bookkeeper.feature.Feature)3 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)2 IdentityStreamPartitionConverter (com.twitter.distributedlog.service.streamset.IdentityStreamPartitionConverter)1 Ignore (org.junit.Ignore)1