Search in sources :

Example 1 with ObjectPool

use of io.grpc.internal.ObjectPool in project grpc-java by grpc.

the class InProcessServerTest method serverHoldsRefToScheduler.

@Test
public void serverHoldsRefToScheduler() throws Exception {
    final ScheduledExecutorService ses = new FakeClock().getScheduledExecutorService();
    class RefCountingObjectPool implements ObjectPool<ScheduledExecutorService> {

        private int count;

        @Override
        public ScheduledExecutorService getObject() {
            count++;
            return ses;
        }

        @Override
        public ScheduledExecutorService returnObject(Object returned) {
            count--;
            return null;
        }
    }
    RefCountingObjectPool pool = new RefCountingObjectPool();
    builder.schedulerPool = pool;
    InProcessServer s = new InProcessServer(builder, Collections.<ServerStreamTracer.Factory>emptyList());
    Truth.assertThat(pool.count).isEqualTo(0);
    s.start(new ServerListener() {

        @Override
        public ServerTransportListener transportCreated(ServerTransport transport) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void serverShutdown() {
        }
    });
    Truth.assertThat(pool.count).isEqualTo(1);
    s.shutdown();
    Truth.assertThat(pool.count).isEqualTo(0);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServerTransportListener(io.grpc.internal.ServerTransportListener) ServerStreamTracer(io.grpc.ServerStreamTracer) ServerTransport(io.grpc.internal.ServerTransport) FakeClock(io.grpc.internal.FakeClock) ObjectPool(io.grpc.internal.ObjectPool) ServerListener(io.grpc.internal.ServerListener) Test(org.junit.Test)

Aggregations

ServerStreamTracer (io.grpc.ServerStreamTracer)1 FakeClock (io.grpc.internal.FakeClock)1 ObjectPool (io.grpc.internal.ObjectPool)1 ServerListener (io.grpc.internal.ServerListener)1 ServerTransport (io.grpc.internal.ServerTransport)1 ServerTransportListener (io.grpc.internal.ServerTransportListener)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Test (org.junit.Test)1