Search in sources :

Example 26 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)

Example 27 with SettableFeature

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

the class ConfigurationFeatureProvider method makeFeature.

static SettableFeature makeFeature(ConcurrentBaseConfiguration featuresConf, ConcurrentMap<String, SettableFeature> features, String featureName) {
    SettableFeature feature = features.get(featureName);
    if (null == feature) {
        int availability = featuresConf.getInt(featureName, 0);
        feature = new SettableFeature(featureName, availability);
        SettableFeature oldFeature = features.putIfAbsent(featureName, feature);
        if (null != oldFeature) {
            feature = oldFeature;
        } else {
            logger.info("Load feature {}={}", featureName, availability);
        }
    }
    return feature;
}
Also used : SettableFeature(org.apache.bookkeeper.feature.SettableFeature)

Aggregations

SettableFeature (org.apache.bookkeeper.feature.SettableFeature)27 Test (org.junit.Test)22 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)6 SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)5 SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)3 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)3 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)3 HashSet (java.util.HashSet)3 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)3 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)2 WriteOp (com.twitter.distributedlog.service.stream.WriteOp)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Feature (org.apache.bookkeeper.feature.Feature)2 OverCapacityException (org.apache.distributedlog.exceptions.OverCapacityException)2