use of ubic.gemma.core.job.executor.common.ExecutingTask in project Gemma by PavlidisLab.
the class ExecutingTaskTest method testOrderOfExecutionSuccess.
// TODO: Test security context under different failure scenarios
// - exception in the task
// - exception in the lifecycle hook
// - exception in progress appender setup/teardown hook
@Test
public void testOrderOfExecutionSuccess() {
TaskCommand taskCommand = new TaskCommand();
Task<TaskResult, TaskCommand> task = new SuccessTestTask();
task.setTaskCommand(taskCommand);
ExecutingTask<TaskResult> executingTask = new ExecutingTask<>(task, taskCommand);
executingTask.setProgressAppender(progressAppender);
executingTask.setStatusCallback(statusUpdateHandler);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<TaskResult> future = executorService.submit(executingTask);
this.tryGetAnswer(future);
assertTrue(appenderInitialized.get());
assertTrue(appenderTakenDown.get());
assertTrue(onStartRan.get());
assertTrue(onFinishRan.get());
assertFalse(onFailureRan.get());
}
use of ubic.gemma.core.job.executor.common.ExecutingTask in project Gemma by PavlidisLab.
the class ExecutingTaskTest method testOrderOfExecutionFailure.
@Test
public void testOrderOfExecutionFailure() {
TaskCommand taskCommand = new TaskCommand();
Task<TaskResult, TaskCommand> task = new FailureTestTask();
task.setTaskCommand(taskCommand);
ExecutingTask<TaskResult> executingTask = new ExecutingTask<>(task, taskCommand);
executingTask.setProgressAppender(progressAppender);
executingTask.setStatusCallback(statusUpdateHandler);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<TaskResult> future = executorService.submit(executingTask);
try {
TaskResult taskResult = future.get();
Throwable exception = taskResult.getException();
assertEquals(AccessDeniedException.class, exception.getClass());
assertEquals("Test!", exception.getMessage());
} catch (InterruptedException | ExecutionException e) {
fail();
}
assertTrue(appenderInitialized.get());
assertTrue(appenderTakenDown.get());
assertTrue(onStartRan.get());
assertFalse(onFinishRan.get());
assertTrue(onFailureRan.get());
}
use of ubic.gemma.core.job.executor.common.ExecutingTask in project Gemma by PavlidisLab.
the class ExecutingTaskTest method testSecurityContextManagement.
@Test
public void testSecurityContextManagement() {
try {
this.userManager.loadUserByUsername("ExecutingTaskTestUser");
} catch (UsernameNotFoundException e) {
this.userManager.createUser(new UserDetailsImpl("foo", "ExecutingTaskTestUser", true, null, "fooUser@chibi.ubc.ca", "key", new Date()));
}
this.runAsUser("ExecutingTaskTestUser");
TaskCommand taskCommand = new TaskCommand();
this.runAsAdmin();
Task<TaskResult, TaskCommand> task = new SuccessTestTask();
task.setTaskCommand(taskCommand);
ExecutingTask<TaskResult> executingTask = new ExecutingTask<>(task, taskCommand);
executingTask.setProgressAppender(progressAppender);
executingTask.setStatusCallback(statusSecurityContextCheckerHandler);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<TaskResult> future = executorService.submit(executingTask);
this.tryGetAnswer(future);
assertEquals(taskCommand.getSecurityContext(), securityContextAfterInitialize);
assertNotSame(taskCommand.getSecurityContext(), securityContextAfterFinish);
assertEquals(null, securityContextAfterFail);
}
Aggregations