use of com.baidu.hugegraph.job.GremlinJob in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJobWithError.
@Test
public void testGremlinJobWithError() throws TimeoutException {
HugeGraph graph = graph();
Assert.assertThrows(IllegalArgumentException.class, () -> {
JobBuilder.of(graph).job(new GremlinJob()).schedule();
}, e -> {
Assert.assertContains("Job name can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
JobBuilder.of(graph).name("test-job-gremlin").schedule();
}, e -> {
Assert.assertContains("Job callable can't be null", e.getMessage());
});
// Test failure task with big input
int length = 8 * 1024 * 1024;
Random random = new Random();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++) {
sb.append("node:").append(random.nextInt(1000));
}
String bigInput = sb.toString();
Assert.assertThrows(HugeException.class, () -> {
runGremlinJob(bigInput);
}, e -> {
Assert.assertContains("Task input size", e.getMessage());
Assert.assertContains("exceeded limit 16777216 bytes", e.getMessage());
});
}
use of com.baidu.hugegraph.job.GremlinJob in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJob.
@Test
public void testGremlinJob() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
GremlinRequest request = new GremlinRequest();
request.gremlin("sleep(100); 3 + 5");
JobBuilder<Object> builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input(request.toJson()).job(new GremlinJob());
HugeTask<Object> task = builder.schedule();
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertFalse(task.completed());
Assert.assertNull(task.result());
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("8", task.result());
task = scheduler.task(task.id());
Assert.assertEquals("test-job-gremlin", task.name());
Assert.assertEquals("gremlin", task.type());
Assert.assertEquals(TaskStatus.SUCCESS, task.status());
Assert.assertEquals("8", task.result());
}
use of com.baidu.hugegraph.job.GremlinJob in project incubator-hugegraph by apache.
the class GremlinAPI method post.
@POST
@Timed
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=gremlin_execute" })
public Map<String, Id> post(@Context GraphManager manager, @PathParam("graph") String graph, GremlinRequest request) {
LOG.debug("Graph [{}] schedule gremlin job: {}", graph, request);
checkCreatingBody(request);
GREMLIN_JOB_INPUT_HISTOGRAM.update(request.gremlin.length());
HugeGraph g = graph(manager, graph);
request.aliase(graph, "graph");
JobBuilder<Object> builder = JobBuilder.of(g);
builder.name(request.name()).input(request.toJson()).job(new GremlinJob());
return ImmutableMap.of("task_id", builder.schedule().id());
}
use of com.baidu.hugegraph.job.GremlinJob in project incubator-hugegraph by apache.
the class SecurityManagerTest method runGremlinJob.
private static String runGremlinJob(String gremlin) {
JobBuilder<Object> builder = JobBuilder.of(graph);
Map<String, Object> input = new HashMap<>();
input.put("gremlin", gremlin);
input.put("bindings", ImmutableMap.of());
input.put("language", "gremlin-groovy");
input.put("aliases", ImmutableMap.of());
builder.name("test-gremlin-job").input(JsonUtil.toJson(input)).job(new GremlinJob());
HugeTask<?> task = builder.schedule();
try {
task = graph.taskScheduler().waitUntilTaskCompleted(task.id(), 10);
} catch (TimeoutException e) {
throw new HugeException("Wait for task timeout: %s", e, task);
}
return task.result();
}
use of com.baidu.hugegraph.job.GremlinJob in project incubator-hugegraph by apache.
the class TaskCoreTest method testGremlinJobWithFailure.
@Test
public void testGremlinJobWithFailure() throws TimeoutException {
HugeGraph graph = graph();
TaskScheduler scheduler = graph.taskScheduler();
JobBuilder<Object> builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("").job(new GremlinJob());
HugeTask<Object> task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Can't read json", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").job(new GremlinJob());
task = builder.schedule();
scheduler.waitUntilTaskCompleted(task.id(), 10);
task = scheduler.task(task.id());
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("The input can't be null", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid gremlin value 'null'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":8}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid gremlin value '8'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\"}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid bindings value 'null'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\", \"bindings\":\"\"}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid bindings value ''", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\", \"bindings\":{}}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid language value 'null'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\", \"bindings\":{}, \"language\":{}}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid language value '{}'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\", \"bindings\":{}, \"language\":\"\"}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("Invalid aliases value 'null'", task.result());
builder = JobBuilder.of(graph);
builder.name("test-job-gremlin").input("{\"gremlin\":\"\", \"bindings\":{}, " + "\"language\":\"test\", \"aliases\":{}}").job(new GremlinJob());
task = builder.schedule();
task = scheduler.waitUntilTaskCompleted(task.id(), 10);
Assert.assertEquals(TaskStatus.FAILED, task.status());
Assert.assertContains("test is not an available GremlinScriptEngine", task.result());
}
Aggregations