@Test(timeout = 16000) public void testPoolUseNoFailuresStarvation() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException, ObjectReturnException, ObjectDisposeException, ExecutionException { RecyclingSupplier<ExpensiveTestObject> pool = new RecyclingSupplierBuilder(1, new ExpensiveTestObjectFactory(1000000, 1000000, 1, 5)).build(); runTest(pool, 0, 15000); pool.dispose(); }
@SuppressFBWarnings("MDM_THREAD_YIELD") private void runTest(final RecyclingSupplier<ExpensiveTestObject> pool, final long sleepBetweenSubmit, final long deadlockTimeout) throws InterruptedException { Thread monitor = startDeadlockMonitor(pool, deadlockTimeout); ExecutorService execService = new LifoThreadPoolExecutorSQP("test", 10, 10, 5000, 1024, true); FailSafeExecutorImpl exec = new FailSafeExecutorImpl(execService); AsyncRetryExecutor policy = RetryPolicy.newBuilder() .withDefaultThrowableRetryPredicate().buildAsync(exec); int nrTests = 1000; Future<Integer>[] futures = new Future[nrTests]; for (int i = 0; i < nrTests; i++) { futures[i] = policy.submit(new TestCallable(pool, i)); Thread.sleep(sleepBetweenSubmit); } Pair<Map<Future, Object>, Exception> all = Futures.getAll(10000, futures); Exception ex = all.getSecond(); if (ex != null) { throw new RuntimeException(ex); } LOG.debug("Done({})", futures.length); monitor.interrupt(); monitor.join(); Thread.sleep(100); if (isDeadlock) { Assert.fail("deadlock detected"); } exec.close(); }
@Test(timeout = 20000) public void testPoolUseNoFailures() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException, ObjectReturnException, ObjectDisposeException, ExecutionException { RecyclingSupplier<ExpensiveTestObject> pool = new RecyclingSupplierBuilder(10, new ExpensiveTestObjectFactory(1000000, 1000000, 1, 5)).build(); runTest(pool, 0, 10000); pool.dispose(); }
@Test(timeout = 20000) public void testPoolUseWithMaintenance() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException, ObjectReturnException, ObjectDisposeException, ExecutionException { final RecyclingSupplier<ExpensiveTestObject> pool = new RecyclingSupplierBuilder<>(10, new ExpensiveTestObjectFactory()) .withMaintenance(DefaultScheduler.INSTANCE, 10, true).build(); runTest(pool, 5, 20000); try { pool.dispose(); } catch (ObjectDisposeException ex) { Throwables.writeTo(ex, System.err, Throwables.PackageDetail.SHORT); } }
@Test(timeout = 20000) public void testPoolUse() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException, ObjectReturnException, ObjectDisposeException, ExecutionException { final RecyclingSupplier<ExpensiveTestObject> pool = new RecyclingSupplierBuilder(10, new ExpensiveTestObjectFactory()).build(); runTest(pool, 0, 10000); try { ExpensiveTestObject.setFailAll(true); LogAssert expect = TestLoggers.sys().expect("", Level.WARN, LogMatchers.hasFormat("Cannot dispose object {}")); pool.dispose(); expect.assertObservation(); } finally { ExpensiveTestObject.setFailAll(false); } }