Search in sources :

Example 1 with ExecutingTask

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());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutingTask(ubic.gemma.core.job.executor.common.ExecutingTask) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 2 with ExecutingTask

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());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutingTask(ubic.gemma.core.job.executor.common.ExecutingTask) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 3 with ExecutingTask

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserDetailsImpl(gemma.gsec.authentication.UserDetailsImpl) ExecutorService(java.util.concurrent.ExecutorService) ExecutingTask(ubic.gemma.core.job.executor.common.ExecutingTask) Date(java.util.Date) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)3 Test (org.junit.Test)3 ExecutingTask (ubic.gemma.core.job.executor.common.ExecutingTask)3 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)3 UserDetailsImpl (gemma.gsec.authentication.UserDetailsImpl)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1