Search in sources :

Example 16 with TestTaskOutput

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

the class ForkedTaskExecutorTest method runAsMe_userDoesNotExist.

@Test
public void runAsMe_userDoesNotExist() throws Throwable {
    TestTaskOutput taskOutput = new TestTaskOutput();
    Decrypter decrypter = createCredentials("somebody_that_does_not_exists");
    ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
    ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "javascript")));
    container.setRunAsUser(true);
    TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", "", decrypter);
    TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
    assertNotNull(result.getException());
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) 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)

Example 17 with TestTaskOutput

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

the class ForkedTaskExecutorTest method result_and_variables.

@Test
public void result_and_variables() throws Throwable {
    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'); variables.put('var','foo'); result='hello'", "javascript"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertEquals(String.format("hello%n"), taskOutput.output());
    assertEquals("hello", result.value());
    assertEquals("foo", SerializationUtil.deserializeVariableMap(result.getPropagatedVariables()).get("var"));
}
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)

Example 18 with TestTaskOutput

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

the class ForkedTaskExecutorTest method forkEnvironment_failingEnvScript.

@Test
public void forkEnvironment_failingEnvScript() 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.setEnvScript(new SimpleScript("should fail execution", "groovy"));
    initializer.setForkEnvironment(forkEnvironment);
    TaskResultImpl taskResult = taskExecutor.execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
    assertTrue(taskResult.hadException());
}
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) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) File(java.io.File) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) Test(org.junit.Test)

Example 19 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput 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());
}
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)

Example 20 with TestTaskOutput

use of org.ow2.proactive.scheduler.task.TestTaskOutput 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());
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) TaskScript(org.ow2.proactive.scripting.TaskScript) ForkedTaskExecutor(org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TestTaskOutput(org.ow2.proactive.scheduler.task.TestTaskOutput) File(java.io.File) 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