use of org.ow2.proactive.scheduler.common.task.Task 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.scheduler.common.task.Task 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.scheduler.common.task.Task 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);
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class TaskLauncherTest method testProgressFileReaderIntegration.
@Test
public void testProgressFileReaderIntegration() throws Throwable {
int nbIterations = 3;
String taskScript = CharStreams.toString(new InputStreamReader(getClass().getResourceAsStream("/task-report-progress.py"), Charsets.UTF_8));
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript(taskScript, "python", new String[] { Integer.toString(nbIterations) })));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("42"), "job", 1000L));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory()), executableContainer);
List result = (List) taskResult.value();
for (int i = 1; i <= result.size(); i++) {
assertEquals(i * (100 / nbIterations), result.get(i - 1));
}
}
use of org.ow2.proactive.scheduler.common.task.Task in project scheduling by ow2-proactive.
the class TaskLoggerTest method getStoredLogs.
@Test
public void getStoredLogs() throws Exception {
taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
final StringWriter stringAppender = new StringWriter();
AppenderProvider stringAppenderProvider = new AppenderProvider() {
@Override
public Appender getAppender() throws LogForwardingException {
return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
}
};
taskLogger.getStoredLogs(stringAppenderProvider);
assertEquals("", stringAppender.toString());
taskLogger.getOutputSink().println("hello");
taskLogger.getStoredLogs(stringAppenderProvider);
assertEquals(String.format("hello%n"), stringAppender.toString());
}
Aggregations