use of com.google.common.util.concurrent.ListeningExecutorService in project closure-compiler by google.
the class PrebuildAst method prebuild.
void prebuild(List<CompilerInput> inputList) {
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(null, r, "jscompiler-PrebuildAst", CompilerExecutor.COMPILER_STACK_SIZE);
// Do not prevent the JVM from exiting.
t.setDaemon(true);
return t;
}
};
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(numParallelThreads, numParallelThreads, Integer.MAX_VALUE, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory);
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(poolExecutor);
List<ListenableFuture<?>> futureList = new ArrayList<>(inputList.size());
// TODO(moz): Support canceling all parsing on the first halting error
for (final CompilerInput input : inputList) {
futureList.add(executorService.submit(new Runnable() {
@Override
public void run() {
input.getAstRoot(compiler);
}
}));
}
poolExecutor.shutdown();
try {
Futures.allAsList(futureList).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project thingsboard by thingsboard.
the class JpaDeviceDaoTest method testFindAsync.
@Test
public void testFindAsync() throws ExecutionException, InterruptedException {
UUID tenantId = UUIDs.timeBased();
UUID customerId = UUIDs.timeBased();
Device device = getDevice(tenantId, customerId);
deviceDao.save(device);
UUID uuid = device.getId().getId();
Device entity = deviceDao.findById(uuid);
assertNotNull(entity);
assertEquals(uuid, entity.getId().getId());
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
ListenableFuture<Device> future = service.submit(() -> deviceDao.findById(uuid));
Device asyncDevice = future.get();
assertNotNull("Async device expected to be not null", asyncDevice);
}
use of com.google.common.util.concurrent.ListeningExecutorService in project tez by apache.
the class TestTaskExecution2 method testSignalDeprecatedFatalErrorAndLoop.
@Test(timeout = 5000)
public void testSignalDeprecatedFatalErrorAndLoop() throws IOException, InterruptedException, TezException, ExecutionException {
ListeningExecutorService executor = null;
try {
ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
executor = MoreExecutors.listeningDecorator(rawExecutor);
ApplicationId appId = ApplicationId.newInstance(10000, 1);
TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
TaskReporter taskReporter = createTaskReporter(appId, umbilical);
TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor, TestProcessor.CONF_SIGNAL_DEPRECATEDFATAL_AND_LOOP);
// Setup the executor
Future<TaskRunner2Result> taskRunnerFuture = taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
// Signal the processor to go through
TestProcessor.awaitStart();
TestProcessor.signal();
TestProcessor.awaitLoop();
// The fatal error should have caused an interrupt.
TaskRunner2Result result = taskRunnerFuture.get();
verifyTaskRunnerResult(result, EndReason.TASK_ERROR, createProcessorIOException(), false, TaskFailureType.NON_FATAL);
TestProcessor.awaitCompletion();
assertTrue(TestProcessor.wasInterrupted());
assertNull(taskReporter.currentCallable);
umbilical.verifyTaskFailedEvent(FAILURE_START_STRING, IOException.class.getName() + ": " + IOException.class.getSimpleName());
// Signal fatal error should cause the processor to fail.
assertTrue(TestProcessor.wasAborted());
} finally {
executor.shutdownNow();
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project tez by apache.
the class TestTaskExecution2 method testSingleSuccessfulTask.
@Test(timeout = 5000)
public void testSingleSuccessfulTask() throws IOException, InterruptedException, TezException, ExecutionException {
ListeningExecutorService executor = null;
try {
ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
executor = MoreExecutors.listeningDecorator(rawExecutor);
ApplicationId appId = ApplicationId.newInstance(10000, 1);
TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
TaskReporter taskReporter = createTaskReporter(appId, umbilical);
TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor, TestProcessor.CONF_EMPTY);
// Setup the executor
Future<TaskRunner2Result> taskRunnerFuture = taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
// Signal the processor to go through
TestProcessor.signal();
TaskRunner2Result result = taskRunnerFuture.get();
verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
assertNull(taskReporter.currentCallable);
umbilical.verifyTaskSuccessEvent();
assertFalse(TestProcessor.wasAborted());
} finally {
executor.shutdownNow();
}
}
use of com.google.common.util.concurrent.ListeningExecutorService in project tez by apache.
the class TestTaskExecution2 method testMultipleSuccessfulTasks.
@Test(timeout = 5000)
public void testMultipleSuccessfulTasks() throws IOException, InterruptedException, TezException, ExecutionException {
ListeningExecutorService executor = null;
try {
ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
executor = MoreExecutors.listeningDecorator(rawExecutor);
ApplicationId appId = ApplicationId.newInstance(10000, 1);
TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
TaskReporter taskReporter = createTaskReporter(appId, umbilical);
TezTaskRunner2 taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor, TestProcessor.CONF_EMPTY, true);
LogicalIOProcessorRuntimeTask runtimeTask = taskRunner.task;
// Setup the executor
Future<TaskRunner2Result> taskRunnerFuture = taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
// Signal the processor to go through
TestProcessor.signal();
TaskRunner2Result result = taskRunnerFuture.get();
verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
assertNull(taskReporter.currentCallable);
umbilical.verifyTaskSuccessEvent();
assertFalse(TestProcessor.wasAborted());
umbilical.resetTrackedEvents();
TezCounters tezCounters = runtimeTask.getCounters();
verifySysCounters(tezCounters, 5, 5);
taskRunner = createTaskRunner(appId, umbilical, taskReporter, executor, TestProcessor.CONF_EMPTY, false);
runtimeTask = taskRunner.task;
// Setup the executor
taskRunnerFuture = taskExecutor.submit(new TaskRunnerCallable2ForTest(taskRunner));
// Signal the processor to go through
TestProcessor.signal();
result = taskRunnerFuture.get();
verifyTaskRunnerResult(result, EndReason.SUCCESS, null, false, null);
assertNull(taskReporter.currentCallable);
umbilical.verifyTaskSuccessEvent();
assertFalse(TestProcessor.wasAborted());
tezCounters = runtimeTask.getCounters();
verifySysCounters(tezCounters, -1, -1);
} finally {
executor.shutdownNow();
}
}
Aggregations