use of com.baidu.hugegraph.task.HugeTask in project incubator-hugegraph by apache.
the class TaskCoreTest method testTask.
@Test
public void testTask() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
TaskCallable<Object> callable = new SleepCallable<>();
Id id = IdGenerator.of(88888);
HugeTask<?> task = new HugeTask<>(id, null, callable);
task.type("test");
task.name("test-task");
scheduler.schedule(task);
Assert.assertEquals(id, task.id());
Assert.assertFalse(task.completed());
Assert.assertThrows(IllegalArgumentException.class, () -> {
scheduler.delete(id);
}, e -> {
Assert.assertContains("Can't delete incomplete task '88888'", e.getMessage());
});
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(id, task.id());
Assert.assertEquals("test-task", task.name());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("test-task", scheduler.task(id).name());
Assert.assertEquals("test-task", scheduler.tasks(Arrays.asList(id)).next().name());
Iterator<HugeTask<Object>> iter = scheduler.tasks(ImmutableList.of(id));
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
iter = scheduler.tasks(TaskStatus.SUCCESS, 10, null);
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
iter = scheduler.tasks(null, 10, null);
Assert.assertTrue(iter.hasNext());
Assert.assertEquals("test-task", iter.next().name());
Assert.assertFalse(iter.hasNext());
scheduler.delete(id);
iter = scheduler.tasks(null, 10, null);
Assert.assertFalse(iter.hasNext());
Assert.assertThrows(NotFoundException.class, () -> {
scheduler.task(id);
});
}
use of com.baidu.hugegraph.task.HugeTask in project incubator-hugegraph by apache.
the class TaskCoreTest method setup.
@Before
@Override
public void setup() {
super.setup();
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
Iterator<HugeTask<Object>> iter = scheduler.tasks(null, -1, null);
while (iter.hasNext()) {
scheduler.delete(iter.next().id());
}
}
use of com.baidu.hugegraph.task.HugeTask 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