Search in sources :

Example 11 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method contextVariables.

@Test
public void contextVariables() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setReplicationIndex(42);
    String printEnvVariables = "print(variables.get('PA_JOB_NAME') + '@' + " + "variables.get('PA_JOB_ID') + '@' + variables.get('PA_TASK_NAME') " + "+ '@' + variables.get('PA_TASK_ID') +'\\n')";
    initializer.setPreScript(new SimpleScript(printEnvVariables, "groovy"));
    initializer.setPostScript(new SimpleScript(printEnvVariables, "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L));
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript(printEnvVariables, "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    String[] lines = taskOutput.output().split("\\n");
    assertEquals("job@1000@task@42", lines[0]);
    assertEquals("job@1000@task@42", lines[1]);
    assertEquals("job@1000@task@42", lines[2]);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 12 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput 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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals("Hello", taskOutput.output());
}
Also used : Serializable(java.io.Serializable) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 13 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput 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("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(FlowActionType.REPLICATE, result.getAction().getType());
    assertEquals("helloflow", taskOutput.output());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 14 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput in project scheduling by ow2-proactive.

the class InProcessTaskExecutorTest method testPaUserVariableAvailabilityFromScriptEngine.

@Test
public void testPaUserVariableAvailabilityFromScriptEngine() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    String jobOwner = "JohnDoe";
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setJobOwner(jobOwner);
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print variables.get('PA_USER')", "python"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(jobOwner, taskOutput.output().trim());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) InProcessTaskExecutor(org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) Test(org.junit.Test)

Example 15 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput in project scheduling by ow2-proactive.

the class ForkedTaskExecutorTest method failToFindJava.

@Test
public void failToFindJava() throws Throwable {
    System.setProperty("java.home", "does not exist");
    TestTaskOutput taskOutput = new TestTaskOutput();
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
    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("print('hello'); result='hello'", "javascript"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertNotNull(result.getException());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)28 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)28 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)28 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)28 SimpleScript (org.ow2.proactive.scripting.SimpleScript)28 TaskScript (org.ow2.proactive.scripting.TaskScript)28 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)9 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)7 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)7 File (java.io.File)4 Serializable (java.io.Serializable)3 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)3 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)3 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1