Search in sources :

Example 1 with Repeat

use of org.ow2.proactive.utils.Repeat in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method kill_while_looping_in_task.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_while_looping_in_task() throws Exception {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("for(;;){}", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    Semaphore taskRunning = new Semaphore(0);
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(taskRunning));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    taskLauncherPA.doTask(executableContainer, null, null);
    taskRunning.acquire();
    taskLauncherPA.kill();
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Example 2 with Repeat

use of org.ow2.proactive.utils.Repeat in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method kill_when_finished.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_when_finished() throws Throwable {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("result='done'", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(new Semaphore(0)));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    TaskResultWaiter taskResultWaiter = new TaskResultWaiter();
    WaitForResultNotification waitForResultNotification = new WaitForResultNotification(taskResultWaiter);
    waitForResultNotification = PAActiveObject.turnActive(waitForResultNotification);
    taskLauncherPA.doTask(executableContainer, null, waitForResultNotification);
    assertEquals("done", taskResultWaiter.getTaskResult().value());
    try {
        taskLauncherPA.kill();
    } catch (Exception ignored) {
    // task launcher can be terminated before the kill message is received
    }
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Example 3 with Repeat

use of org.ow2.proactive.utils.Repeat in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method finished_but_terminate_not_called_back.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void finished_but_terminate_not_called_back() throws Throwable {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("result='done'", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(new Semaphore(0)));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    TaskResultWaiter taskResultWaiter = new TaskResultWaiter();
    WaitForResultNotification waitForResultNotification = new WaitForResultNotification(taskResultWaiter);
    waitForResultNotification = PAActiveObject.turnActive(waitForResultNotification);
    taskLauncherPA.doTask(executableContainer, null, waitForResultNotification);
    assertEquals("done", taskResultWaiter.getTaskResult().value());
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Example 4 with Repeat

use of org.ow2.proactive.utils.Repeat in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method kill_while_sleeping_in_task.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_while_sleeping_in_task() throws Exception {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("java.lang.Thread.sleep(10000)", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    Semaphore taskRunning = new Semaphore(0);
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(taskRunning));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    taskLauncherPA.doTask(executableContainer, null, null);
    taskRunning.acquire();
    taskLauncherPA.kill();
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Example 5 with Repeat

use of org.ow2.proactive.utils.Repeat in project scheduling by ow2-proactive.

the class KillTaskLauncherTest method kill_when_copying.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_when_copying() throws Throwable {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("result='done'", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    Semaphore taskRunning = new Semaphore(0);
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new SlowDataspacesTaskLauncherFactory(taskRunning));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    taskLauncherPA.doTask(executableContainer, null, null);
    taskRunning.acquire();
    taskLauncherPA.kill();
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Aggregations

Semaphore (java.util.concurrent.Semaphore)5 Test (org.junit.Test)5 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)5 SimpleScript (org.ow2.proactive.scripting.SimpleScript)5 TaskScript (org.ow2.proactive.scripting.TaskScript)5 Repeat (org.ow2.proactive.utils.Repeat)5