use of com.linkedin.r2.transport.http.client.PoolStats in project rest.li by linkedin.
the class TestAsyncPool method testGetStatsWithErrors.
@Test
public void testGetStatsWithErrors() throws Exception {
final int POOL_SIZE = 25;
final int GET = 20;
final int PUT_BAD = 5;
final int DISPOSE = 7;
final int CREATE_BAD = 9;
final int TIMEOUT = 100;
final UnreliableLifecycle lifecycle = new UnreliableLifecycle();
final AsyncPool<AtomicBoolean> pool = new AsyncPoolImpl<>("object pool", lifecycle, POOL_SIZE, TIMEOUT, _executor);
PoolStats stats;
final List<AtomicBoolean> objects = new ArrayList<>();
pool.start();
// do a few gets
for (int i = 0; i < GET; i++) {
FutureCallback<AtomicBoolean> cb = new FutureCallback<>();
pool.get(cb);
AtomicBoolean obj = cb.get();
objects.add(obj);
}
// put and destroy some, with errors
lifecycle.setFail(true);
for (int i = 0; i < PUT_BAD; i++) {
AtomicBoolean obj = objects.remove(objects.size() - 1);
obj.set(false);
pool.put(obj);
}
for (int i = 0; i < DISPOSE; i++) {
AtomicBoolean obj = objects.remove(objects.size() - 1);
pool.dispose(obj);
}
stats = pool.getStats();
Assert.assertEquals(stats.getTotalDestroyed(), 0);
Assert.assertEquals(stats.getTotalCreateErrors(), 0);
Assert.assertEquals(stats.getTotalDestroyErrors(), PUT_BAD + DISPOSE);
Assert.assertEquals(stats.getTotalBadDestroyed(), PUT_BAD + DISPOSE);
// create some with errors
for (int i = 0; i < CREATE_BAD; i++) {
FutureCallback<AtomicBoolean> cb = new FutureCallback<>();
try {
pool.get(cb);
} catch (Exception e) {
// this error is expected
}
}
stats = pool.getStats();
Assert.assertEquals(stats.getCheckedOut(), GET - PUT_BAD - DISPOSE);
Assert.assertEquals(stats.getTotalCreateErrors(), CREATE_BAD);
}
use of com.linkedin.r2.transport.http.client.PoolStats in project rest.li by linkedin.
the class TestAsyncSharedPoolImpl method testGetStats.
@Test
public void testGetStats() {
AsyncSharedPoolImpl<Object> pool = new AsyncSharedPoolImpl<>(POOL_NAME, LIFECYCLE, SCHEDULER, LIMITER, NO_POOL_TIMEOUT, MAX_WAITERS);
PoolStats stats = pool.getStats();
Assert.assertNotNull(stats);
Assert.assertEquals(stats.getMaxPoolSize(), 1);
Assert.assertEquals(stats.getMinPoolSize(), 0);
Assert.assertEquals(stats.getIdleCount(), 0);
Assert.assertEquals(stats.getTotalDestroyErrors(), 0);
Assert.assertEquals(stats.getTotalDestroyed(), 0);
Assert.assertEquals(stats.getTotalTimedOut(), 0);
Assert.assertEquals(stats.getTotalCreateErrors(), 0);
Assert.assertEquals(stats.getTotalBadDestroyed(), 0);
Assert.assertEquals(stats.getCheckedOut(), 0);
Assert.assertEquals(stats.getTotalCreated(), 0);
Assert.assertEquals(stats.getPoolSize(), 0);
Assert.assertEquals(stats.getSampleMaxCheckedOut(), 0);
Assert.assertEquals(stats.getSampleMaxPoolSize(), 0);
Assert.assertEquals(stats.getWaitTime50Pct(), 0);
Assert.assertEquals(stats.getWaitTime95Pct(), 0);
Assert.assertEquals(stats.getWaitTime99Pct(), 0);
Assert.assertEquals(stats.getWaitTimeAvg(), 0.0);
}
use of com.linkedin.r2.transport.http.client.PoolStats in project rest.li by linkedin.
the class TestAsyncSharedPoolImpl method testMaximumConcurrency.
@Test(dataProvider = "lifecycles")
public void testMaximumConcurrency(AsyncPool.Lifecycle<Object> lifecycle) throws Exception {
final AsyncSharedPoolImpl<Object> pool = new AsyncSharedPoolImpl<>(POOL_NAME, lifecycle, SCHEDULER, LIMITER, NO_POOL_TIMEOUT, MAX_WAITERS);
pool.start();
CountDownLatch latch = new CountDownLatch(NUMBER_OF_THREADS);
IntStream.range(0, NUMBER_OF_THREADS).forEach(i -> SCHEDULER.execute(() -> {
try {
FutureCallback<Object> callback = new FutureCallback<>();
Assert.assertNotNull(pool.get(callback));
Object item = callback.get(GET_TIMEOUT, TIME_UNIT);
Assert.assertNotNull(item);
pool.put(item);
} catch (Exception e) {
} finally {
latch.countDown();
}
}));
if (!latch.await(OPERATION_TIMEOUT, TIME_UNIT)) {
Assert.fail("Timed out before tasks finish");
}
PoolStats stats = pool.getStats();
System.err.println("Total Created: " + stats.getTotalCreated());
FutureCallback<None> shutdownCallback = new FutureCallback<>();
pool.shutdown(shutdownCallback);
shutdownCallback.get(SHUTDOWN_TIMEOUT, TIME_UNIT);
}
Aggregations