use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method scriptArguments.
@Test
public void scriptArguments() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
String printEnvVariables = "print(args[0])";
initializer.setPreScript(new SimpleScript(printEnvVariables, "groovy", new Serializable[] { "Hello" }));
initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertEquals("Hello", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo 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.context.NodeInfo 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.context.NodeInfo 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.context.NodeInfo in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method nonDaemonThreadsForkedJVMExit.
/**
* This test ensures that the forked JVM exited properly when non-daemon threads are created inside the task
*
* @throws Exception
*/
@Test(timeout = 30000)
public void nonDaemonThreadsForkedJVMExit() throws Exception {
String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-nondaemon-thread.groovy"), Charsets.UTF_8));
TestTaskOutput taskOutput = new TestTaskOutput();
File workingDir = tmpFolder.newFolder();
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(workingDir);
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
TaskResultImpl result = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(taskScript, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
Assert.assertFalse(result.hadException());
}
Aggregations