-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. use element id as task name 2. check whether element is already deleted 3. use async mode for HugeGraphServer Change-Id: Id8471712e2cd9b5f7cff4639b27e6c198e4d1f01 fixed: #247
- Loading branch information
Showing
5 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
hugegraph-test/src/main/java/com/baidu/hugegraph/api/TaskApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.api; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.baidu.hugegraph.testutil.Assert; | ||
|
||
import jersey.repackaged.com.google.common.collect.ImmutableList; | ||
import jersey.repackaged.com.google.common.collect.ImmutableMap; | ||
|
||
public class TaskApiTest extends BaseApiTest { | ||
|
||
private static String path = "/graphs/hugegraph/tasks/"; | ||
private static String rebuildPath = | ||
"/graphs/hugegraph/jobs/rebuild/indexlabels/personByCity"; | ||
private static String personByCity = "personByCity"; | ||
private static Map<String, Object> personByCityIL = ImmutableMap.of( | ||
"name", "personByCity", | ||
"base_type", "VERTEX_LABEL", | ||
"base_value", "person", | ||
"index_type", "SECONDARY", | ||
"fields", ImmutableList.of("city")); | ||
|
||
@Before | ||
public void prepareSchema() { | ||
BaseApiTest.initPropertyKey(); | ||
BaseApiTest.initVertexLabel(); | ||
BaseApiTest.initIndexLabel(); | ||
} | ||
|
||
@Test | ||
public void testList() { | ||
int taskId = this.rebuild(); | ||
|
||
Response r = client().get(path); | ||
String content = assertResponseStatus(200, r); | ||
List<Map<?, ?>> tasks = assertJsonContains(content, "tasks"); | ||
assertArrayContains(tasks, "id", taskId); | ||
|
||
this.waitTaskSuccess(taskId); | ||
r = client().get(path, ImmutableMap.of("status", "RUNNING")); | ||
content = assertResponseStatus(200, r); | ||
tasks = assertJsonContains(content, "tasks"); | ||
Assert.assertTrue(tasks.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGet() { | ||
int taskId = this.rebuild(); | ||
|
||
Response r = client().get(path, String.valueOf(taskId)); | ||
String content = assertResponseStatus(200, r); | ||
assertJsonContains(content, "id"); | ||
} | ||
|
||
@Test | ||
public void testDelete() { | ||
int taskId = this.rebuild(); | ||
|
||
this.waitTaskSuccess(taskId); | ||
Response r = client().delete(path, String.valueOf(taskId)); | ||
assertResponseStatus(204, r); | ||
} | ||
|
||
private int rebuild() { | ||
Response r = client().put(rebuildPath, personByCity, personByCityIL); | ||
String content = assertResponseStatus(202, r); | ||
return assertJsonContains(content, "task_id"); | ||
} | ||
|
||
private void waitTaskSuccess(int task) { | ||
String status; | ||
do { | ||
Response r = client().get(path, String.valueOf(task)); | ||
String content = assertResponseStatus(200, r); | ||
status = assertJsonContains(content, "task_status"); | ||
} while (!status.equals("success")); | ||
} | ||
} |