Search in sources :

Example 1 with AbstractJmxManager

use of com.linkedin.r2.transport.http.client.AbstractJmxManager in project rest.li by linkedin.

the class TestHttpNettyClient method testPoolStatsProviderManager.

@Test
public void testPoolStatsProviderManager() throws InterruptedException, ExecutionException, TimeoutException {
    final CountDownLatch setLatch = new CountDownLatch(1);
    final CountDownLatch removeLatch = new CountDownLatch(1);
    AbstractJmxManager manager = new AbstractJmxManager() {

        @Override
        public void onProviderCreate(PoolStatsProvider provider) {
            setLatch.countDown();
        }

        @Override
        public void onProviderShutdown(PoolStatsProvider provider) {
            removeLatch.countDown();
        }
    };
    HttpNettyClient client = new HttpClientBuilder(_eventLoop, _scheduler).setJmxManager(manager).buildRestClient();
    // test setPoolStatsProvider
    try {
        setLatch.await(30, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Assert.fail("PoolStatsAware setPoolStatsProvider didn't get called when creating channel pool.");
    }
    // test removePoolStatsProvider
    FutureCallback<None> shutdownCallback = new FutureCallback<>();
    client.shutdown(shutdownCallback);
    try {
        removeLatch.await(30, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        Assert.fail("PoolStatsAware removePoolStatsProvider didn't get called when shutting down channel pool.");
    }
    shutdownCallback.get(30, TimeUnit.SECONDS);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) HttpNettyClient(com.linkedin.r2.transport.http.client.rest.HttpNettyClient) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Aggregations

FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 HttpNettyClient (com.linkedin.r2.transport.http.client.rest.HttpNettyClient)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.testng.annotations.Test)1