Search in sources :

Example 1 with CleanupTimeoutGetter

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

the class TaskLauncher method initActivity.

@Override
public void initActivity(Body body) {
    this.taskId = initializer.getTaskId();
    this.taskLogger = new TaskLogger(taskId, getHostname());
    this.progressFileReader = new ProgressFileReader();
    this.taskKiller = new TaskKiller(Thread.currentThread(), new CleanupTimeoutGetter());
    nodeShutdownHook = new Thread(new Runnable() {

        @Override
        public void run() {
            kill();
        }
    });
}
Also used : CleanupTimeoutGetter(org.ow2.proactive.scheduler.task.utils.task.termination.CleanupTimeoutGetter) TaskKiller(org.ow2.proactive.scheduler.task.utils.task.termination.TaskKiller)

Example 2 with CleanupTimeoutGetter

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

the class TaskKillerTest method testThatTaskKillerInterruptsThreadImmediatelyWhenSetToZero.

@Test
public void testThatTaskKillerInterruptsThreadImmediatelyWhenSetToZero() {
    KilledThread testThreadToBeInterrupted = new KilledThread();
    testThreadToBeInterrupted.start();
    CleanupTimeoutGetter cleanupTimeoutGetterMock = mock(CleanupTimeoutGetter.class);
    doReturn(0L).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)

Example 3 with CleanupTimeoutGetter

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

the class TaskKillerTest method testThatTaskKillerInterruptsThreadThenWaitsUntilInterruptingAgainWithoutSystemPropertySet.

@Test
public void testThatTaskKillerInterruptsThreadThenWaitsUntilInterruptingAgainWithoutSystemPropertySet() {
    KilledThread testThreadToBeInterrupted = new KilledThread();
    testThreadToBeInterrupted.start();
    CleanupTimeoutGetter cleanupTimeoutGetterMock = mock(CleanupTimeoutGetter.class);
    doReturn(10L).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 a second for killing thread to start
    waitOrFailTest(1000);
    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(false));
    // Wait 10 seconds for killing timeout to be exceeded
    waitOrFailTest(10000);
    assertThat("Task Killer must have interrupted at least twice after timeout has passed", testThreadToBeInterrupted.isInterruptedMoreThanOnce, is(true));
}
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)

Example 4 with CleanupTimeoutGetter

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

the class TaskKillerTest method testThatTaskKillerInterruptsThreadThenWaitsUntilInterruptingAgain.

@Test
public void testThatTaskKillerInterruptsThreadThenWaitsUntilInterruptingAgain() {
    KilledThread testThreadToBeInterrupted = new KilledThread();
    testThreadToBeInterrupted.start();
    CleanupTimeoutGetter cleanupTimeoutGetterMock = mock(CleanupTimeoutGetter.class);
    doReturn(5L).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 a second for killing thread to start
    waitOrFailTest(1000);
    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(false));
    // Wait 5 seconds for killing timeout to be exceeded
    waitOrFailTest(5000);
    assertThat("Task Killer must have interrupted at least twice after timeout has passed", 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)

Example 5 with CleanupTimeoutGetter

use of org.ow2.proactive.scheduler.task.utils.task.termination.CleanupTimeoutGetter 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