DirectExecutorService() { delegate = MoreExecutors.newDirectExecutorService(); }
DirectExecutorService() { delegate = MoreExecutors.newDirectExecutorService(); }
public void testExecuteAfterShutdown() { ExecutorService executor = newDirectExecutorService(); executor.shutdown(); try { executor.execute(EMPTY_RUNNABLE); fail(); } catch (RejectedExecutionException expected) { } }
public <T> void testListeningExecutorServiceInvokeAllJavadocCodeCompiles() throws Exception { ListeningExecutorService executor = newDirectExecutorService(); List<Callable<T>> tasks = ImmutableList.of(); List<? extends Future<?>> unused = executor.invokeAll(tasks); }
public void testThreadRenaming() { Executor renamingExecutor = renamingDecorator(newDirectExecutorService(), Suppliers.ofInstance("FooBar")); String oldName = Thread.currentThread().getName(); renamingExecutor.execute( new Runnable() { @Override public void run() { assertEquals("FooBar", Thread.currentThread().getName()); } }); assertEquals(oldName, Thread.currentThread().getName()); }
/** * Starts building the steps to run. * * @param buildConfiguration the {@link BuildConfiguration} * @return a new {@link StepsRunner} */ public static StepsRunner begin(BuildConfiguration buildConfiguration) { ExecutorService executorService = JibSystemProperties.isSerializedExecutionEnabled() ? MoreExecutors.newDirectExecutorService() : buildConfiguration.getExecutorService(); return new StepsRunner(MoreExecutors.listeningDecorator(executorService), buildConfiguration); }
public void testDirectExecutorService_shutdownNow() { ExecutorService executor = newDirectExecutorService(); assertEquals(ImmutableList.of(), executor.shutdownNow()); assertTrue(executor.isShutdown()); }
public static CachingHiveMetastore memoizeMetastore(ExtendedHiveMetastore delegate, long maximumSize) { return new CachingHiveMetastore( delegate, newDirectExecutorService(), OptionalLong.empty(), OptionalLong.empty(), maximumSize); }
@Override public Executor create() { // Cache implementations must avoid deadlocks by incorrectly assuming async execution return new TrackingExecutor(MoreExecutors.newDirectExecutorService()); } },
/** invokeAny(empty collection) throws IAE */ public void testInvokeAnyImpl_emptyTasks() throws Exception { ListeningExecutorService e = newDirectExecutorService(); try { invokeAnyImpl(e, new ArrayList<Callable<String>>(), false, 0, TimeUnit.NANOSECONDS); fail(); } catch (IllegalArgumentException success) { } finally { joinPool(e); } }
public void testDirectExecutorServiceInvokeAll() throws Exception { final ExecutorService executor = newDirectExecutorService(); final ThreadLocal<Integer> threadLocalCount = new ThreadLocal<Integer>() { @Override protected Integer initialValue() { return 0; } }; final Callable<Integer> incrementTask = new Callable<Integer>() { @Override public Integer call() { int i = threadLocalCount.get(); threadLocalCount.set(i + 1); return i; } }; List<Future<Integer>> futures = executor.invokeAll(Collections.nCopies(10, incrementTask)); for (int i = 0; i < 10; i++) { Future<Integer> future = futures.get(i); assertTrue("Task should have been run before being returned", future.isDone()); assertEquals(i, future.get().intValue()); } assertEquals(10, threadLocalCount.get().intValue()); }
public void testListeningDecorator() throws Exception { ListeningExecutorService service = listeningDecorator(newDirectExecutorService()); assertSame(service, listeningDecorator(service)); List<Callable<String>> callables = ImmutableList.of(Callables.returning("x")); List<Future<String>> results; results = service.invokeAll(callables); assertThat(getOnlyElement(results)).isInstanceOf(TrustedListenableFutureTask.class); results = service.invokeAll(callables, 1, SECONDS); assertThat(getOnlyElement(results)).isInstanceOf(TrustedListenableFutureTask.class); /* * TODO(cpovirk): move ForwardingTestCase somewhere common, and use it to * test the forwarded methods */ }
@BeforeClass public void setupClass() { Logging.initialize(); if (PARALLEL) { executor = listeningDecorator(newFixedThreadPool(getRuntime().availableProcessors() * 2, daemonThreadsNamed("completer-%s"))); } else { executor = newDirectExecutorService(); } functionAssertions = new FunctionAssertions(); }
/** invokeAny(c) throws NPE if c has null elements */ public void testInvokeAnyImpl_nullElement() throws Exception { ListeningExecutorService e = newDirectExecutorService(); List<Callable<Integer>> l = new ArrayList<>(); l.add( new Callable<Integer>() { @Override public Integer call() { throw new ArithmeticException("/ by zero"); } }); l.add(null); try { invokeAnyImpl(e, l, false, 0, TimeUnit.NANOSECONDS); fail(); } catch (NullPointerException success) { } finally { joinPool(e); } }
/** * Test for a bug where threads weren't getting signaled when shutdown was called, only when tasks * completed. */ public void testDirectExecutorService_awaitTermination_missedSignal() { final ExecutorService service = MoreExecutors.newDirectExecutorService(); Thread waiter = new Thread() { @Override public void run() { try { service.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException e) { return; } } }; waiter.start(); awaitTimedWaiting(waiter); service.shutdown(); Uninterruptibles.joinUninterruptibly(waiter, 10, TimeUnit.SECONDS); if (waiter.isAlive()) { waiter.interrupt(); fail("awaitTermination failed to trigger after shutdown()"); } }
/** invokeAny(c) returns result of some task in c if at least one completes */ public void testInvokeAnyImpl() throws Exception { ListeningExecutorService e = newDirectExecutorService(); try { List<Callable<String>> l = new ArrayList<>(); l.add(new StringTask()); l.add(new StringTask()); String result = invokeAnyImpl(e, l, false, 0, TimeUnit.NANOSECONDS); assertSame(TEST_STRING, result); } finally { joinPool(e); } }
/** invokeAny(null) throws NPE */ public void testInvokeAnyImpl_nullTasks() throws Exception { ListeningExecutorService e = newDirectExecutorService(); try { invokeAnyImpl(e, null, false, 0, TimeUnit.NANOSECONDS); fail(); } catch (NullPointerException success) { } finally { joinPool(e); } }
/** invokeAny(c) throws ExecutionException if no task in c completes */ public void testInvokeAnyImpl_noTaskCompletes() throws Exception { ListeningExecutorService e = newDirectExecutorService(); List<Callable<String>> l = new ArrayList<>(); l.add(new NPETask()); try { invokeAnyImpl(e, l, false, 0, TimeUnit.NANOSECONDS); fail(); } catch (ExecutionException success) { assertThat(success).hasCauseThat().isInstanceOf(NullPointerException.class); } finally { joinPool(e); } }
@GwtIncompatible public void testAsAsyncCallable() throws Exception { final String expected = "MyCallableString"; Callable<String> callable = new Callable<String>() { @Override public String call() throws Exception { return expected; } }; AsyncCallable<String> asyncCallable = Callables.asAsyncCallable(callable, MoreExecutors.newDirectExecutorService()); ListenableFuture<String> future = asyncCallable.call(); assertSame(expected, future.get()); }
@GwtIncompatible public void testAsAsyncCallable_exception() throws Exception { final Exception expected = new IllegalArgumentException(); Callable<String> callable = new Callable<String>() { @Override public String call() throws Exception { throw expected; } }; AsyncCallable<String> asyncCallable = Callables.asAsyncCallable(callable, MoreExecutors.newDirectExecutorService()); ListenableFuture<String> future = asyncCallable.call(); try { future.get(); fail("Expected exception to be thrown"); } catch (ExecutionException e) { assertThat(e).hasCauseThat().isSameAs(expected); } }