use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId in project scheduling by ow2-proactive.
the class TaskLauncherTest method simpleTask.
@Test
public void simpleTask() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("print('pre')", "groovy"));
initializer.setPostScript(new SimpleScript("print('post')", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory()), executableContainer);
assertThat((String) taskResult.value(), is("hello"));
assertThat(taskResult.getOutput().getAllLogs(false).contains(String.format("prehellopost%n")), is(true));
}
use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId in project scheduling by ow2-proactive.
the class TaskLauncherTest method thirdPartyCredentials.
@Test
public void thirdPartyCredentials() throws Throwable {
ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(credentials.get('password'))", "groovy")));
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory());
CredData credData = new CredData("john", "pwd");
credData.addThirdPartyCredential("password", "r00t");
final KeyPairProducer keyPairProducer = new KeyPairProducer();
final TaskLauncher spy = spy(taskLauncher);
doReturn(keyPairProducer.getKeyPair()).when(spy).getKeyPair();
Credentials thirdPartyCredentials = Credentials.createCredentials(credData, spy.generatePublicKey());
executableContainer.setCredentials(thirdPartyCredentials);
TaskResult taskResult = runTaskLauncher(spy, executableContainer);
final String allLogs = taskResult.getOutput().getAllLogs(false);
assertThat(allLogs.contains(String.format("r00t%n")), is(true));
}
use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId 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());
}
use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId in project scheduling by ow2-proactive.
the class TaskLoggerTest method logPattern.
@Test
public void logPattern() throws Exception {
TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
taskLogger = new TaskLogger(taskId, "myhost");
assertEquals("", taskLogger.getLogs().getAllLogs(false));
taskLogger.getOutputSink().println("hello");
String quotedStringTaskId = Pattern.quote(taskId.toString());
assertTrue(taskLogger.getLogs().getAllLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] hello \r?\n"));
taskLogger.getErrorSink().println("error");
assertTrue(taskLogger.getLogs().getStderrLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] error \r?\n"));
}
use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId in project scheduling by ow2-proactive.
the class TaskLoggerTest method logStreaming.
@Test
public void logStreaming() 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.activateLogs(stringAppenderProvider);
assertEquals("", stringAppender.toString());
taskLogger.getOutputSink().println("hello");
// async appender, it gets buffered
assertEquals("", stringAppender.toString());
for (int i = 0; i < 1000; i++) {
taskLogger.getOutputSink().println("hello");
}
assertNotEquals("", stringAppender.toString());
}
Aggregations