use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method ensureForkedJvmContainTaskForkProperty.
@Test
public void ensureForkedJvmContainTaskForkProperty() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "sample", 1000L)));
ForkedTaskExecutor forkedTaskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskResultImpl result = forkedTaskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("result=System.getProperty('" + PASchedulerProperties.TASK_FORK.getKey() + "')", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
Assert.assertEquals("true", result.value());
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method forkEnvironment.
@Test
public void forkEnvironment() throws Exception {
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)));
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addSystemEnvironmentVariable("envVar", "envValue");
forkEnvironment.addJVMArgument("-DjvmArg=jvmValue");
initializer.setForkEnvironment(forkEnvironment);
taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(String.format("envValue%njvmValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class ForkedTaskExecutorTest method forkEnvironment_WithVariables.
@Test
public void forkEnvironment_WithVariables() throws Exception {
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)));
initializer.setJobVariables(Collections.singletonMap("aVar", new JobVariable("aVar", "aValue")));
ForkEnvironment forkEnvironment = new ForkEnvironment();
forkEnvironment.addSystemEnvironmentVariable("envVar", "$aVar");
forkEnvironment.addJVMArgument("-DjvmArg=$aVar");
initializer.setForkEnvironment(forkEnvironment);
taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println System.getenv('envVar'); " + "println System.getProperty('jvmArg'); " + "println new File('.').getCanonicalPath()", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(String.format("aValue%naValue%n%s%n", new File(workingDir, ".").getCanonicalPath()), taskOutput.output());
}
use of org.ow2.proactive.scripting.SimpleScript 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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertTrue(result.hadException());
assertFalse(taskOutput.error().isEmpty());
}
use of org.ow2.proactive.scripting.SimpleScript in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method failingScriptTask.
@Test
public void failingScriptTask() throws Exception {
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("return 10/0", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals("", taskOutput.output());
assertNotEquals("", taskOutput.error());
assertNotNull(result.getException());
}
Aggregations