use of org.infinispan.tasks.Task in project infinispan by infinispan.
the class SecureScriptingTaskManagerTest method testTask.
public void testTask() throws Exception {
Security.doAs(PHEIDIPPIDES, new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
String result = CompletionStages.join(taskManager.runTask(SCRIPT_NAME, new TaskContext().addParameter("a", "a")));
assertEquals("a", result);
return null;
}
});
List<Task> tasks = taskManager.getTasks();
assertEquals(1, tasks.size());
ScriptTask scriptTask = (ScriptTask) tasks.get(0);
assertEquals(SCRIPT_NAME, scriptTask.getName());
assertEquals(TaskExecutionMode.ONE_NODE, scriptTask.getExecutionMode());
assertEquals("Script", scriptTask.getType());
}
use of org.infinispan.tasks.Task in project infinispan by infinispan.
the class ScriptingTaskManagerTest method testTask.
public void testTask() throws Exception {
ScriptingManager scriptingManager = extractGlobalComponent(cacheManager, ScriptingManager.class);
ScriptingUtils.loadScript(scriptingManager, TEST_SCRIPT);
String result = CompletionStages.join(taskManager.runTask(TEST_SCRIPT, new TaskContext().addParameter("a", "a")));
assertEquals("a", result);
List<Task> tasks = taskManager.getTasks();
assertEquals(1, tasks.size());
ScriptTask scriptTask = (ScriptTask) tasks.get(0);
assertEquals("test.js", scriptTask.getName());
assertEquals(TaskExecutionMode.ONE_NODE, scriptTask.getExecutionMode());
assertEquals("Script", scriptTask.getType());
}
use of org.infinispan.tasks.Task in project infinispan by infinispan.
the class ServerTaskEngine method invokeTask.
private <T> CompletableFuture<T> invokeTask(TaskContext context, ServerTaskWrapper<T> task) {
ServerTaskRunner runner;
switch(task.getExecutionMode()) {
case ONE_NODE:
runner = localRunner;
break;
default:
runner = distributedRunner;
break;
}
launderParameters(context);
MediaType requestMediaType = context.getCache().map(c -> c.getAdvancedCache().getValueDataConversion().getRequestMediaType()).orElse(MediaType.MATCH_ALL);
context.getCache().ifPresent(c -> context.cache(c.getAdvancedCache().withMediaType(APPLICATION_OBJECT, APPLICATION_OBJECT)));
return runner.execute(task.getName(), context).thenApply(r -> (T) scriptConversions.convertToRequestType(r, APPLICATION_OBJECT, requestMediaType));
}
Aggregations