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