Search in sources :

Example 11 with SimplePermitLimiter

use of org.apache.distributedlog.util.SimplePermitLimiter in project bookkeeper by apache.

the class TestWriteLimiter method testDarkmodeGlobalOverStreamUnder.

@Test(timeout = 60000)
public void testDarkmodeGlobalOverStreamUnder() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(true, 2);
    SimplePermitLimiter globalLimiter = createPermitLimiter(true, 1);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 2, globalLimiter, 2);
    limiter.release();
    assertPermits(streamLimiter, 1, globalLimiter, 1);
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) Test(org.junit.Test)

Example 12 with SimplePermitLimiter

use of org.apache.distributedlog.util.SimplePermitLimiter in project bookkeeper by apache.

the class TestWriteLimiter method testUnsetDisableFeatureBeforePermitsExceeded.

@Test(timeout = 60000)
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(org.apache.distributedlog.util.SimplePermitLimiter) SettableFeature(org.apache.bookkeeper.feature.SettableFeature) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Aggregations

SimplePermitLimiter (org.apache.distributedlog.util.SimplePermitLimiter)12 Test (org.junit.Test)10 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)5 OverCapacityException (org.apache.distributedlog.exceptions.OverCapacityException)5 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1 Feature (org.apache.bookkeeper.feature.Feature)1 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 BKDistributedLogNamespace (org.apache.distributedlog.BKDistributedLogNamespace)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 PermitLimiter (org.apache.distributedlog.common.util.PermitLimiter)1 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)1 AsyncFailureInjector (org.apache.distributedlog.injector.AsyncFailureInjector)1 NamespaceDriver (org.apache.distributedlog.namespace.NamespaceDriver)1