use of org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractThrowsExceptionIfVariablesAreInvalidByteStream.
@Test(expected = Exception.class)
public void testExtractThrowsExceptionIfVariablesAreInvalidByteStream() 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, taskResultPropagatedVariables1Value.getBytes());
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));
new TaskContextVariableExtractor().getAllVariables(taskContext);
}
use of org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractTaskResultVariablesGetAllNonTaskVariables.
@Test
public void testExtractTaskResultVariablesGetAllNonTaskVariables() 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().getAllNonTaskVariables(taskContext);
Assert.assertThat(scopeVariables.toString(), CoreMatchers.containsString("PA_TASK_NAME=TestTaskName"));
}
use of org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor in project scheduling by ow2-proactive.
the class ForkedProcessBuilderCreatorTest method setMocks.
private void setMocks(ForkedProcessBuilderCreator forkedProcessBuilderCreator) throws Exception {
ForkedJvmTaskExecutionCommandCreator forkedJvmTaskExecutionCommandCreator = mock(ForkedJvmTaskExecutionCommandCreator.class);
TaskContextVariableExtractor taskContextVariableExtractor = mock(TaskContextVariableExtractor.class);
ForkEnvironmentScriptExecutor forkEnvironmentScriptExecutor = mock(ForkEnvironmentScriptExecutor.class);
given(forkedJvmTaskExecutionCommandCreator.createForkedJvmTaskExecutionCommand(any(TaskContext.class), any(ScriptResult.class), any(String.class))).willReturn(Arrays.asList(forkEnJavaCommandString));
given(taskContextVariableExtractor.extractVariablesThirdPartyCredentialsAndSystemEnvironmentVariables(any(TaskContext.class))).willReturn(taskContextExtractedVariables);
given(forkEnvironmentScriptExecutor.executeForkEnvironmentScript(any(TaskContext.class), any(PrintStream.class), any(PrintStream.class))).willReturn(new ScriptResult<ForkEnvironmentScriptResult>(new ForkEnvironmentScriptResult()));
setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("forkedJvmTaskExecutionCommandCreator"), forkedProcessBuilderCreator, forkedJvmTaskExecutionCommandCreator);
setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("taskContextVariableExtractor"), forkedProcessBuilderCreator, taskContextVariableExtractor);
setPrivateField(ForkedProcessBuilderCreator.class.getDeclaredField("forkEnvironmentScriptExecutor"), forkedProcessBuilderCreator, forkEnvironmentScriptExecutor);
}
use of org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor in project scheduling by ow2-proactive.
the class ForkedTaskExecutor method createTaskResult.
private TaskResultImpl createTaskResult(TaskContext context, Throwable throwable) {
TaskResultImpl result = new TaskResultImpl(context.getTaskId(), new ForkedJvmProcessException("Failed to execute task in a forked JVM", throwable));
result.setPropagatedVariables(new TaskContextVariableExtractor().extractPropagatedVariables(context));
return result;
}
use of org.ow2.proactive.scheduler.task.context.TaskContextVariableExtractor in project scheduling by ow2-proactive.
the class TaskContextVariableExtractorTest method testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext.
@Test
public void testExtractWorkflowVariablesFromTaskLauncherInitializerInsideTaskContext() 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> contextVariables = new TaskContextVariableExtractor().getAllVariables(taskContext);
assertThat((String) contextVariables.get(testVariable1Key), is(testVariable1Value));
assertThat((String) contextVariables.get(testVariable2Key), is(testVariable2Value));
}
Aggregations