use of org.ow2.proactive.scripting.SimpleScript 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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("valuepretask", taskOutput.output());
assertEquals("post", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingPrescript.
@Test
public void failingPrescript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("return 10/0", "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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("", taskOutput.output());
assertNotEquals("", taskOutput.error());
assertNotNull(result.getException());
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method resultMetadata.
@Test
public void resultMetadata() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Map<String, String> metadata = ImmutableMap.of("pre", "pre", "post", "post", "task", "task");
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('pre','pre')", "groovy"));
initializer.setPostScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('post','post')", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(SchedulerConstants.RESULT_METADATA_VARIABLE + ".put('task','task')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(metadata, result.getMetadata());
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class KillTaskLauncherTest method kill_while_looping_in_task.
@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_while_looping_in_task() throws Exception {
final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("for(;;){}", "javascript")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
Semaphore taskRunning = new Semaphore(0);
final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(taskRunning));
final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
taskLauncherPA.doTask(executableContainer, null, null);
taskRunning.acquire();
taskLauncherPA.kill();
assertTaskLauncherIsTerminated(taskLauncherPA);
PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
use of org.ow2.proactive.scripting.SimpleScript 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);
}
Aggregations