Search in sources :

Example 6 with SimplePermitLimiter

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

the class TestWriteLimiter method testDisabledFeature.

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

Example 7 with SimplePermitLimiter

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

the class TestWriteLimiter method testGlobalOnly.

@Test(timeout = 60000)
public void testGlobalOnly() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, Integer.MAX_VALUE);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, 1);
    WriteLimiter limiter = new WriteLimiter("test", streamLimiter, globalLimiter);
    limiter.acquire();
    try {
        limiter.acquire();
        fail("should have thrown global limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 1, globalLimiter, 1);
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 8 with SimplePermitLimiter

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

the class TestWriteLimiter method testDarkmode.

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

Example 9 with SimplePermitLimiter

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

the class TestWriteLimiter method testStreamOnly.

@Test(timeout = 60000)
public void testStreamOnly() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 1);
    SimplePermitLimiter globalLimiter = createPermitLimiter(false, Integer.MAX_VALUE);
    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);
}
Also used : SimplePermitLimiter(org.apache.distributedlog.util.SimplePermitLimiter) OverCapacityException(org.apache.distributedlog.exceptions.OverCapacityException) Test(org.junit.Test)

Example 10 with SimplePermitLimiter

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

the class TestWriteLimiter method testUnsetDisableFeatureAfterPermitsExceeded.

@Test(timeout = 60000)
public void testUnsetDisableFeatureAfterPermitsExceeded() throws Exception {
    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();
    limiter.acquire();
    limiter.acquire();
    assertPermits(streamLimiter, 4, globalLimiter, 4);
    feature.set(0);
    limiter.release();
    assertPermits(streamLimiter, 3, globalLimiter, 3);
    try {
        limiter.acquire();
        fail("should have thrown stream limit exception");
    } catch (OverCapacityException ex) {
    }
    assertPermits(streamLimiter, 3, globalLimiter, 3);
    limiter.release();
    limiter.release();
    limiter.release();
    assertPermits(streamLimiter, 0, globalLimiter, 0);
}
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