use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer 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);
}
use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method input_file_using_variable_in_its_selector.
@Test
public void input_file_using_variable_in_its_selector() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
initializer.setJobVariables(singletonMap("aVar", new JobVariable("aVar", "foo")));
initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_${aVar}_${aResultVar}.txt"), InputAccessMode.TransferFromInputSpace)));
File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_foo_bar.txt");
assertTrue(inputFile.createNewFile());
TaskResultImpl previousTaskResult = taskResult(Collections.<String, Serializable>singletonMap("aResultVar", "bar"));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer, previousTaskResult);
assertTaskResultOk(taskResult);
assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_foo_bar.txt"));
}
use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.
the class TaskLauncherDataSpacesTest method input_file_using_job_id_in_its_selector.
@Test
public void input_file_using_job_id_in_its_selector() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("println new File('.').listFiles();", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
initializer.setTaskInputFiles(singletonList(new InputSelector(new FileSelector("input_$PA_JOB_ID.txt"), InputAccessMode.TransferFromInputSpace)));
File inputFile = new File(taskLauncherFactory.getDataSpaces().getInputURI(), "input_1000.txt");
assertTrue(inputFile.createNewFile());
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, taskLauncherFactory), executableContainer);
assertFalse(taskResult.hadException());
assertTrue(taskResult.getOutput().getAllLogs(false).contains("input_1000.txt"));
}
use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.
the class TaskLauncherTest method testProgressFileReaderIntegration.
@Test
public void testProgressFileReaderIntegration() throws Throwable {
int nbIterations = 3;
String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-report-progress.py"), Charsets.UTF_8));
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript(taskScript, "python", new String[] { Integer.toString(nbIterations) })));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("42"), "job", 1000L));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory()), executableContainer);
List result = (List) taskResult.value();
for (int i = 1; i <= result.size(); i++) {
assertEquals(i * (100 / nbIterations), result.get(i - 1));
}
}
use of org.ow2.proactive.scheduler.task.containers.ExecutableContainer in project scheduling by ow2-proactive.
the class TaskLauncherTest method scratchDirDeletedAfterTaskCompleted.
@Test
public void scratchDirDeletedAfterTaskCompleted() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
final TaskDataspaces dataspacesMock = mock(TaskDataspaces.class);
when(dataspacesMock.getScratchFolder()).thenReturn(tmpFolder.newFolder());
runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory() {
@Override
public TaskDataspaces createTaskDataspaces(TaskId taskId, NamingService namingService, boolean isRunAsUser) {
return dataspacesMock;
}
}), executableContainer);
verify(dataspacesMock).close();
}
Aggregations