@Test(timeout = 60_000L) public void testConcurrentTakeBatch() throws ExecutionException, InterruptedException { final int batch1 = pool.maxSize() / 2; final Callable<List<ReferenceCountingResourceHolder<Integer>>> c1 = () -> pool.takeBatch(batch1, 10); final int batch2 = pool.maxSize() - batch1 + 1; final Callable<List<ReferenceCountingResourceHolder<Integer>>> c2 = () -> pool.takeBatch(batch2, 10); final Future<List<ReferenceCountingResourceHolder<Integer>>> f1 = service.submit(c1); final Future<List<ReferenceCountingResourceHolder<Integer>>> f2 = service.submit(c2); final List<ReferenceCountingResourceHolder<Integer>> r1 = f1.get(); final List<ReferenceCountingResourceHolder<Integer>> r2 = f2.get(); if (r1 != null) { assertTrue(r2.isEmpty()); assertEquals(pool.maxSize() - batch1, pool.getPoolSize()); assertEquals(batch1, r1.size()); r1.forEach(ReferenceCountingResourceHolder::close); } else { assertNotNull(r2); assertEquals(pool.maxSize() - batch2, pool.getPoolSize()); assertEquals(batch2, r2.size()); r2.forEach(ReferenceCountingResourceHolder::close); } assertEquals(pool.maxSize(), pool.getPoolSize()); }
@Test(timeout = 60_000L) public void testConcurrentTake() throws ExecutionException, InterruptedException final int limit1 = pool.maxSize() / 2; final int limit2 = pool.maxSize() - limit1 + 1; assertEquals(pool.maxSize(), nonNullCount); future2.get(); assertEquals(pool.maxSize(), pool.getPoolSize());
@Test(timeout = 60_000L) public void testConcurrentBatchClose() throws ExecutionException, InterruptedException final int batch1 = pool.maxSize() / 2; final Callable<List<ReferenceCountingResourceHolder<Integer>>> c1 = () -> pool.takeBatch(batch1, 10); final int batch2 = pool.maxSize() - batch1; final Callable<List<ReferenceCountingResourceHolder<Integer>>> c2 = () -> pool.takeBatch(batch2, 10); future2.get(); assertEquals(pool.maxSize(), pool.getPoolSize());
assertEquals(pool.maxSize(), pool.getPoolSize());