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);
}
Aggregations