in hugegraph-test/src/main/java/org/apache/hugegraph/core/VertexCoreTest.java [391:514]
public void testRemoveLeftRangeIndex() throws InterruptedException {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
schema.propertyKey("updateTime").asLong().create();
schema.vertexLabel("soft").properties("name", "updateTime")
.primaryKeys("name").create();
schema.indexLabel("softByUpdateTime").onV("soft").range()
.by("updateTime").create();
final long testDataCount = 10L;
for (int i = 1; i <= testDataCount; i++) {
graph.addVertex(T.label, "soft", "name", "soft" + i,
"updateTime", i);
}
this.commitTx();
long count = graph.traversal().V()
.has("soft", "updateTime",
ConditionP.gt(0))
.limit(-1)
.count()
.next();
Assert.assertEquals(testDataCount, count);
for (int i = 1; i <= testDataCount; i++) {
graph.addVertex(T.label, "soft", "name", "soft" + i,
"updateTime", 2 * i);
}
this.commitTx();
count = graph.traversal().V()
.has("soft", "updateTime",
ConditionP.gt(0))
.limit(-1)
.count()
.next();
Assert.assertEquals(testDataCount, count);
schema.propertyKey("score").asInt().create();
schema.vertexLabel("developer").properties("name", "age", "score")
.primaryKeys("name").create();
schema.indexLabel("developerByAge").onV("developer").range()
.by("age").create();
schema.indexLabel("developerByScore").onV("developer").range()
.by("score").create();
for (int i = 1; i <= testDataCount; i++) {
graph.addVertex(T.label, "developer", "name", "developer" + i,
"age", i,
"score", i);
}
this.commitTx();
count = graph.traversal().V()
.hasLabel("developer")
.has("age", ConditionP.gt(0))
.has("score", ConditionP.gt(0))
.limit(-1)
.count()
.next();
Assert.assertEquals(testDataCount, count);
for (int i = 1; i <= testDataCount; i++) {
graph.addVertex(T.label, "developer", "name", "developer" + i,
"age", i * 2,
"score", i * 2);
}
this.commitTx();
count = graph.traversal().V()
.hasLabel("developer")
.has("age", ConditionP.gt(0))
.has("score", ConditionP.gt(0))
.limit(-1)
.count()
.next();
Assert.assertEquals(testDataCount, count);
// Wait left index to be removed
Thread.sleep(2000);
count = graph.traversal().V()
.hasLabel("developer")
.has("age", ConditionP.gt(0))
.limit(-1)
.count()
.next();
// Debug stop here to see whether the left index be correctly determined
Assert.assertEquals(testDataCount, count);
// mock test removeLeftIndexIfNeeded
boolean removeLeftIndexOnOverwrite =
Whitebox.getInternalState(params().graphTransaction(),
"removeLeftIndexOnOverwrite");
Whitebox.setInternalState(params().graphTransaction(),
"removeLeftIndexOnOverwrite", true);
for (int i = 1; i <= testDataCount; i++) {
graph.addVertex(T.label, "developer", "name", "developer" + i,
"age", i * 3,
"score", i * 3);
}
this.commitTx();
if (!removeLeftIndexOnOverwrite) {
Whitebox.setInternalState(params().graphTransaction(),
"removeLeftIndexOnOverwrite", false);
}
count = graph.traversal().V()
.hasLabel("developer")
.has("age", ConditionP.gt(0))
.has("score", ConditionP.gt(0))
.limit(-1)
.count()
.next();
Assert.assertEquals(testDataCount, count);
}