Search in sources :

Example 6 with TaskKiller

use of org.ow2.proactive.scheduler.task.utils.task.termination.TaskKiller in project scheduling by ow2-proactive.

the class TaskKillerTest method testThatTaskKillerInterruptsThreadImmediatelyWhenSetToNegativeNumber.

@Test
public void testThatTaskKillerInterruptsThreadImmediatelyWhenSetToNegativeNumber() {
    KilledThread testThreadToBeInterrupted = new KilledThread();
    testThreadToBeInterrupted.start();
    CleanupTimeoutGetter cleanupTimeoutGetterMock = mock(CleanupTimeoutGetter.class);
    doReturn(-20L).when(cleanupTimeoutGetterMock).getCleanupTimeSeconds();
    TaskKiller taskKiller = new TaskKiller(testThreadToBeInterrupted, cleanupTimeoutGetterMock);
    assertThat("Task Killer must not interrupt thread before kill() is called", testThreadToBeInterrupted.isInterruptedOnce, is(false));
    assertThat("Task Killer must not interrupt thread before kill() is called", testThreadToBeInterrupted.isInterruptedMoreThanOnce, is(false));
    startKilling(taskKiller);
    // Wait 100 milliseconds for killing thread to start
    waitOrFailTest(100);
    assertThat("Task Killer must interrupt once if kill() is called and then wait for the timeout which is set to 10 seconds.", testThreadToBeInterrupted.isInterruptedOnce, is(true));
    assertThat("Task Killer must only interrupt once (not twice) after kill() is called and then wait for the timeout which is set to 10 seconds.", testThreadToBeInterrupted.isInterruptedMoreThanOnce, is(true));
    // Cleanup - remove system property
    System.clearProperty(this.taskKillerCleanupTimePropertyName);
}
Also used : CleanupTimeoutGetter(org.ow2.proactive.scheduler.task.utils.task.termination.CleanupTimeoutGetter) TaskKiller(org.ow2.proactive.scheduler.task.utils.task.termination.TaskKiller) Test(org.junit.Test)

Aggregations

CleanupTimeoutGetter (org.ow2.proactive.scheduler.task.utils.task.termination.CleanupTimeoutGetter)5 TaskKiller (org.ow2.proactive.scheduler.task.utils.task.termination.TaskKiller)5 Test (org.junit.Test)4 Stopwatch (com.google.common.base.Stopwatch)1 File (java.io.File)1 Map (java.util.Map)1 TaskTerminateNotification (org.ow2.proactive.scheduler.common.TaskTerminateNotification)1 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)1 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)1 TaskDataspaces (org.ow2.proactive.scheduler.task.data.TaskDataspaces)1 TaskExecutor (org.ow2.proactive.scheduler.task.executors.TaskExecutor)1 WallTimer (org.ow2.proactive.scheduler.task.utils.WallTimer)1