use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesGetScopeVariables.
@Test
public void testExtractTaskResultVariablesGetScopeVariables() throws Exception {
ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
Map<String, Serializable> scopeVariables = new TaskContextVariableExtractor().getScopeVariables(taskContext);
Assert.assertThat(scopeVariables.toString(), CoreMatchers.containsString("{TestVariable2=valueForTest2}"));
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractTaskLauncherInitializerVariablesFromTaskContext.
@Test
public void testExtractTaskLauncherInitializerVariablesFromTaskContext() throws Exception {
ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
TaskContext taskContext = new TaskContext(scriptContainer, createTaskLauncherInitializer(), null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
validateExtractedVariablesFromTaskLauncherInitializer(contextVariables);
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesFromPreviousTaskResultsInsideTheTaskContext.
@Test
public void testExtractTaskResultVariablesFromPreviousTaskResultsInsideTheTaskContext() throws Exception {
ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariables();
Map<String, byte[]> taskResultVariables = new HashMap<>();
// The task result variables are expected to be converted to byte streams.
taskResultVariables.put(taskResultPropagatedVariables1Key, AllObjects2BytesConverterHandler.convertObject2Byte(taskResultPropagatedVariables1Key, taskResultPropagatedVariables1Value));
taskResultVariables.put(SchedulerVars.PA_TASK_ID.name(), AllObjects2BytesConverterHandler.convertObject2Byte(SchedulerVars.PA_TASK_ID.name(), "" + previousTaskIdValue));
TaskResultImpl taskResult = new TaskResultImpl(taskLauncherInitializer.getTaskId(), new Exception("Exception"));
taskResult.setPropagatedVariables(taskResultVariables);
TaskResult[] taskResultArray = { taskResult };
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, taskResultArray, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
Map<String, Serializable> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
assertThat((String) contextVariables.get(taskResultPropagatedVariables1Key), is(taskResultPropagatedVariables1Value));
// Makes sure the previous task id has been overwritten by the current task id
assertThat((String) contextVariables.get(SchedulerVars.PA_TASK_ID.name()), is("" + taskIdValue));
contextVariables = new TaskContextVariableExtractor().getAllNonTaskVariables(taskContext);
assertThat((String) contextVariables.get(taskResultPropagatedVariables1Key), is(taskResultPropagatedVariables1Value));
// Makes sure the previous task id has been overwritten by the current task id
assertThat((String) contextVariables.get(SchedulerVars.PA_TASK_ID.name()), is("" + taskIdValue));
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class ForkedProcessBuilderCreatorTest method createTaskContext.
private TaskContext createTaskContext() throws InvalidScriptException, NodeException {
ScriptExecutableContainer scriptContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
TaskLauncherInitializer taskLauncherInitializer = getTaskLauncherInitializerWithWorkflowVariableAndForkEnvironment();
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, null, null, null, null), null, new NodeInfo(null, null, null, null));
return taskContext;
}
use of org.ow2.proactive.scheduler.task.context.NodeInfo in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingScript.
@Test
public void failingScript() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("dsfsdfsdf", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
assertTrue(result.hadException());
assertFalse(taskOutput.error().isEmpty());
}
Aggregations