Search in sources :

Example 6 with SimplePermitLimiter

use of com.twitter.distributedlog.util.SimplePermitLimiter in project distributedlog by twitter.

the class TestWriteLimiter method testUnsetDisableFeatureAfterPermitsExceeded.

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

Example 7 with SimplePermitLimiter

use of com.twitter.distributedlog.util.SimplePermitLimiter in project distributedlog by twitter.

the class TestWriteLimiter method testDarkmodeGlobalUnderStreamOver.

@Test
public void testDarkmodeGlobalUnderStreamOver() throws Exception {
    SimplePermitLimiter streamLimiter = createPermitLimiter(true, 1);
    SimplePermitLimiter globalLimiter = createPermitLimiter(true, 2);
    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) Test(org.junit.Test)

Example 8 with SimplePermitLimiter

use of com.twitter.distributedlog.util.SimplePermitLimiter in project distributedlog by twitter.

the class TestWriteLimiter method testSetDisableFeatureAfterAcquireAndBeforeRelease.

@Test
public void testSetDisableFeatureAfterAcquireAndBeforeRelease() throws Exception {
    SettableFeature feature = new SettableFeature("test", 0);
    SimplePermitLimiter streamLimiter = createPermitLimiter(false, 2, 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);
    feature.set(10000);
    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 9 with SimplePermitLimiter

use of com.twitter.distributedlog.util.SimplePermitLimiter 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 10 with SimplePermitLimiter

use of com.twitter.distributedlog.util.SimplePermitLimiter in project distributedlog by twitter.

the class TestWriteLimiter method testDarkmode.

@Test
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(com.twitter.distributedlog.util.SimplePermitLimiter) Test(org.junit.Test)

Aggregations

SimplePermitLimiter (com.twitter.distributedlog.util.SimplePermitLimiter)11 Test (org.junit.Test)10 OverCapacityException (com.twitter.distributedlog.exceptions.OverCapacityException)5 SettableFeature (org.apache.bookkeeper.feature.SettableFeature)5 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 Future (com.twitter.util.Future)1 ArrayList (java.util.ArrayList)1 FixedValueFeature (org.apache.bookkeeper.feature.FixedValueFeature)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1