Search in sources :

Example 11 with SettableFeature

use of org.apache.bookkeeper.feature.SettableFeature 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 12 with SettableFeature

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

the class TestWriteLimiter method testDisabledFeature.

@Test
public void testDisabledFeature() throws Exception {
    // Disable darkmode, but should still ignore limits because of the feature.
    SettableFeature feature = new SettableFeature("test", 10000);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) Test(org.junit.Test)

Example 13 with SettableFeature

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

the class TestWriteLimiter method testUnsetDisableFeatureBeforePermitsExceeded.

@Test
public void testUnsetDisableFeatureBeforePermitsExceeded() throws Exception {
    SettableFeature feature = new SettableFeature("test", 0);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1, feature);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE, feature);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    try {
        limiter.acquire();
        fail("should have thrown stream limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 1, globalLimiter, 1);
    feature.set(10000);
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
}
Also used : SimplePermitLimiter(com.twitter.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(com.twitter.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Aggregations

SettableFeature (org.apache.bookkeeper.feature.SettableFeature)13 Test (org.junit.Test)12 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)3 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)3 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)2 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FlakyTest (com.twitter.distributedlog.annotations.DistributedLogAnnotations.FlakyTest)1 ConcurrentBaseConfiguration (com.twitter.distributedlog.config.ConcurrentBaseConfiguration)1 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)1 StreamUnavailableException (com.twitter.distributedlog.exceptions.StreamUnavailableException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Feature (org.apache.bookkeeper.feature.Feature)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1