final ExecutorService exec = getActiveExecutor(); for (final BackgroundInitializer<?> bi : inits.values()) { if (bi.getExternalExecutor() == null) {
/** * Tests background processing if a temporary executor is used. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeTempExec() throws ConcurrentException { checkInitialize(); assertTrue("Executor not shutdown", initializer.getActiveExecutor() .isShutdown()); }
/** * Tests background processing if an external executor service is provided. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeExternalExec() throws ConcurrentException, InterruptedException { final ExecutorService exec = Executors.newCachedThreadPool(); try { initializer = new MultiBackgroundInitializer(exec); checkInitialize(); assertEquals("Wrong executor", exec, initializer .getActiveExecutor()); assertFalse("Executor was shutdown", exec.isShutdown()); } finally { exec.shutdown(); exec.awaitTermination(1, TimeUnit.SECONDS); } }
/** * Tests the background processing if there are no child initializers. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeNoChildren() throws ConcurrentException { assertTrue("Wrong result of start()", initializer.start()); final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer .get(); assertTrue("Got child initializers", res.initializerNames().isEmpty()); assertTrue("Executor not shutdown", initializer.getActiveExecutor() .isShutdown()); }
/** * Tests the behavior of initialize() if a child initializer has a specific * executor service. Then this service should not be overridden. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeChildWithExecutor() throws ConcurrentException, InterruptedException { final String initExec = "childInitializerWithExecutor"; final ExecutorService exec = Executors.newSingleThreadExecutor(); try { final ChildBackgroundInitializer c1 = new ChildBackgroundInitializer(); final ChildBackgroundInitializer c2 = new ChildBackgroundInitializer(); c2.setExternalExecutor(exec); initializer.addInitializer(CHILD_INIT, c1); initializer.addInitializer(initExec, c2); initializer.start(); initializer.get(); checkChild(c1, initializer.getActiveExecutor()); checkChild(c2, exec); } finally { exec.shutdown(); exec.awaitTermination(1, TimeUnit.SECONDS); } }
assertFalse("Exception flag", res.isException(key)); assertNull("Got an exception", res.getException(key)); checkChild(res.getInitializer(key), initializer.getActiveExecutor());
final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer .get(); final ExecutorService exec = initializer.getActiveExecutor(); checkChild(res.getInitializer(CHILD_INIT), exec); final MultiBackgroundInitializer.MultiBackgroundInitializerResults res2 = (MultiBackgroundInitializer.MultiBackgroundInitializerResults) res
final ExecutorService exec = getActiveExecutor(); for (final BackgroundInitializer<?> bi : inits.values()) { if (bi.getExternalExecutor() == null) {
final ExecutorService exec = getActiveExecutor(); for (final BackgroundInitializer<?> bi : inits.values()) { if (bi.getExternalExecutor() == null) {
final ExecutorService exec = getActiveExecutor(); for (final BackgroundInitializer<?> bi : inits.values()) { if (bi.getExternalExecutor() == null) {