use of com.baidu.hugegraph.task.TaskCallable in project incubator-hugegraph by apache.
the class JobBuilder method schedule.
public HugeTask<V> schedule() {
E.checkArgumentNotNull(this.name, "Job name can't be null");
E.checkArgumentNotNull(this.job, "Job callable can't be null");
E.checkArgument(this.job instanceof TaskCallable, "Job must be instance of TaskCallable");
this.graph.taskScheduler().checkRequirement("schedule");
@SuppressWarnings("unchecked") TaskCallable<V> job = (TaskCallable<V>) this.job;
HugeTask<V> task = new HugeTask<>(this.genTaskId(), null, job);
task.type(this.job.type());
task.name(this.name);
if (this.input != null) {
task.input(this.input);
}
if (this.dependencies != null && !this.dependencies.isEmpty()) {
for (Id depend : this.dependencies) {
task.depends(depend);
}
}
TaskScheduler scheduler = this.graph.taskScheduler();
scheduler.schedule(task);
return task;
}
use of com.baidu.hugegraph.task.TaskCallable in project incubator-hugegraph by apache.
the class TaskCoreTest method testTaskWithFailure.
@Test
public void testTaskWithFailure() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
TaskCallable<Integer> callable = new TaskCallable<Integer>() {
@Override
public Integer call() throws Exception {
sleepAWhile();
return 125;
}
@Override
protected void done() {
scheduler.save(this.task());
}
};
Assert.assertThrows(IllegalArgumentException.class, () -> {
new HugeTask<>(null, null, callable);
}, e -> {
Assert.assertContains("Task id can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id id = IdGenerator.of("88888");
new HugeTask<>(id, null, callable);
}, e -> {
Assert.assertContains("Invalid task id type, it must be number", e.getMessage());
});
Assert.assertThrows(NullPointerException.class, () -> {
Id id = IdGenerator.of(88888);
new HugeTask<>(id, null, null);
});
Assert.assertThrows(IllegalStateException.class, () -> {
Id id = IdGenerator.of(88888);
HugeTask<?> task2 = new HugeTask<>(id, null, callable);
task2.name("test-task");
scheduler.schedule(task2);
}, e -> {
Assert.assertContains("Task type can't be null", e.getMessage());
});
Assert.assertThrows(IllegalStateException.class, () -> {
Id id = IdGenerator.of(88888);
HugeTask<?> task2 = new HugeTask<>(id, null, callable);
task2.type("test");
scheduler.schedule(task2);
}, e -> {
Assert.assertContains("Task name can't be null", e.getMessage());
});
}
Aggregations