use of com.enonic.xp.impl.task.distributed.TaskManager in project xp by enonic.
the class TaskServiceImplTest method getTasks.
@Test
void getTasks() {
final TaskId someTaskId1 = TaskId.from("someTask1");
taskService.getTaskInfo(someTaskId1);
verify(taskManager).getTaskInfo(eq(someTaskId1));
final TaskManager taskManager = mock(TaskManager.class);
taskService.setClusteredTaskManager(taskManager);
taskService.getAllTasks();
verify(taskManager).getAllTasks();
taskService.unsetClusteredTaskManager(taskManager);
taskService.getRunningTasks();
verifyNoMoreInteractions(taskManager);
verify(this.taskManager).getRunningTasks();
}
use of com.enonic.xp.impl.task.distributed.TaskManager in project xp by enonic.
the class TaskServiceImplTest method submitTask_DescriptorKey_offload_to_clustered.
@Test
void submitTask_DescriptorKey_offload_to_clustered() {
final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
final TaskManager clusteredTaskManager = mock(TaskManager.class);
taskService.setClusteredTaskManager(clusteredTaskManager);
final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(descriptorKey).build());
verify(clusteredTaskManager).submitTask(describedTaskCaptor.capture());
describedTaskCaptor.getValue();
final DescribedTask argument = describedTaskCaptor.getValue();
assertEquals(taskId, argument.getTaskId());
}
use of com.enonic.xp.impl.task.distributed.TaskManager in project xp by enonic.
the class ClusteredTaskManagerImpl method send.
private List<TaskInfo> send(final SerializableFunction<TaskManager, List<TaskInfo>> taskFunction) {
final List<TaskInfo> taskInfoBuilder = new ArrayList<>();
final Map<Member, Future<List<TaskInfo>>> resultsFromMembers = executorService.submitToAllMembers(new TasksReporterCallable(taskFunction));
for (Future<List<TaskInfo>> responseFuture : resultsFromMembers.values()) {
try {
final List<TaskInfo> response = responseFuture.get(outboundTimeoutNs, TimeUnit.NANOSECONDS);
taskInfoBuilder.addAll(response);
} catch (TimeoutException e) {
resultsFromMembers.values().forEach(f -> f.cancel(true));
throw new RuntimeException(e);
} catch (InterruptedException | ExecutionException e) {
throw ExceptionUtil.rethrow(e);
}
}
return taskInfoBuilder;
}
use of com.enonic.xp.impl.task.distributed.TaskManager in project xp by enonic.
the class TaskServiceImpl method submitTask.
@Override
public TaskId submitTask(SubmitTaskParams params) {
TaskManager taskManager;
taskManager = clusteredTaskManagerRef.getNow(null);
if (taskManager == null) {
if (acceptOffloaded) {
LOG.debug("Clustered task manager is unavailable, falling back to local task manager.");
taskManager = localTaskManager;
} else {
try {
LOG.info("Clustered task manager is unavailable, waiting...");
taskManager = clusteredTaskManagerRef.get(5, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException e) {
throw new RuntimeException(e);
}
}
}
final DistributableTask task = new DistributableTask(params.getDescriptorKey(), params.getData(), buildContext());
taskManager.submitTask(task);
return task.getTaskId();
}
use of com.enonic.xp.impl.task.distributed.TaskManager in project xp by enonic.
the class TaskServiceImplTest method submitTask_DescriptorKey_offload_to_clustered_wait_success.
@Test
void submitTask_DescriptorKey_offload_to_clustered_wait_success() {
final DescriptorKey descriptorKey = DescriptorKey.from("module:my-admin-tool");
final TaskManager clusteredTaskManager = mock(TaskManager.class);
when(taskConfig.distributable_acceptInbound()).thenReturn(false);
taskService.activate(taskConfig);
CompletableFuture.runAsync(() -> taskService.setClusteredTaskManager(clusteredTaskManager), CompletableFuture.delayedExecutor(1, TimeUnit.SECONDS));
final TaskId taskId = taskService.submitTask(SubmitTaskParams.create().descriptorKey(descriptorKey).build());
verify(clusteredTaskManager).submitTask(describedTaskCaptor.capture());
describedTaskCaptor.getValue();
final DescribedTask argument = describedTaskCaptor.getValue();
assertEquals(taskId, argument.getTaskId());
}
Aggregations