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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations