use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method contextVariables_index.
@Test
public void contextVariables_index() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setReplicationIndex(7);
initializer.setIterationIndex(6);
String script = "result = variables.get('PA_TASK_ITERATION') * variables.get('PA_TASK_REPLICATION')";
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(script, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(42, result.value());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method variablesPropagation.
@Test
public void variablesPropagation() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'pre')", "groovy"));
initializer.setPostScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'post')", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
initializer.setJobVariables(Collections.singletonMap("var", new JobVariable("var", "value")));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(variables.get('var')); variables.put('var', 'task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals("valuepretask", taskOutput.output());
assertEquals("post", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method taskWithFlowScript.
@Test
public void taskWithFlowScript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setControlFlowScript(FlowScript.createReplicateFlowScript("print('flow'); runs=5", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals(FlowActionType.REPLICATE, result.getAction().getType());
assertEquals("helloflow", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method nodesFileIsCreated.
@Test
public void nodesFileIsCreated() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
ScriptExecutableContainer printNodesFileTask = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print new File(variables.get('PA_NODESFILE')).text", "groovy")));
printNodesFileTask.setNodes(mockedNodeSet());
TaskContext context = new TaskContext(printNodesFileTask, initializer, null, new NodeDataSpacesURIs(tmpFolder.newFolder().getAbsolutePath(), "", "", "", "", ""), "", new NodeInfo("thisHost", "", "", ""));
TaskResultImpl taskResult = new InProcessTaskExecutor().execute(context, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(taskResult);
assertEquals(String.format("thisHost%ndummyhost%n"), taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl 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"));
}
Aggregations