Pool { public void close() { size.set(maxSize); while (true) { PoolItem<T> item = idleItems.poll(); if (item == null) return; closeResource(item); } } Pool(Supplier<T> factory, String name); void size(int minSize, int maxSize); void checkoutTimeout(Duration timeout); void validator(ResourceValidator<T> validator, Duration aliveWindow); PoolItem<T> borrowItem(); void returnItem(PoolItem<T> item); void refresh(); void close(); public Duration maxIdleTime; }
@Test void close() { PoolItem<TestPoolResource> item = pool.borrowItem(); pool.returnItem(item); pool.close(); assertThat(item.resource.closed).isTrue(); }