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