From 2e0deac4af0e465588d742bc22d587aa8df05e97 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Tue, 29 Mar 2022 18:35:27 +0800 Subject: [PATCH 1/7] fix query by within + Text.contains fix #1794 Change-Id: I4f4f2f52b6986ca5af9a27ee4677e16387235c0b --- .../hugegraph/backend/page/QueryList.java | 13 +++++++ .../backend/query/ConditionQuery.java | 19 ++++++++-- .../backend/tx/GraphIndexTransaction.java | 36 ++++++++++++++----- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java index 9739e329a3..4e20945863 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/page/QueryList.java @@ -219,6 +219,7 @@ public QueryResults iterator() { private QueryResults each(IdHolder holder) { assert !holder.paging(); Query bindQuery = holder.query(); + this.updateResultsFilter(bindQuery); this.updateOffsetIfNeeded(bindQuery); // Iterate by all @@ -267,6 +268,8 @@ public PageResults iterator(int index, String page, long pageSize) { E.checkArgument(0 <= index && index <= this.holders.size(), "Invalid page index %s", index); IdHolder holder = this.holders.get(index); + Query bindQuery = holder.query(); + this.updateResultsFilter(bindQuery); PageIds pageIds = holder.fetchNext(page, pageSize); if (pageIds.empty()) { return PageResults.emptyIterator(); @@ -298,6 +301,16 @@ private void updateOffsetIfNeeded(Query query) { query.copyOffset(parent); } + private void updateResultsFilter(Query query) { + while (query != null) { + if (query instanceof ConditionQuery) { + ((ConditionQuery) query).updateResultsFilter(); + return; + } + query = query.originQuery(); + } + } + private QueryResults queryByIndexIds(Set ids) { return this.queryByIndexIds(ids, false); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java index a2fda90dad..f988a5aa06 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java @@ -618,11 +618,26 @@ public OptimizedType optimized() { public void registerResultsFilter(Function filter) { assert this.resultsFilter == null; this.resultsFilter = filter; + } + public void updateResultsFilter() { Query originQuery = this.originQuery(); if (originQuery instanceof ConditionQuery) { - ConditionQuery cq = ((ConditionQuery) originQuery); - cq.registerResultsFilter(filter); + ConditionQuery originCQ = ((ConditionQuery) originQuery); + if (this.resultsFilter != null) { + originCQ.updateResultsFilter(this.resultsFilter); + } else { + originCQ.updateResultsFilter(); + } + } + } + + protected void updateResultsFilter(Function filter) { + this.resultsFilter = filter; + Query originQuery = this.originQuery(); + if (originQuery instanceof ConditionQuery) { + ConditionQuery originCQ = ((ConditionQuery) originQuery); + originCQ.updateResultsFilter(filter); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java index d497cb9e6a..740e5a91e8 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java @@ -1053,7 +1053,7 @@ private static Set matchRangeOrSearchIndexLabels( private static IndexQueries buildJointIndexesQueries(ConditionQuery query, MatchedIndex index) { - IndexQueries queries = new IndexQueries(); + IndexQueries queries = IndexQueries.of(query); List allILs = new ArrayList<>(index.indexLabels()); // Handle range/search indexes @@ -1174,7 +1174,7 @@ private static IndexQueries constructJointSecondaryQueries( private static IndexQueries constructQueries(ConditionQuery query, Set ils, Set propKeys) { - IndexQueries queries = new IndexQueries(); + IndexQueries queries = IndexQueries.of(query); for (IndexLabel il : ils) { List fields = il.indexFields(); @@ -1627,15 +1627,25 @@ private static class IndexQueries extends HashMap { private static final long serialVersionUID = 1400326138090922676L; + private static final IndexQueries EMPTY = new IndexQueries(null); - public static final IndexQueries EMPTY = new IndexQueries(); + private final ConditionQuery parentQuery; + + public IndexQueries(ConditionQuery parentQuery) { + this.parentQuery = parentQuery; + } public static IndexQueries of(IndexLabel il, ConditionQuery query) { - IndexQueries indexQueries = new IndexQueries(); + IndexQueries indexQueries = new IndexQueries(query); indexQueries.put(il, query); return indexQueries; } + public static IndexQueries of(ConditionQuery parentQuery) { + IndexQueries indexQueries = new IndexQueries(parentQuery); + return indexQueries; + } + public boolean oomRisk() { for (Query subQuery : this.values()) { if (subQuery.bigCapacity() && subQuery.aggregate() != null) { @@ -1660,26 +1670,36 @@ public Query rootQuery() { public Query asJointQuery() { @SuppressWarnings({ "unchecked", "rawtypes" }) - Collection queries = (Collection) this.values();; - return new JointQuery(this.rootQuery().resultType(), queries); + Collection queries = (Collection) this.values(); + return new JointQuery(this.rootQuery().resultType(), + this.parentQuery, queries); } private static class JointQuery extends Query { private final Collection queries; + private final ConditionQuery parentQuery; - public JointQuery(HugeType type, Collection queries) { + public JointQuery(HugeType type, ConditionQuery parentQuery, + Collection queries) { super(type, parent(queries)); + this.parentQuery = parentQuery; this.queries = queries; } @Override public Query originQuery() { + return this.parentQuery; + } + + @SuppressWarnings("unused") + public Query originJointQuery() { List origins = new ArrayList<>(); for (Query q : this.queries) { origins.add(q.originQuery()); } - return new JointQuery(this.resultType(), origins); + return new JointQuery(this.resultType(), + this.parentQuery, origins); } @Override From 7926f6b2c59b93f18ca28e531a73dd75e812d998 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Tue, 29 Mar 2022 21:08:05 +0800 Subject: [PATCH 2/7] add test Change-Id: If9f66400b64f4c7835c58e1ce46f12b3a47c5e8d --- .../baidu/hugegraph/core/VertexCoreTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index 674f0e1ec5..bb7bbdaee6 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -5191,6 +5191,68 @@ public void testQueryByJointIndexesWithTwoSearchAndOneRangeIndexes() { Assert.assertEquals(0, vertices.size()); } + @Test + public void testQueryByJointIndexesWithSearchAndTwoRangeIndexesAndWithin() { + SchemaManager schema = graph().schema(); + + schema.propertyKey("type").asInt().ifNotExist().create(); + schema.propertyKey("kid").asInt().ifNotExist().create(); + schema.propertyKey("name").asText().ifNotExist().create(); + schema.propertyKey("confirmType").asInt().ifNotExist().create(); + + schema.vertexLabel("test") + .properties("confirmType", "name", "kid", "type") + .nullableKeys("confirmType", "name", "type") + .primaryKeys("kid") + .ifNotExist().create(); + + schema.indexLabel("test_by_type") + .onV("test").by("type") + .range() + .ifNotExist().create(); + schema.indexLabel("test_by_confirmType") + .onV("test").by("confirmType") + .range() + .ifNotExist().create(); + schema.indexLabel("test_by_name") + .onV("test").by("name") + .search() + .ifNotExist().create(); + + HugeGraph graph = graph(); + + graph.addVertex(T.label, "test", "name", "诚信", + "confirmType", 0, "type", 0, "kid", 0); + graph.addVertex(T.label, "test", "name", "诚信", + "confirmType", 1, "type", 1, "kid", 1); + graph.addVertex(T.label, "test", "name", "诚信文明", + "confirmType", 2, "type", 1, "kid", 2); + graph.addVertex(T.label, "test", "name", "诚信文明", + "confirmType", 3, "type", 1, "kid", 3); + + List vertices; + vertices = graph().traversal().V() + .has("type", 1) + .has("confirmType", P.within(0, 1, 2, 3)) + .has("name", Text.contains("诚信")) + .toList(); + Assert.assertEquals(3, vertices.size()); + + vertices = graph().traversal().V() + .has("type", 1) + .has("confirmType", P.within(0, 1, 2, 3)) + .has("name", Text.contains("文明")) + .toList(); + Assert.assertEquals(2, vertices.size()); + + vertices = graph().traversal().V() + .has("type", 0) + .has("confirmType", P.within(0, 1, 3)) + .has("name", Text.contains("诚信")) + .toList(); + Assert.assertEquals(1, vertices.size()); + } + @Test public void testQueryByShardIndex() { SchemaManager schema = graph().schema(); From 76a73221f4af0ab4a745bc1588fd7032a3e90049 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Thu, 31 Mar 2022 13:52:20 +0800 Subject: [PATCH 3/7] improve resultfilter Change-Id: Id01555720f5df5e9282fdeccc38ca12fe33808c6 --- .../hugegraph/backend/query/Condition.java | 1 + .../backend/query/ConditionQuery.java | 111 ++++++++++-------- .../backend/tx/GraphIndexTransaction.java | 29 ++--- 3 files changed, 80 insertions(+), 61 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java index ecf7ac87a2..6be1b6eb4c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/Condition.java @@ -74,6 +74,7 @@ public enum RelationType implements BiPredicate { ((Id) v1).asBytes()); }), TEXT_CONTAINS("textcontains", String.class, String.class, (v1, v2) -> { + // TODO: support collection-property textcontains return v1 != null && ((String) v1).contains((String) v2); }), TEXT_CONTAINS_ANY("textcontainsany", String.class, Collection.class, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java index f988a5aa06..fcb2fe9507 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/query/ConditionQuery.java @@ -47,7 +47,6 @@ import com.baidu.hugegraph.util.InsertionOrderUtil; import com.baidu.hugegraph.util.LongEncoding; import com.baidu.hugegraph.util.NumericUtil; -import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -79,7 +78,7 @@ public class ConditionQuery extends IdQuery { private List conditions = EMPTY_CONDITIONS; private OptimizedType optimizedType = OptimizedType.NONE; - private Function resultsFilter = null; + private ResultsFilter resultsFilter = null; private Element2IndexValueMap element2IndexValueMap = null; public ConditionQuery(HugeType resultType) { @@ -173,20 +172,11 @@ public void resetConditions() { } public void recordIndexValue(Id propertyId, Id id, Object indexValue) { - this.ensureElement2IndexValueMap(); - this.element2IndexValueMap.addIndexValue(propertyId, id, indexValue); + this.element2IndexValueMap().addIndexValue(propertyId, id, indexValue); } public void selectedIndexField(Id indexField) { - this.ensureElement2IndexValueMap(); - this.element2IndexValueMap.selectedIndexField(indexField); - } - - public Set getElementLeftIndex(Id elementId) { - if (this.element2IndexValueMap == null) { - return null; - } - return this.element2IndexValueMap.getLeftIndex(elementId); + this.element2IndexValueMap().selectedIndexField(indexField); } public void removeElementLeftIndex(Id elementId) { @@ -197,7 +187,21 @@ public void removeElementLeftIndex(Id elementId) { } public boolean existLeftIndex(Id elementId) { - return this.getElementLeftIndex(elementId) != null; + return this.getLeftIndexOfElement(elementId) != null; + } + + public Set getLeftIndexOfElement(Id elementId) { + if (this.element2IndexValueMap == null) { + return null; + } + return this.element2IndexValueMap.getLeftIndex(elementId); + } + + private Element2IndexValueMap element2IndexValueMap() { + if (this.element2IndexValueMap == null) { + this.element2IndexValueMap = new Element2IndexValueMap(); + } + return this.element2IndexValueMap; } public List relations() { @@ -548,14 +552,26 @@ public boolean test(HugeElement element) { return false; } - if (this.resultsFilter != null) { - return this.resultsFilter.apply(element); + /* + * Currently results-filter is used to filter unmatched results returned + * by search index, and there may be multiple results-filter for every + * sub-query like within() + Text.contains(). + * We can't use sub-query results-filter here for fresh element which is + * not committed to backend store, because it's not from a sub-query. + */ + if (this.resultsFilter != null && !element.fresh()) { + return this.resultsFilter.test(element); } + + /* + * NOTE: seems need to keep call checkRangeIndex() for each condition, + * so don't break early even if test() return false. + */ boolean valid = true; for (Condition cond : this.conditions) { valid &= cond.test(element); - valid &= (this.element2IndexValueMap == null || - this.element2IndexValueMap.validRangeIndex(element, cond)); + valid &= this.element2IndexValueMap == null || + this.element2IndexValueMap.checkRangeIndex(element, cond); } return valid; } @@ -615,7 +631,7 @@ public OptimizedType optimized() { return this.optimizedType; } - public void registerResultsFilter(Function filter) { + public void registerResultsFilter(ResultsFilter filter) { assert this.resultsFilter == null; this.resultsFilter = filter; } @@ -632,7 +648,7 @@ public void updateResultsFilter() { } } - protected void updateResultsFilter(Function filter) { + protected void updateResultsFilter(ResultsFilter filter) { this.resultsFilter = filter; Query originQuery = this.originQuery(); if (originQuery instanceof ConditionQuery) { @@ -653,12 +669,6 @@ public ConditionQuery originConditionQuery() { return (ConditionQuery) originQuery; } - private void ensureElement2IndexValueMap() { - if (this.element2IndexValueMap == null) { - this.element2IndexValueMap = new Element2IndexValueMap(); - } - } - public static String concatValues(List values) { assert !values.isEmpty(); List newValues = new ArrayList<>(values.size()); @@ -732,7 +742,7 @@ public Element2IndexValueMap() { public void addIndexValue(Id indexField, Id elementId, Object indexValue) { if (!this.filed2IndexValues.containsKey(indexField)) { - this.filed2IndexValues.put(indexField, new HashMap<>()); + this.filed2IndexValues.putIfAbsent(indexField, new HashMap<>()); } Map> element2IndexValueMap = this.filed2IndexValues.get(indexField); @@ -748,15 +758,15 @@ public void selectedIndexField(Id indexField) { this.selectedIndexField = indexField; } - public Set removeIndexValues(Id indexField, Id elementId) { + public Set toRemoveIndexValues(Id indexField, Id elementId) { if (!this.filed2IndexValues.containsKey(indexField)) { return null; } return this.filed2IndexValues.get(indexField).get(elementId); } - public void addLeftIndex(Id indexField, Set indexValues, - Id elementId) { + public void addLeftIndex(Id elementId, Id indexField, + Set indexValues) { LeftIndex leftIndex = new LeftIndex(indexValues, indexField); if (this.leftIndexMap.containsKey(elementId)) { this.leftIndexMap.get(elementId).add(leftIndex); @@ -773,7 +783,7 @@ public void removeElementLeftIndex(Id elementId) { this.leftIndexMap.remove(elementId); } - public boolean validRangeIndex(HugeElement element, Condition cond) { + public boolean checkRangeIndex(HugeElement element, Condition cond) { // Not UserpropRelation if (!(cond instanceof Condition.UserpropRelation)) { return true; @@ -782,35 +792,36 @@ public boolean validRangeIndex(HugeElement element, Condition cond) { Condition.UserpropRelation propRelation = (Condition.UserpropRelation) cond; Id propId = propRelation.key(); - Set fieldValues = this.removeIndexValues(propId, - element.id()); + Set fieldValues = this.toRemoveIndexValues(propId, + element.id()); if (fieldValues == null) { // Not range index return true; } - HugeProperty hugeProperty = element.getProperty(propId); - if (hugeProperty == null) { - // Property value has been deleted - this.addLeftIndex(propId, fieldValues, element.id()); + HugeProperty property = element.getProperty(propId); + if (property == null) { + // Property value has been deleted, so it's not matched + this.addLeftIndex(element.id(), propId, fieldValues); return false; } /* - * NOTE: If success remove means has correct index, - * we should add left index values to left index map - * waiting to be removed + * NOTE: If removing successfully means there is correct index, + * else we should add left-index values to left index map to + * wait the left-index to be removed. */ - boolean hasRightValue = removeValue(fieldValues, hugeProperty.value()); + boolean hasRightValue = removeFieldValue(fieldValues, + property.value()); if (fieldValues.size() > 0) { - this.addLeftIndex(propId, fieldValues, element.id()); + this.addLeftIndex(element.id(), propId, fieldValues); } /* * NOTE: When query by more than one range index field, * if current field is not the selected one, it can only be used to * determine whether the index values matched, can't determine - * the element is valid or not + * the element is valid or not. */ if (this.selectedIndexField != null) { return !propId.equals(this.selectedIndexField) || hasRightValue; @@ -819,10 +830,11 @@ public boolean validRangeIndex(HugeElement element, Condition cond) { return hasRightValue; } - private static boolean removeValue(Set values, Object value){ - for (Object compareValue : values) { - if (numberEquals(compareValue, value)) { - values.remove(compareValue); + private static boolean removeFieldValue(Set values, + Object value){ + for (Object elem : values) { + if (numberEquals(elem, value)) { + values.remove(elem); return true; } } @@ -862,4 +874,9 @@ public Id indexField() { return this.indexField; } } + + public static interface ResultsFilter { + + public boolean test(HugeElement element); + } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java index 740e5a91e8..3397cc3f6a 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphIndexTransaction.java @@ -828,7 +828,7 @@ private MatchedIndex collectMatchedIndex(SchemaLabel schemaLabel, private ConditionQuery constructSearchQuery(ConditionQuery query, MatchedIndex index) { - ConditionQuery originQuery = query; + ConditionQuery newQuery = query; Set indexFields = new HashSet<>(); // Convert has(key, text) to has(key, textContainsAny(word1, word2)) for (IndexLabel il : index.indexLabels()) { @@ -836,39 +836,40 @@ private ConditionQuery constructSearchQuery(ConditionQuery query, continue; } Id indexField = il.indexField(); - String fieldValue = (String) query.userpropValue(indexField); + String fieldValue = (String) newQuery.userpropValue(indexField); Set words = this.segmentWords(fieldValue); indexFields.add(indexField); - query = query.copy(); - query.unsetCondition(indexField); - query.query(Condition.textContainsAny(indexField, words)); + newQuery = newQuery.copy(); + newQuery.unsetCondition(indexField); + newQuery.query(Condition.textContainsAny(indexField, words)); } // Register results filter to compare property value and search text - query.registerResultsFilter(elem -> { - for (Condition cond : originQuery.conditions()) { - Object key = cond.isRelation() ? ((Relation) cond).key() : null; + newQuery.registerResultsFilter(element -> { + assert element != null; + for (Condition cond : query.conditions()) { + Object key = cond.isRelation() ? + ((Relation) cond).key() : null; if (key instanceof Id && indexFields.contains(key)) { // This is an index field of search index Id field = (Id) key; - assert elem != null; - HugeProperty property = elem.getProperty(field); + HugeProperty property = element.getProperty(field); String propValue = propertyValueToString(property.value()); - String fieldValue = (String) originQuery.userpropValue(field); + String fieldValue = (String) query.userpropValue(field); if (this.matchSearchIndexWords(propValue, fieldValue)) { continue; } return false; } - if (!cond.test(elem)) { + if (!cond.test(element)) { return false; } } return true; }); - return query; + return newQuery; } private boolean matchSearchIndexWords(String propValue, String fieldValue) { @@ -1732,7 +1733,7 @@ private RemoveLeftIndexJob(ConditionQuery query, HugeElement element) { this.query = query; this.element = element; this.tx = null; - this.leftIndexes = query.getElementLeftIndex(element.id()); + this.leftIndexes = query.getLeftIndexOfElement(element.id()); } @Override From e6029e2b83dcb0279a1ffc83c97c9102996a3fdd Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Thu, 31 Mar 2022 14:14:18 +0800 Subject: [PATCH 4/7] improve test Change-Id: I6967afa8969ecdc16013d1217542da200e5b09ca --- .../baidu/hugegraph/core/BaseCoreTest.java | 9 ++++ .../baidu/hugegraph/core/VertexCoreTest.java | 42 +++++++++---------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java index 59556ab2cf..cfa30b193c 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java @@ -19,6 +19,8 @@ package com.baidu.hugegraph.core; +import java.util.Random; + import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.junit.After; @@ -102,6 +104,13 @@ private void clearSchema() { }); } + protected void mayCommitTx() { + // Commit tx probabilistically for test + if (new Random().nextBoolean()) { + graph().tx().commit(); + } + } + protected BackendFeatures storeFeatures() { return graph().backendStoreFeatures(); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index bb7bbdaee6..c3e25f8cad 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -595,16 +595,17 @@ public void testAddVertexWithCollectionIndex() { schema.vertexLabel("soft").properties("name", "tags", "score", "country", "category") - .primaryKeys("name").create(); + .primaryKeys("name") + .create(); - schema.indexLabel("softByTag").onV("soft").secondary() - .by("tags").create(); + schema.indexLabel("softByTag").onV("soft").by("tags") + .secondary().create(); - schema.indexLabel("softByCategory").onV("soft").search() - .by("category").create(); + schema.indexLabel("softByScore").onV("soft").by("score") + .secondary().create(); - schema.indexLabel("softByScore").onV("soft").secondary() - .by("score").create(); + schema.indexLabel("softByCategory").onV("soft").by("category") + .search().create(); HugeGraph graph = graph(); @@ -627,7 +628,7 @@ public void testAddVertexWithCollectionIndex() { ImmutableList.of("hello graph", "graph database"), "tags", ImmutableList.of("graphdb", "gremlin")); - graph.tx().commit(); + this.mayCommitTx(); List vertices; vertices = graph.traversal().V() @@ -643,27 +644,23 @@ public void testAddVertexWithCollectionIndex() { Assert.assertEquals(2, vertices.size()); Assert.assertThrows(IllegalStateException.class, () -> { - graph.traversal().V().has("soft", "tags", - "gremlin").toList(); + graph.traversal().V().has("soft", "tags", "gremlin").toList(); }); // query by contains vertices = graph.traversal().V() - .has("soft", "tags", - ConditionP.contains("gremlin")) + .has("soft", "tags", ConditionP.contains("gremlin")) .toList(); Assert.assertEquals(2, vertices.size()); // secondary-index with list/set of number properties vertices = graph.traversal().V() - .has("soft", "score", - ConditionP.contains(5)) + .has("soft", "score", ConditionP.contains(5)) .toList(); Assert.assertEquals(3, vertices.size()); vertices = graph.traversal().V() - .has("soft", "name", - "hugegraph").toList(); + .has("soft", "name", "hugegraph").toList(); Assert.assertEquals(1, vertices.size()); // add a new tag @@ -672,17 +669,18 @@ public void testAddVertexWithCollectionIndex() { graph.tx().commit(); vertices = graph.traversal().V() - .has("soft", "tags", - ConditionP.contains("new_tag")).toList(); + .has("soft", "tags", ConditionP.contains("new_tag")) + .toList(); Assert.assertEquals(1, vertices.size()); // delete tag gremlin vertex = graph.addVertex(T.label, "soft", "name", "hugegraph", "country", "china", "score", ImmutableList.of(5, 4, 3), - "category", - ImmutableList.of("hello graph", "graph database"), - "tags", ImmutableList.of("graphdb", "new_tag")); + "category", ImmutableList.of("hello graph", + "graph database"), + "tags", ImmutableList.of("graphdb", + "new_tag")); graph.tx().commit(); vertices = graph.traversal().V() @@ -5230,6 +5228,8 @@ public void testQueryByJointIndexesWithSearchAndTwoRangeIndexesAndWithin() { graph.addVertex(T.label, "test", "name", "诚信文明", "confirmType", 3, "type", 1, "kid", 3); + this.mayCommitTx(); + List vertices; vertices = graph().traversal().V() .has("type", 1) From 6a6d99c958a763d3dfd422cf64ab34518d7caaf4 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Thu, 31 Mar 2022 14:15:14 +0800 Subject: [PATCH 5/7] fix warnings Change-Id: Ib5292546a57e594228c5967972f2600cd7129ae0 --- .../com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java | 1 - .../hugegraph/api/traversers/ResourceAllocationAPITest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java index 04a1b67ab5..4d65c274a8 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/AdamicAdarAPITest.java @@ -48,7 +48,6 @@ public void testGet() { String markoId = name2Ids.get("marko"); String joshId = name2Ids.get("josh"); - String peterId = name2Ids.get("peter"); Response r = client().get(PATH, ImmutableMap.of("vertex", id2Json(markoId), "other", diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java index ede6b7031e..72101e68eb 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/api/traversers/ResourceAllocationAPITest.java @@ -48,7 +48,6 @@ public void testGet() { String markoId = name2Ids.get("marko"); String joshId = name2Ids.get("josh"); - String peterId = name2Ids.get("peter"); Response r = client().get(PATH, ImmutableMap.of("vertex", id2Json(markoId), "other", From f293145d79e6799e4f726a88a6bbebd75bbb4d88 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Thu, 31 Mar 2022 20:25:30 +0800 Subject: [PATCH 6/7] improve test: add mayCommitTx() Change-Id: Iefc59747a2cb300a927a48c68a79d4988bc30b12 --- .../backend/tx/GraphTransaction.java | 26 +- .../baidu/hugegraph/core/BaseCoreTest.java | 4 + .../baidu/hugegraph/core/VertexCoreTest.java | 568 ++++++++++-------- 3 files changed, 357 insertions(+), 241 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java index 0adbaa3124..a035a5560b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java @@ -777,9 +777,16 @@ public Iterator queryVertices() { } public Iterator queryVertices(Query query) { - E.checkArgument(this.removedVertices.isEmpty() || query.noLimit(), - "It's not allowed to query with limit when " + - "there are uncommitted delete records."); + if (this.hasUpdate()) { + E.checkArgument(this.removedVertices.isEmpty() || + query.noLimitAndOffset(), + "It's not allowed to query with offser/limit " + + "when there are uncommitted delete records."); + // TODO: also add check: no SCAN, no OLAP + E.checkArgument(!query.paging(), + "It's not allowed to query by paging when " + + "there are uncommitted records."); + } query.resetActualOffset(); @@ -935,9 +942,16 @@ public Iterator queryEdges() { @Watched public Iterator queryEdges(Query query) { - E.checkArgument(this.removedEdges.isEmpty() || query.noLimit(), - "It's not allowed to query with limit when " + - "there are uncommitted delete records."); + if (this.hasUpdate()) { + E.checkArgument(this.removedEdges.isEmpty() || + query.noLimitAndOffset(), + "It's not allowed to query with offser/limit " + + "when there are uncommitted delete records."); + // TODO: also add check: no SCAN, no OLAP + E.checkArgument(!query.paging(), + "It's not allowed to query by paging when " + + "there are uncommitted records."); + } query.resetActualOffset(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java index cfa30b193c..43118961ee 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java @@ -111,6 +111,10 @@ protected void mayCommitTx() { } } + protected void commitTx() { + graph().tx().commit(); + } + protected BackendFeatures storeFeatures() { return graph().backendStoreFeatures(); } diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index c3e25f8cad..28f7f494f0 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -205,7 +205,7 @@ public void testAddVertex() { "city", "Beijing", "age", 20); graph.addVertex(T.label, "person", "name", "Hebe", "city", "Taipei", "age", 21); - graph.tx().commit(); + this.commitTx(); long count = graph.traversal().V().count().next(); Assert.assertEquals(6, count); @@ -324,7 +324,7 @@ public void testAddVertexWithPropertyList() { Vertex vertex = graph.addVertex(T.label, "review", "id", 1, "comment", "looks good!", "comment", "LGTM!"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("review", "id", 1); Assert.assertEquals(ImmutableList.of("looks good!", "LGTM!"), @@ -337,7 +337,7 @@ public void testAddVertexWithPropertyList() { vertex = graph.addVertex(T.label, "review", "id", 2, "comment", ImmutableList.of("looks good 2!", "LGTM!")); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("review", "id", 2); Assert.assertEquals(ImmutableList.of("looks good 2!", "LGTM!"), @@ -350,7 +350,7 @@ public void testAddVertexWithPropertyList() { vertex = graph.addVertex(T.label, "review", "id", 3, "comment", new String[]{"looks good 3!", "LGTM!"}); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("review", "id", 3); Assert.assertEquals(ImmutableList.of("looks good 3!", "LGTM!"), @@ -408,7 +408,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { graph.addVertex(T.label, "soft", "name", "soft" + i, "updateTime", i); } - graph.tx().commit(); + this.commitTx(); long count = graph.traversal().V() .has("soft", "updateTime", @@ -422,7 +422,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { graph.addVertex(T.label, "soft", "name", "soft" + i, "updateTime", 2 * i); } - graph.tx().commit(); + this.commitTx(); count = graph.traversal().V() .has("soft", "updateTime", @@ -446,7 +446,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { "age", i, "score", i); } - graph.tx().commit(); + this.commitTx(); count = graph.traversal().V() .hasLabel("developer") @@ -462,7 +462,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { "age", i * 2, "score", i * 2); } - graph.tx().commit(); + this.commitTx(); count = graph.traversal().V() .hasLabel("developer") @@ -498,7 +498,7 @@ public void testRemoveLeftRangeIndex() throws InterruptedException { "age", i * 3, "score", i * 3); } - graph.tx().commit(); + this.commitTx(); if (!removeLeftIndexOnOverwrite) { Whitebox.setInternalState(params().graphTransaction(), @@ -535,7 +535,7 @@ public void testLeftUnionIndex(){ graph.addVertex(T.label, "soft", "name", "soft" + i, "country", "china", "updateTime", i); } - graph.tx().commit(); + this.commitTx(); long count = graph.traversal().V() .hasLabel("soft") @@ -550,7 +550,7 @@ public void testLeftUnionIndex(){ graph.addVertex(T.label, "soft", "name", "soft" + i, "country", "china", "updateTime", i * 2); } - graph.tx().commit(); + this.commitTx(); count = graph.traversal().V() .hasLabel("soft") @@ -569,7 +569,7 @@ public void testAddVertexWithPropertySet() { "contribution", "+1", "contribution", "+2", "contribution", "+2"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("review", "id", 1); Assert.assertEquals(ImmutableSet.of("+1", "+2"), @@ -578,7 +578,7 @@ public void testAddVertexWithPropertySet() { vertex = graph.addVertex(T.label, "review", "id", 2, "contribution", ImmutableSet.of("+1", "+1", "+2")); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("review", "id", 2); Assert.assertEquals(ImmutableSet.of("+1", "+2"), @@ -628,7 +628,8 @@ public void testAddVertexWithCollectionIndex() { ImmutableList.of("hello graph", "graph database"), "tags", ImmutableList.of("graphdb", "gremlin")); - this.mayCommitTx(); + // TODO: test mayCommitTx() after support textContains(collection, str) + this.commitTx(); List vertices; vertices = graph.traversal().V() @@ -666,7 +667,8 @@ public void testAddVertexWithCollectionIndex() { // add a new tag Vertex vertex = vertices.get(0); vertex.property("tags", ImmutableSet.of("new_tag")); - graph.tx().commit(); + + this.commitTx(); vertices = graph.traversal().V() .has("soft", "tags", ConditionP.contains("new_tag")) @@ -681,7 +683,7 @@ public void testAddVertexWithCollectionIndex() { "graph database"), "tags", ImmutableList.of("graphdb", "new_tag")); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V() .has("soft", "tags", ConditionP.contains("gremlin")) @@ -700,7 +702,7 @@ public void testAddVertexWithCollectionIndex() { // remove vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V() .has("soft", "tags", ConditionP.contains("new_tag")) @@ -778,6 +780,8 @@ public void testAddVertexWithAppendedNullableKeysAbsent() { // Absent 'age' and 'city' Vertex vertex = graph().addVertex(T.label, "person", "name", "Baby"); Assert.assertEquals("Baby", vertex.value("name")); + + this.mayCommitTx(); } @Test @@ -805,7 +809,7 @@ public void testAddVertexWithDefaultPropertyValue() { Assert.assertFalse(vertex.values("cnt").hasNext()); Assert.assertFalse(vertex.values("age").hasNext()); - graph().tx().commit(); + this.commitTx(); // Exist 'fav' after commit then query vertex = graph().vertex(vertex.id()); @@ -879,7 +883,7 @@ public void testAddVertexWithAutomaticIdStrategy() { Vertex v1 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().toList(); Assert.assertEquals(1, vertices.size()); @@ -889,7 +893,7 @@ public void testAddVertexWithAutomaticIdStrategy() { Vertex v2 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNotEquals(v1.id(), v2.id()); @@ -919,7 +923,7 @@ public void testAddVertexWithAutomaticIdStrategyAndForceStringId() { Vertex v1 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().toList(); Assert.assertEquals(1, vertices.size()); @@ -929,7 +933,7 @@ public void testAddVertexWithAutomaticIdStrategyAndForceStringId() { Vertex v2 = graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNotEquals(v1.id(), v2.id()); @@ -972,7 +976,7 @@ public void testAddVertexWithPrimaryKeyIdStrategy() { .create(); graph.addVertex(T.label, "programmer", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); String programmerId = graph.vertexLabel("programmer").id().asString(); String vid = String.format("%s:%s!%s", programmerId, "marko", "1I"); @@ -995,7 +999,7 @@ public void testAddVertexWithCustomizeStringIdStrategy() { .create(); graph.addVertex(T.label, "programmer", T.id, "123456", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V("123456").toList(); Assert.assertEquals(1, vertices.size()); @@ -1051,7 +1055,7 @@ public void testAddVertexWithCustomizeNumberIdStrategy() { "age", 18, "city", "Beijing"); graph.addVertex(T.label, "programmer", T.id, 61695499031416832L, "name", "marko", "age", 19, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V(123456).toList(); Assert.assertEquals(1, vertices.size()); @@ -1114,7 +1118,8 @@ public void testAddVertexWithCustomizeUuidIdStrategy() { graph.addVertex(T.label, "programmer", T.id, "835e1153928149578691cf79258e90ee", "name", "marko", "age", 19, "city", "Beijing"); - graph.tx().commit(); + + this.commitTx(); Assert.assertEquals(2L, graph.traversal().V().count().next()); Object uuid = Text.uuid("835e1153928149578691cf79258e90eb"); @@ -1191,12 +1196,12 @@ public void testAddVertexWithTx() { public void testAddVertexWithTtl() { Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().vertices(vertex); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1213,12 +1218,12 @@ public void testAddVertexWithTtlAndTtlStartTime() { T.label, "follower", "name", "Baby", "age", 3, "city", "Beijing", "birth", graph().now() - 1000L); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().vertices(vertex); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(1100L); @@ -1228,7 +1233,7 @@ public void testAddVertexWithTtlAndTtlStartTime() { vertices = graph().vertices(vertex); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(1100L); @@ -1246,13 +1251,13 @@ public void testAddVertexWithSecondaryIndexAndTtl() { Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V() .has("city", "Beijing"); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1281,7 +1286,7 @@ public void testAddVertexWithRangeIndexAndTtl() { "age", 6, "city", "Beijing"); Vertex vertex5 = graph().addVertex(T.label, "fan", "name", "Baby5", "age", 7, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has("age", 5); Assert.assertTrue(vertices.hasNext()); @@ -1302,7 +1307,7 @@ public void testAddVertexWithRangeIndexAndTtl() { vertices = graph().traversal().V().has("age", P.lte(4)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1345,7 +1350,7 @@ public void testAddVertexWithShardIndexAndTtl() { "age", 7, "city", "Beijing"); Vertex vertex6 = graph().addVertex(T.label, "fan", "name", "Baby6", "age", 5, "city", "Shanghai"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has("city", "Shanghai"); @@ -1376,7 +1381,7 @@ public void testAddVertexWithShardIndexAndTtl() { .has("age", P.lte(4)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1415,13 +1420,13 @@ public void testAddVertexWithSearchIndexAndTtl() { Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing Haidian"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has( "city", Text.contains("Haidian")); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1441,12 +1446,12 @@ public void testAddVertexWithUniqueIndexAndTtl() { graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); }); try { @@ -1457,7 +1462,7 @@ public void testAddVertexWithUniqueIndexAndTtl() { graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); } @Test @@ -1467,13 +1472,13 @@ public void testOverrideVertexWithSecondaryIndexAndTtl() { Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V() .has("city", "Beijing"); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1484,7 +1489,7 @@ public void testOverrideVertexWithSecondaryIndexAndTtl() { // Override vertex = graph().addVertex(T.label, "fan", "name", "Baby", "age", 3, "city", "Shanghai"); - graph().tx().commit(); + this.commitTx(); // Due to overridden vertices are expired, // query will lead to async delete @@ -1494,7 +1499,7 @@ public void testOverrideVertexWithSecondaryIndexAndTtl() { vertices = graph().traversal().V().has("city", "Shanghai"); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1526,7 +1531,7 @@ public void testOverrideVertexWithRangeIndexAndTtl() { "age", 9, "city", "Beijing"); Vertex vertex5 = graph().addVertex(T.label, "fan", "name", "Baby5", "age", 11, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has("age", 7); Assert.assertTrue(vertices.hasNext()); @@ -1547,7 +1552,7 @@ public void testOverrideVertexWithRangeIndexAndTtl() { vertices = graph().traversal().V().has("age", P.lte(5)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1568,7 +1573,7 @@ public void testOverrideVertexWithRangeIndexAndTtl() { "age", 10, "city", "Beijing"); Vertex vertex10 = graph().addVertex(T.label, "fan", "name", "Baby10", "age", 12, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); /* * Due to overridden vertices are expired, * query will lead to async delete @@ -1595,7 +1600,7 @@ public void testOverrideVertexWithRangeIndexAndTtl() { vertices = graph().traversal().V().has("age", P.lte(6)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1642,7 +1647,7 @@ public void testOverrideVertexWithShardIndexAndTtl() { "age", 9, "city", "Beijing"); Vertex vertex6 = graph().addVertex(T.label, "fan", "name", "Baby6", "age", 5, "city", "Shanghai"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has("city", "Shanghai"); @@ -1673,7 +1678,7 @@ public void testOverrideVertexWithShardIndexAndTtl() { .has("age", P.lte(3)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1698,7 +1703,7 @@ public void testOverrideVertexWithShardIndexAndTtl() { Vertex vertex12 = graph().addVertex(T.label, "fan", "name", "Baby12", "age", 6, "city", "Shenzhen"); - graph().tx().commit(); + this.commitTx(); // Due to overridden vertices are expired, query will lead to async delete vertices = graph().traversal().V().has("city", "Shanghai"); @@ -1736,7 +1741,7 @@ public void testOverrideVertexWithShardIndexAndTtl() { .has("age", P.lte(4)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1783,13 +1788,13 @@ public void testOverrideVertexWithSearchIndexAndTtl() { Vertex vertex = graph().addVertex(T.label, "fan", "name", "Baby1", "age", 3, "city", "Beijing Haidian"); - graph().tx().commit(); + this.commitTx(); Iterator vertices = graph().traversal().V().has( "city", Text.contains("Haidian")); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1799,7 +1804,7 @@ public void testOverrideVertexWithSearchIndexAndTtl() { vertex = graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Shanghai Pudong"); - graph().tx().commit(); + this.commitTx(); // Due to overridden vertices are expired, query will lead to async delete vertices = graph().traversal().V().has("city", @@ -1810,7 +1815,7 @@ public void testOverrideVertexWithSearchIndexAndTtl() { Text.contains("Pudong")); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1828,7 +1833,7 @@ public void testOverrideVertexWithSearchIndexAndTtl() { public void testQueryVertexWithTtlInTx() { Vertex vertex1 = graph().addVertex(T.label, "fan", "name", "Baby1", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); // Add vertices in tx Vertex vertex2 = graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing"); @@ -1840,7 +1845,7 @@ public void testQueryVertexWithTtlInTx() { vertices = graph().vertices(vertex2); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(vertex2, vertices.next()); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1863,7 +1868,7 @@ public void testQueryVertexWithSecondaryIndexAndTtlInTx() { graph().addVertex(T.label, "fan", "name", "Baby1", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); // Add vertices in tx graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing"); @@ -1872,7 +1877,7 @@ public void testQueryVertexWithSecondaryIndexAndTtlInTx() { .has("city", "Beijing"); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1900,7 +1905,7 @@ public void testQueryVertexWithRangeIndexAndTtlInTx() { "age", 6, "city", "Beijing"); graph().addVertex(T.label, "fan", "name", "Baby5", "age", 7, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); // Add vertices in tx graph().addVertex(T.label, "fan", "name", "Baby6", @@ -1933,7 +1938,7 @@ public void testQueryVertexWithRangeIndexAndTtlInTx() { vertices = graph().traversal().V().has("age", P.lte(4)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(4, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -1975,7 +1980,7 @@ public void testQueryVertexWithShardIndexAndTtlInTx() { "age", 7, "city", "Beijing"); graph().addVertex(T.label, "fan", "name", "Baby6", "age", 5, "city", "Shanghai"); - graph().tx().commit(); + this.commitTx(); // Add vertices in tx graph().addVertex(T.label, "fan", "name", "Baby7", @@ -2020,7 +2025,7 @@ public void testQueryVertexWithShardIndexAndTtlInTx() { .has("age", P.lte(4)); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(4, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -2060,7 +2065,7 @@ public void testQueryVertexWithSearchIndexAndTtlInTx() { graph().addVertex(T.label, "fan", "name", "Baby1", "age", 3, "city", "Beijing Haidian"); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing Haidian"); @@ -2069,7 +2074,7 @@ public void testQueryVertexWithSearchIndexAndTtlInTx() { "city", Text.contains("Haidian")); Assert.assertTrue(vertices.hasNext()); Assert.assertEquals(2, IteratorUtils.count(vertices)); - graph().tx().commit(); + this.commitTx(); try { Thread.sleep(3100L); @@ -2096,6 +2101,8 @@ public void testAddOlapNoneProperties() { .ifNotExist().create(); init10Vertices(); + this.commitTx(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2125,7 +2132,7 @@ public void testAddOlapNoneProperties() { graph.addVertex(T.id, id9.asObject(), olapPropName, "i"); graph.addVertex(T.id, id10.asObject(), olapPropName, "j"); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode()); Assert.assertThrows(NotAllowException.class, () -> { @@ -2181,6 +2188,8 @@ public void testAddOlapSecondaryProperties() { .ifNotExist().create(); init10Vertices(); + this.commitTx(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2210,7 +2219,7 @@ public void testAddOlapSecondaryProperties() { graph.addVertex(T.id, id9.asObject(), olapPropName, "i"); graph.addVertex(T.id, id10.asObject(), olapPropName, "j"); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode()); Assert.assertThrows(NotAllowException.class, () -> { @@ -2267,6 +2276,8 @@ public void testAddOlapRangeProperties() { .ifNotExist().create(); init10Vertices(); + this.commitTx(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2296,7 +2307,7 @@ public void testAddOlapRangeProperties() { graph.addVertex(T.id, id9.asObject(), olapPropName, 0.9D); graph.addVertex(T.id, id10.asObject(), olapPropName, 1.0D); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode()); Assert.assertThrows(NotAllowException.class, () -> { @@ -2391,6 +2402,8 @@ public void testAddOlapRangeAndOlapSecondaryProperties() { .ifNotExist().create(); init10Vertices(); + this.commitTx(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2420,7 +2433,7 @@ public void testAddOlapRangeAndOlapSecondaryProperties() { graph.addVertex(T.id, id9.asObject(), "pagerank", 0.9D); graph.addVertex(T.id, id10.asObject(), "pagerank", 1.0D); - graph.tx().commit(); + this.commitTx(); graph.addVertex(T.id, id1.asObject(), "wcc", "a"); graph.addVertex(T.id, id2.asObject(), "wcc", "a"); @@ -2433,7 +2446,7 @@ public void testAddOlapRangeAndOlapSecondaryProperties() { graph.addVertex(T.id, id9.asObject(), "wcc", "f"); graph.addVertex(T.id, id10.asObject(), "wcc", "f"); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode()); Assert.assertThrows(NotAllowException.class, () -> { @@ -2565,6 +2578,8 @@ public void testQueryOlapRangeAndRegularSecondaryProperties() { .ifNotExist().create(); init10Vertices(); + this.commitTx(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2574,12 +2589,12 @@ public void testQueryOlapRangeAndRegularSecondaryProperties() { graph.addVertex(T.id, id1.asObject(), "pagerank", 0.1D); graph.addVertex(T.id, id2.asObject(), "pagerank", 0.2D); - graph.tx().commit(); + this.commitTx(); graph.addVertex(T.id, id1.asObject(), "wcc", "a"); graph.addVertex(T.id, id2.asObject(), "wcc", "b"); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals(GraphReadMode.OLTP_ONLY, graph.readMode()); Assert.assertThrows(NotAllowException.class, () -> { @@ -2667,6 +2682,51 @@ public void testQueryOlapRangeAndRegularSecondaryProperties() { graph.readMode(GraphReadMode.OLTP_ONLY); } + @Test + public void testQueryOlapWithUpdates() { + Assume.assumeTrue("Not support olap properties", + storeFeatures().supportsOlapProperties()); + + HugeGraph graph = graph(); + SchemaManager schema = graph.schema(); + schema.propertyKey("pagerank") + .asDouble().valueSingle() + .writeType(WriteType.OLAP_RANGE) + .ifNotExist().create(); + + init10Vertices(); + this.commitTx(); + + String author = graph.vertexLabel("author").id().asString(); + Id id1 = SplicingIdGenerator.splicing(author, + LongEncoding.encodeNumber(1)); + Id id2 = SplicingIdGenerator.splicing(author, + LongEncoding.encodeNumber(2)); + + graph.addVertex(T.id, id1.asObject(), "pagerank", 0.1D); + graph.addVertex(T.id, id2.asObject(), "pagerank", 0.2D); + + graph.readMode(GraphReadMode.ALL); + + // FIXME: expect to throw error here +// Assert.assertThrows(IllegalArgumentException.class, () -> { +// graph.traversal().V().has("pagerank", 0.1D).toList(); +// }, e -> { +// Assert.assertContains("not allowed to query by olap " + +// "when there are uncommitted records", +// e.toString()); +// }); + + this.commitTx(); + + List vertices = graph.traversal().V() + .has("pagerank", 0.2D) + .toList(); + Assert.assertEquals(1, vertices.size()); + + graph.readMode(GraphReadMode.OLTP_ONLY); + } + @Test public void testQueryAll() { HugeGraph graph = graph(); @@ -2730,14 +2790,15 @@ public void testQueryAllWithLimitAfterDelete() { // Query with limit graph.traversal().V().limit(3).toList(); }); - graph.tx().commit(); + + this.commitTx(); Assert.assertEquals(4L, graph.traversal().V().count().next()); List vertices = graph.traversal().V().limit(3).toList(); Assert.assertEquals(3, vertices.size()); // Query all with limit after delete twice graph.traversal().V().limit(3).drop().iterate(); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().limit(3).toList(); Assert.assertEquals(1, vertices.size()); } @@ -2976,6 +3037,7 @@ public void testQueryByIdWithGraphAPIAndNotCommitedUpdate() { public void testQueryByIdWithGraphAPIAndNotCommitedRemoved() { HugeGraph graph = graph(); init10Vertices(); + this.commitTx(); List vertices = graph.traversal().V() .hasLabel("author").toList(); @@ -3092,7 +3154,7 @@ public void testQueryByLabelWithLimit() { // Query by vertex label with limit graph.traversal().V().hasLabel("book").limit(3).drop().iterate(); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("book") .limit(3).toList(); @@ -3310,7 +3372,8 @@ public void testQueryByStringPropWithMultiResults() { graph.traversal().V().hasLabel("person") .has("city", "Beijing").limit(2) .drop().iterate(); - graph.tx().commit(); + this.commitTx(); + vertices = graph.traversal().V().hasLabel("person") .has("city", "Beijing").limit(2).toList(); Assert.assertEquals(1, vertices.size()); @@ -3657,7 +3720,7 @@ public void testQueryByIntPropUsingBetweenWithMultiResults() { graph.traversal().V().hasLabel("person") .has("age", P.between(3, 21)).limit(3) .drop().iterate(); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("person") .has("age", P.between(3, 21)).limit(3).toList(); @@ -3688,7 +3751,7 @@ public void testQueryByIntPropUsingBetweenAfterPropOverride() { // override vertex without age (in backend) and make left index graph.addVertex(T.label, "person", "name", "Baby","city", "Hongkong") .remove(); // avoid merge property mode - graph.tx().commit(); + this.mayCommitTx(); // qeury again after commit vertices = graph.traversal().V().hasLabel("person") @@ -3747,7 +3810,7 @@ public void testQueryByIntProperty() { graph().addVertex(T.label, "number", "id", 8, "int", Integer.MIN_VALUE + 1); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("number") .has("int", 0).toList(); @@ -3829,7 +3892,7 @@ public void testQueryByLongProperty() { graph().addVertex(T.label, "number", "id", 10, "long", Long.MIN_VALUE + 1); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("number") .has("long", 0).toList(); @@ -3924,7 +3987,7 @@ public void testQueryByFloatProperty() { graph().addVertex(T.label, "number", "id", 12, "float", -secondSmallest); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("number") .has("float", 7).toList(); @@ -4037,7 +4100,7 @@ public void testQueryByDoubleProperty() { graph().addVertex(T.label, "number", "id", 9, "double", min15); graph().addVertex(T.label, "number", "id", 10, "double", -min15); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("number") .has("double", 7).toList(); @@ -4124,7 +4187,7 @@ public void testQueryByDoublePropertyWithMaxMinValue() { graph().addVertex(T.label, "number", "id", 8, "double", -secondSmallest); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("number") .has("double", 0.123456789012345678901d) @@ -4232,7 +4295,8 @@ public void testQueryByDateProperty() { graph.traversal().V().hasLabel("person") .has("birth", P.between(dates[1], dates[4])) .limit(2).drop().iterate(); - graph.tx().commit(); + this.commitTx(); + vertices = graph.traversal().V().hasLabel("person") .has("birth", P.between(dates[1], dates[4])) .limit(2).toList(); @@ -4368,7 +4432,7 @@ public void testQueryByUUIDProperty() { graph().addVertex(T.label, "user", "id", 1, "uuid", uuid1); graph().addVertex(T.label, "user", "id", 2, "uuid", uuid2); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("user") .has("uuid", uuid1).toList(); @@ -4397,7 +4461,7 @@ public void testQueryByBlobProperty() { graph().addVertex(T.label, "user", "id", 1, "blob", blob1); graph().addVertex(T.label, "user", "id", 2, "blob", blob2); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().hasLabel("user") .has("blob", blob1).toList(); @@ -4429,7 +4493,7 @@ public void testQueryByTextContainsProperty() { Assert.assertEquals(1, vertices.size()); // Committed - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V() .hasLabel("author") .has("lived", Text.contains("Bay Area")) @@ -4462,7 +4526,7 @@ public void testQueryByTextContainsAndExactMatchProperty() { graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "San Francisco Bay Area"); - graph.tx().commit(); + this.mayCommitTx(); // By authorByLivedSearch index List vertices = graph.traversal().V() @@ -4506,7 +4570,7 @@ public void testQueryByTextContainsPropertyOrderByMatchedCount() { "lived", "Tokyo Bay"); graph.addVertex(T.label, "author", "id", 5, "name", "James", "age", 62, "lived", "San Francisco Bay Area"); - graph.tx().commit(); + this.commitTx(); List vertices = graph.traversal().V() .hasLabel("author") @@ -4575,7 +4639,7 @@ public void testQueryByTextContainsPropertyOrderByMatchedCountWithPaging() { "lived", "Tokyo Bay"); graph.addVertex(T.label, "author", "id", 5, "name", "James", "age", 62, "lived", "San Francisco Bay Area"); - graph.tx().commit(); + this.commitTx(); List vertices = graph.traversal().V() .hasLabel("author") @@ -4601,14 +4665,14 @@ public void testQueryByTextContainsPropertyWithLeftIndex() { graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "San Francisco Bay Area"); - graph.tx().commit(); + this.commitTx(); // Override the origin vertex with different property value // and then lead to index left graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "San Francisco, California, U.S."); - graph.tx().commit(); + this.commitTx(); // Set breakpoint to observe the store before and after this statement List vertices = graph.traversal().V().hasLabel("author") @@ -4630,7 +4694,7 @@ public void testQueryByNeq() { graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "San Francisco Bay Area"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertThrows(NoIndexException.class, () -> { graph.traversal().V().hasLabel("author") @@ -4686,7 +4750,7 @@ public void testQueryByIntPropOfOverrideVertex() { "city", "Beijing", "age", 28); graph.addVertex(T.label, "person", "name", "Zhangyi", "city", "Hongkong", "age", 29); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().has("age", 28).toList(); Assert.assertEquals(0, vertices.size()); @@ -4703,7 +4767,7 @@ public void testQueryByStringPropOfOverrideVertex() { "city", "Beijing", "age", 28); graph.addVertex(T.label, "person", "name", "Zhangyi", "city", "Hongkong", "age", 29); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().has("city", "Beijing") .toList(); @@ -4801,9 +4865,10 @@ public void testQueryWithTxNotCommittedUpdatedProp() { "age", 18, "city", "Beijing"); Vertex v = graph.addVertex(T.label, "person", "name", "james", "age", 19, "city", "Hongkong"); - graph().tx().commit(); + this.commitTx(); v.property("age", 20); + // Don't commit List vertices = graph.traversal().V() .where(__.values("age").is(20)) @@ -4889,7 +4954,7 @@ public void testQueryByJointIndexesAndCompositeIndexForOneLabel() { graph().addVertex(T.label, "person", "name", "Tom", "city", "Hongkong", "age", 3); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V().has("age", 3).toList(); @@ -4900,6 +4965,10 @@ public void testQueryByJointIndexesAndCompositeIndexForOneLabel() { .has("age", 3).toList(); Assert.assertEquals(1, vertices.size()); + /* + * NOTE: may block if not commit records: + * Lock [hugegraph_il_delete:3] is locked by other operation + */ graph().schema().indexLabel("personByCityAndAge").onV("person") .by("city", "age").ifNotExist().create(); @@ -4932,6 +5001,7 @@ public void testQueryByJointIndexesAndCompositeIndexForMultiLabel() { "city", "Hongkong", "age", 3); graph().addVertex(T.label, "cat", "name", "Baby", "city", "Hongkong", "age", 3); + this.mayCommitTx(); List vertices; vertices = graph().traversal().V().has("age", 3) @@ -4956,7 +5026,7 @@ public void testQueryByJointIndexesOnlyWithCompositeIndex() { graph().addVertex(T.label, "dog", "name", "Tom", "city", "Hongkong", "age", 3); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph().traversal().V().has("age", 3) .has("city", "Hongkong") @@ -4988,7 +5058,7 @@ public void testQueryByJointIndexesWithCompositeIndexIncludeOtherField() { graph().addVertex(T.label, "dog", "name", "Tom", "city", "Hongkong", "age", 3); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph().traversal().V().has("age", P.gt(2)) .has("city", "Hongkong").toList(); @@ -5005,7 +5075,7 @@ public void testQueryByJointIndexesWithOnlyRangeIndexes() { graph().addVertex(T.label, "dog", "name", "Tom", "age", 8, "weight", 3); - graph().tx().commit(); + this.mayCommitTx(); List vertices = graph().traversal().V().has("age", P.gt(2)) .has("weight", P.lt(10)).toList(); @@ -5030,7 +5100,7 @@ public void testQueryByJointIndexesWithSearchAndRangeIndexes() { graph().addVertex(T.label, "dog", "name", "Coco", "age", 3, "description", "yellow hair golden tail"); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V() @@ -5077,7 +5147,7 @@ public void testQueryByJointIndexesWithSearchAndRangeAndSecondaryIndexes() { "city", "Shanghai", "description", "yellow hair golden tail"); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V() @@ -5139,7 +5209,7 @@ public void testQueryByJointIndexesWithTwoSearchAndOneRangeIndexes() { "city", "Shanghai Pudong", "description", "yellow hair golden tail"); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V() @@ -5272,7 +5342,7 @@ public void testQueryByShardIndex() { "city", "Beijing", "age", 23); graph.addVertex(T.label, "person", "name", "p5", "city", "Beijing", "age", 29); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph().traversal().V() .has("city", "Hongkong") @@ -5755,15 +5825,16 @@ public void testAddVertexWithUniqueIndex() { schema.indexLabel("userByName").onV("user").by("name").unique() .create(); Vertex v = graph().addVertex(T.label, "user", "name", "Tom"); - graph().tx().commit(); + this.commitTx(); + Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "user", "name", "Tom"); - graph().tx().commit(); + this.commitTx(); }); v.remove(); graph().addVertex(T.label, "user", "name", "Tom"); - graph().tx().commit(); + this.commitTx(); } @Test @@ -5777,7 +5848,7 @@ public void testAddVerticesWithUniqueIndexInTx() { graph().addVertex(T.label, "user", "name", "Tom"); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "user", "name", "Tom"); - graph().tx().commit(); + this.commitTx(); }); } @@ -5792,16 +5863,17 @@ public void testUpdatePropertyToValueOfRemovedVertexWithUniqueIndex() { Vertex tom = graph().addVertex(T.label, "user", "name", "Tom"); Vertex jack = graph().addVertex(T.label, "user", "name", "Jack"); Vertex james = graph().addVertex(T.label, "user", "name", "James"); - graph().tx().commit(); + this.commitTx(); tom.remove(); - graph().tx().commit(); + this.commitTx(); + jack.property("name", "Tom"); - graph().tx().commit(); + this.commitTx(); james.remove(); jack.property("name", "James"); - graph().tx().commit(); + this.commitTx(); } @Test @@ -5816,38 +5888,38 @@ public void testAddVerticesWithUniqueIndexForNullableProperties() { .unique().create(); graph().addVertex(T.label, "user", "name", "Tom", "city", "Beijing", "age", 18); - graph().tx().commit(); + this.commitTx(); // Nullable properties graph().addVertex(T.label, "user", "name", "Tom", "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "name", "Tom", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "city", "Beijing", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "name", "Tom"); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user"); - graph().tx().commit(); + this.commitTx(); // Empty String properties graph().addVertex(T.label, "user", "name", "", "city", "", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "name", "", "city", ""); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "name", "", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "city", "", "age", 18); - graph().tx().commit(); + this.commitTx(); graph().addVertex(T.label, "user", "name", ""); - graph().tx().commit(); + this.commitTx(); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "user", "age", 18); - graph().tx().commit(); + this.commitTx(); }, e -> { String message = e.getMessage(); Assert.assertTrue(message.contains("Unique constraint " + @@ -5855,16 +5927,16 @@ public void testAddVerticesWithUniqueIndexForNullableProperties() { Assert.assertTrue(message.contains("conflict is found")); }); graph().addVertex(T.label, "user", "city", ""); - graph().tx().commit(); + this.commitTx(); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "user"); - graph().tx().commit(); + this.commitTx(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().addVertex(T.label, "user", "city", "\u0001"); - graph().tx().commit(); + this.commitTx(); }); } @@ -5885,7 +5957,7 @@ public void testQueryByUniqueIndex() { .create(); graph.addVertex(T.label, "node", "name", "tom"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertThrows(NoIndexException.class, () -> { graph.traversal().V().hasLabel("node").has("name", "tom").next(); @@ -5910,7 +5982,7 @@ public void testRemoveVertex() { Vertex vertex = vertex("author", "id", 1); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V().toList(); Assert.assertEquals(9, vertices.size()); @@ -5935,7 +6007,7 @@ public void testRemoveVertexById() { graph.addVertex(T.label, "author", "id", 2, "name", "Guido van Rossum", "age", 61, "lived", "California"); - graph.tx().commit(); + this.mayCommitTx(); List vertices = graph.traversal().V().toList(); Assert.assertEquals(2, vertices.size()); @@ -5946,7 +6018,7 @@ public void testRemoveVertexById() { // remove vertex without label index Vertex vertex = vertex("author2", "id", 1); graph.removeVertex(vertex.label(), vertex.id()); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V().toList(); Assert.assertEquals(1, vertices.size()); @@ -5957,7 +6029,7 @@ public void testRemoveVertexById() { // remove vertex with label index vertex = vertex("author", "id", 2); graph.removeVertex(vertex.label(), vertex.id()); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V().toList(); Assert.assertEquals(0, vertices.size()); @@ -5976,7 +6048,7 @@ public void testRemoveVertexOfNotExists() { Vertex vertex = vertex("author", "id", 1); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); vertices = graph.traversal().V().toList(); Assert.assertEquals(9, vertices.size()); @@ -5986,7 +6058,7 @@ public void testRemoveVertexOfNotExists() { // Remove again vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); } @Test @@ -6016,7 +6088,7 @@ public void testRemoveVertexOneByOne() { for (int i = 0; i < vertices.size(); i++) { vertices.get(i).remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertEquals(9 - i, graph.traversal().V().toList().size()); } } @@ -6026,13 +6098,13 @@ public void testAddVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom"); - graph.tx().commit(); + this.mayCommitTx(); // Add properties vertex.property("name", "Tom2"); vertex.property("age", 10); vertex.property("lived", "USA"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tom2", vertex.property("name").value()); @@ -6045,13 +6117,13 @@ public void testAddVertexPropertyExisted() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tom", vertex.property("name").value()); vertex.property("name", "Tom2"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tom2", vertex.property("name").value()); @@ -6062,13 +6134,13 @@ public void testAddVertexPropertyExistedWithIndex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "person", "name", "Tom", "city", "Hongkong", "age", 3); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("person", "name", "Tom"); Assert.assertEquals(3, vertex.property("age").value()); vertex.property("age", 4); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertEquals(4, vertex.property("age").value()); vertex = vertex("person", "name", "Tom"); @@ -6091,7 +6163,7 @@ public void testAddVertexPropertyWithNotExistPropKey() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Jim"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertThrows(IllegalArgumentException.class, () -> { vertex.property("prop-not-exist", "2017-1-1"); @@ -6103,7 +6175,7 @@ public void testAddVertexPropertyOfPrimaryKey() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Jim"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertEquals(1, vertex.property("id").value()); Assert.assertThrows(IllegalArgumentException.class, () -> { @@ -6123,7 +6195,7 @@ public void testAddVertexPropertyWithSpecialValueForSecondaryIndex() { "city", "c\u0002", "age", 2); graph.addVertex(T.label, "person", "name", "3", "city", "d\u0003", "age", 3); - graph.tx().commit(); + this.mayCommitTx(); List vertices; @@ -6146,7 +6218,7 @@ public void testAddVertexPropertyWithSpecialValueForSecondaryIndex() { Assert.assertThrows(Exception.class, () -> { graph.addVertex(T.label, "person", "name", "0", "city", "a\u0000", "age", 0); - graph.tx().commit(); + this.commitTx(); }, e -> { if (e instanceof BackendException) { Assert.assertContains("0x00", e.getCause().getMessage()); @@ -6157,7 +6229,7 @@ public void testAddVertexPropertyWithSpecialValueForSecondaryIndex() { } else { graph.addVertex(T.label, "person", "name", "0", "city", "a\u0000", "age", 0); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().has("city", "a\u0000").toList(); Assert.assertEquals(1, vertices.size()); @@ -6173,7 +6245,7 @@ public void testAddVertexPropertyWithIllegalValueForSecondaryIndex() { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.addVertex(T.label, "person", "name", "Baby", "city", "\u0000", "age", 3); - graph.tx().commit(); + this.commitTx(); }, e -> { Assert.assertContains("Illegal leading char '\\u0' in index", e.getMessage()); @@ -6182,7 +6254,7 @@ public void testAddVertexPropertyWithIllegalValueForSecondaryIndex() { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.addVertex(T.label, "person", "name", "Baby", "city", "\u0001", "age", 3); - graph.tx().commit(); + this.commitTx(); }, e -> { Assert.assertContains("Illegal leading char '\\u1' in index", e.getMessage()); @@ -6191,7 +6263,7 @@ public void testAddVertexPropertyWithIllegalValueForSecondaryIndex() { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.addVertex(T.label, "person", "name", "Baby", "city", "\u0002", "age", 3); - graph.tx().commit(); + this.commitTx(); }, e -> { Assert.assertContains("Illegal leading char '\\u2' in index", e.getMessage()); @@ -6200,7 +6272,7 @@ public void testAddVertexPropertyWithIllegalValueForSecondaryIndex() { Assert.assertThrows(IllegalArgumentException.class, () -> { graph.addVertex(T.label, "person", "name", "Baby", "city", "\u0003", "age", 3); - graph.tx().commit(); + this.commitTx(); }, e -> { Assert.assertContains("Illegal leading char '\\u3' in index", e.getMessage()); @@ -6213,10 +6285,10 @@ public void testAddVertexMultiTimesWithMergedProperties() { storeFeatures().supportsMergeVertexProperty()); HugeGraph graph = graph(); - // "city" is a nonnullable property + // "city" is a non-nullable property graph.addVertex(T.label, "person", "name", "marko", "city", "Beijing", "birth", "1992-11-17 12:00:00.000"); - graph.tx().commit(); + this.commitTx(); Vertex vertex = vertex("person", "name", "marko"); Assert.assertEquals("Beijing", vertex.value("city")); Assert.assertEquals(Utils.date("1992-11-17 12:00:00.000"), @@ -6225,7 +6297,7 @@ public void testAddVertexMultiTimesWithMergedProperties() { // append property 'age' graph.addVertex(T.label, "person", "name", "marko", "city", "Beijing", "age", 26); - graph.tx().commit(); + this.commitTx(); Assert.assertEquals("Beijing", vertex.value("city")); vertex = vertex("person", "name", "marko"); Assert.assertEquals(26, (int) vertex.value("age")); @@ -6234,7 +6306,7 @@ public void testAddVertexMultiTimesWithMergedProperties() { // update property "birth" and keep the original properties unchanged graph.addVertex(T.label, "person", "name", "marko", "city", "Beijing", "birth", "1993-11-17 12:00:00.000"); - graph.tx().commit(); + this.commitTx(); vertex = vertex("person", "name", "marko"); Assert.assertEquals("Beijing", vertex.value("city")); Assert.assertEquals(26, (int) vertex.value("age")); @@ -6247,14 +6319,14 @@ public void testRemoveVertexProperty() { HugeGraph graph = graph(); Vertex v = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "age", 10, "lived", "USA"); - graph.tx().commit(); + this.mayCommitTx(); // Remove "name" property Assert.assertTrue(v.property("name").isPresent()); Assert.assertTrue(v.property("lived").isPresent()); Assert.assertThrows(IllegalArgumentException.class, () -> { v.property("name").remove(); - graph.tx().commit(); + this.commitTx(); }); Assert.assertTrue(v.property("name").isPresent()); Assert.assertTrue(v.property("lived").isPresent()); @@ -6264,7 +6336,7 @@ public void testRemoveVertexProperty() { Assert.assertTrue(vertex.property("name").isPresent()); Assert.assertTrue(vertex.property("lived").isPresent()); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertTrue(vertex.property("name").isPresent()); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -6328,7 +6400,7 @@ public void testQueryVertexByPropertyWithEmptyString() { initPersonIndex(true); graph.addVertex(T.label, "person", "name", "Baby", "city", ""); - graph.tx().commit(); + this.commitTx(); Vertex vertex = graph.traversal().V().has("city", "").next(); Assert.assertEquals("Baby", vertex.value("name")); @@ -6342,7 +6414,7 @@ public void testQueryVertexBeforeAfterUpdateMultiPropertyWithIndex() { Vertex vertex = graph.addVertex(T.label, "person", "name", "Baby", "city", "Hongkong", "age", 3); - graph.tx().commit(); + this.commitTx(); List vl = graph.traversal().V().has("age", 3).toList(); Assert.assertEquals(1, vl.size()); @@ -6357,7 +6429,7 @@ public void testQueryVertexBeforeAfterUpdateMultiPropertyWithIndex() { vertex.property("age", 5); vertex.property("city", "Shanghai"); - graph.tx().commit(); + this.commitTx(); vl = graph.traversal().V().has("age", 3).toList(); Assert.assertEquals(0, vl.size()); @@ -6378,7 +6450,7 @@ public void testQueryVertexBeforeAfterUpdatePropertyWithSecondaryIndex() { Vertex vertex = graph.addVertex(T.label, "person", "name", "Baby", "city", "Hongkong", "age", 3); - graph.tx().commit(); + this.commitTx(); List vl = graph.traversal().V().has("city", "Hongkong").toList(); Assert.assertEquals(1, vl.size()); @@ -6387,7 +6459,7 @@ public void testQueryVertexBeforeAfterUpdatePropertyWithSecondaryIndex() { Assert.assertEquals(0, vl.size()); vertex.property("city", "Shanghai"); - graph.tx().commit(); + this.commitTx(); vl = graph.traversal().V().has("city", "Hongkong").toList(); Assert.assertEquals(0, vl.size()); @@ -6403,7 +6475,7 @@ public void testQueryVertexBeforeAfterUpdatePropertyWithRangeIndex() { Vertex vertex = graph.addVertex(T.label, "person", "name", "Baby", "city", "Hongkong", "age", 3); - graph.tx().commit(); + this.commitTx(); List vl = graph.traversal().V().has("age", 3).toList(); Assert.assertEquals(1, vl.size()); @@ -6412,7 +6484,7 @@ public void testQueryVertexBeforeAfterUpdatePropertyWithRangeIndex() { Assert.assertEquals(0, vl.size()); vertex.property("age", 5); - graph.tx().commit(); + this.commitTx(); vl = graph.traversal().V().has("age", 3).toList(); Assert.assertEquals(0, vl.size()); @@ -6428,8 +6500,7 @@ public void testQueryVertexWithNullablePropertyInCompositeIndex() { graph.addVertex(T.label, "computer", "name", "1st", "band", "10Gbps", "cpu", "2GHz", "ram", "8GB", "price", 1000); - graph.tx().commit(); - + this.commitTx(); List vl = graph.traversal().V().has("cpu", "2GHz").toList(); Assert.assertEquals(1, vl.size()); @@ -6446,11 +6517,11 @@ public void testUpdateVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); vertex.property("lived").remove(); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -6461,7 +6532,7 @@ public void testUpdateVertexPropertyTwice() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); vertex.property("lived").remove(); vertex.property("lived").remove(); @@ -6469,7 +6540,7 @@ public void testUpdateVertexPropertyTwice() { vertex.property("lived", "Hangzhou"); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -6484,7 +6555,7 @@ public void testUpdateVertexPropertyOfNewVertex() { vertex.property("lived").remove(); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -6495,7 +6566,7 @@ public void testUpdateVertexPropertyOfPrimaryKey() { HugeGraph graph = graph(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); Vertex vertex = vertex("author", "id", 1); Assert.assertThrows(IllegalArgumentException.class, () -> { @@ -6519,9 +6590,13 @@ public void testUpdateVertexPropertyOfPrimaryKeyOfNewVertex() { @Test public void testUpdateVertexPropertyOfAddingVertex() { HugeGraph graph = graph(); + Vertex vertex0 = graph.addVertex(T.label, "author", "id", 1, + "name", "Tom", "lived", "Beijing"); + vertex0.property("lived").remove(); + Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.commitTx(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); @@ -6539,7 +6614,7 @@ public void testUpdateVertexPropertyOfRemovingVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.commitTx(); vertex.remove(); @@ -6556,7 +6631,7 @@ public void testUpdateVertexPropertyOfRemovingVertexWithDrop() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); - graph.tx().commit(); + this.commitTx(); graph.traversal().V(vertex.id()).drop().iterate(); @@ -6604,7 +6679,7 @@ public void testUpdateVertexPropertyOfAggregateType() { graph.addVertex(T.label, "student", "name", "Tom", "worstScore", 55, "bestScore", 96, "testNum", 1, "rank", 8, "reword", 8); - graph.tx().commit(); + this.commitTx(); Vertex tom = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -6619,7 +6694,7 @@ public void testUpdateVertexPropertyOfAggregateType() { tom.property("testNum", 1); tom.property("rank", 12); tom.property("reword", 12); - graph.tx().commit(); + this.commitTx(); tom = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -6634,7 +6709,7 @@ public void testUpdateVertexPropertyOfAggregateType() { tom.property("testNum", 1); tom.property("rank", 8); tom.property("reword", 8); - graph.tx().commit(); + this.commitTx(); tom = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -6650,7 +6725,7 @@ public void testUpdateVertexPropertyOfAggregateType() { tom.property("testNum", 1); tom.property("rank", 1); tom.property("reword", 1); - graph.tx().commit(); + this.commitTx(); tom = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -6713,7 +6788,7 @@ public void testAddAndUpdateVertexPropertyOfAggregateType() { Assert.assertEquals(ImmutableSet.of(8, 12), result.value("rank")); Assert.assertEquals(ImmutableList.of(8, 12), result.value("reword")); - graph.tx().commit(); + this.commitTx(); result = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -6748,7 +6823,7 @@ public void testAddAndUpdateVertexPropertyOfAggregateType() { Assert.assertEquals(ImmutableList.of(2, 1), tom.value("reword")); - graph.tx().commit(); + this.commitTx(); result = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); Assert.assertEquals(65, result.value("worstScore")); @@ -6827,7 +6902,7 @@ public void testQueryVertexByAggregateProperty() { graph.addVertex(T.label, "student", "name", "Tom", "worstScore", 55, "bestScore", 96, "testNum", 1, "no", "001"); - graph.tx().commit(); + this.commitTx(); List vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -6864,7 +6939,7 @@ public void testQueryVertexByAggregateProperty() { tom.property("bestScore", 98); tom.property("testNum", 1); tom.property("no", "002"); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -6902,7 +6977,7 @@ public void testQueryVertexByAggregateProperty() { tom.property("bestScore", 99); tom.property("testNum", 1); tom.property("no", "003"); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -6940,7 +7015,7 @@ public void testQueryVertexByAggregateProperty() { tom.property("bestScore", 100); tom.property("testNum", 1); tom.property("no", "004"); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -6978,19 +7053,19 @@ public void testQueryVertexByAggregateProperty() { tom.property("bestScore", 99); tom.property("testNum", 1); tom.property("no", "005"); - graph.tx().commit(); + this.commitTx(); tom.property("worstScore", 65); tom.property("bestScore", 93); tom.property("testNum", 1); tom.property("no", "006"); - graph.tx().commit(); + this.commitTx(); tom.property("worstScore", 58); tom.property("bestScore", 63); tom.property("testNum", 1); tom.property("no", "007"); - graph.tx().commit(); + this.commitTx(); vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -7076,7 +7151,7 @@ public void testUpdateVertexWithAggregatePropertyMultiTimes() { graph.addVertex(T.label, "student", "name", "Tom", "worstScore", 55, "bestScore", 96, "testNum", 1, "no", "001", "rank", 1, "reword", 1); - graph.tx().commit(); + this.commitTx(); List vertices = graph.traversal().V().hasLabel("student") .has("name", "Tom").toList(); @@ -7107,7 +7182,7 @@ public void testUpdateVertexWithAggregatePropertyMultiTimes() { reword = random.nextInt(); rewords.add(reword); tom.property("reword", reword); - graph.tx().commit(); + this.commitTx(); tom = graph.traversal().V().hasLabel("student") .has("name", "Tom").next(); @@ -7130,7 +7205,7 @@ public void testInsertAndInsertVertex() { "name", "Tom", "lived", "Beijing"); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); Vertex vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -7143,7 +7218,7 @@ public void testInsertAndDeleteVertex() { Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7155,7 +7230,7 @@ public void testInsertAndAppendVertex() { Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -7168,7 +7243,7 @@ public void testInsertAndEliminateVertex() { Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -7185,7 +7260,7 @@ public void testDeleteAndInsertVertex() { graph.traversal().V().hasLabel("author").has("id", 1).next().remove(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); Vertex vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); @@ -7200,7 +7275,7 @@ public void testDeleteAndDeleteVertex() { "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7213,7 +7288,7 @@ public void testDeleteAndAppendVertex() { "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7226,7 +7301,7 @@ public void testDeleteAndEliminateVertex() { "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7241,7 +7316,7 @@ public void testAppendAndInsertVertex() { vertex.property("lived", "Wuhan"); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); @@ -7256,7 +7331,7 @@ public void testAppendAndDeleteVertex() { "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Wuhan"); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7268,7 +7343,7 @@ public void testAppendAndAppendSameVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Wuhan"); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Shanghai", vertex.property("lived").value()); @@ -7281,7 +7356,7 @@ public void testAppendAndAppendDifferentVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("name", "Tomcat"); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertEquals("Tomcat", vertex.property("name").value()); @@ -7295,7 +7370,7 @@ public void testAppendAndEliminateSameVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Shanghai"); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -7308,7 +7383,7 @@ public void testAppendAndEliminateDifferentVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("name", "Tomcat"); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -7325,7 +7400,7 @@ public void testEliminateAndInsertVertex() { vertex.property("lived").remove(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); @@ -7340,7 +7415,7 @@ public void testEliminateAndDeleteVertex() { "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7352,7 +7427,7 @@ public void testEliminateAndAppendSameVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.property("lived", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); @@ -7367,7 +7442,7 @@ public void testEliminateAndAppendDifferentVertexProperty() { vertex.property("lived").remove(); vertex.property("name", "Tomcat"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -7381,7 +7456,7 @@ public void testEliminateAndEliminateSameVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); @@ -7394,7 +7469,7 @@ public void testEliminateAndEliminateDifferentVertexProperty() { "name", "Tom", "lived", "Beijing"); vertex.property("age").remove(); vertex.property("lived").remove(); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("age").isPresent()); @@ -7407,7 +7482,7 @@ public void testOverrideVertex() { graph.addVertex(T.label, "person", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.mayCommitTx(); Vertex vertex = vertex("person", "name", "marko"); Assert.assertTrue(vertex.property("age").isPresent()); Assert.assertEquals(18, vertex.value("age")); @@ -7415,7 +7490,7 @@ public void testOverrideVertex() { Assert.assertEquals("Beijing", vertex.value("city")); graph.addVertex(T.label, "person", "name", "marko", "city", "Wuhan"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("person", "name", "marko"); Assert.assertFalse(vertex.property("age").isPresent()); Assert.assertTrue(vertex.property("city").isPresent()); @@ -7423,7 +7498,7 @@ public void testOverrideVertex() { graph.addVertex(T.label, "person", "name", "marko", "age", 19, "city", "Shanghai"); - graph.tx().commit(); + this.mayCommitTx(); vertex = vertex("person", "name", "marko"); Assert.assertTrue(vertex.property("age").isPresent()); Assert.assertEquals(19, vertex.value("age")); @@ -7431,7 +7506,6 @@ public void testOverrideVertex() { Assert.assertEquals("Shanghai", vertex.value("city")); } - @SuppressWarnings("unchecked") @Test public void testScanVertex() { HugeGraph graph = graph(); @@ -7440,12 +7514,14 @@ public void testScanVertex() { storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); init10Vertices(); + this.commitTx(); List vertices = new LinkedList<>(); long splitSize = 1 * 1024 * 1024; - Object splits = graph.metadata(HugeType.VERTEX, "splits", splitSize); - for (Shard split : (List) splits) { + List splits = graph.metadata(HugeType.VERTEX, "splits", + splitSize); + for (Shard split : splits) { ConditionQuery q = new ConditionQuery(HugeType.VERTEX); q.scan(split.start(), split.end()); vertices.addAll(ImmutableList.copyOf(graph.vertices(q))); @@ -7461,6 +7537,7 @@ public void testScanVertexInPaging() { storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); init10Vertices(); + this.commitTx(); List vertices = new LinkedList<>(); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); @@ -7957,6 +8034,27 @@ public void testQueryByPageWithOffset() { }); } + @Test + public void testQueryByPageWithtUncommittedRecords() { + Assume.assumeTrue("Not support paging", + storeFeatures().supportsQueryByPage()); + + HugeGraph graph = graph(); + + graph.addVertex(T.label, "author", "id", 1, + "name", "James Gosling", "age", 62, + "lived", "Canadian"); + graph.addVertex(T.label, "author", "id", 2, + "name", "Guido van Rossum", "age", 61, + "lived", "California"); + + Assert.assertThrows(IllegalArgumentException.class, () -> { + graph.traversal().V() + .has("~page", "") + .toList(); + }); + } + @Test public void testQueryByLabelInPageWithLimitLtePageSize() { Assume.assumeTrue("Not support paging", @@ -8604,16 +8702,16 @@ public void testAddCustomizedIdVerticesContainsExisted() { graph.addVertex(T.label, "programmer", T.id, "123456", "name", "marko", "age", 18, "city", "Beijing"); - graph.tx().commit(); + this.commitTx(); graph.addVertex(T.label, "programmer", T.id, "123456", "name", "marko", "age", 19, "city", "Beijing"); - graph.tx().commit(); + this.commitTx(); graph.addVertex(T.label, "designer", T.id, "123456", "name", "marko", "age", 18, "city", "Beijing"); Assert.assertThrows(HugeException.class, () -> { - graph.tx().commit(); + this.commitTx(); }); } @@ -8627,7 +8725,7 @@ public void testQueryVerticesByIdsWithHasIdFilterAndNumberId() { graph.addVertex(T.label, "user", T.id, 123); graph.addVertex(T.label, "user", T.id, 456); graph.addVertex(T.label, "user", T.id, 789); - graph.tx().commit(); + this.mayCommitTx(); GraphTraversalSource g = graph.traversal(); List vertices; @@ -8662,7 +8760,7 @@ public void testQueryVerticesByLabelsWithOneLabelNotExist() { graph.addVertex(T.label, "user1", T.id, 123); graph.addVertex(T.label, "user2", T.id, 456); graph.addVertex(T.label, "user2", T.id, 789); - graph.tx().commit(); + this.mayCommitTx(); GraphTraversalSource g = graph.traversal(); List vertices; @@ -8800,7 +8898,7 @@ public void testAddVertexWithSpecialSymbolInPrimaryValues() { Vertex vertex3 = graph.addVertex(T.label, "person", "name", "xyz\u0003abc", "city", "Hongkong", "age", 13); - graph.tx().commit(); + this.mayCommitTx(); GraphTraversalSource g = graph.traversal(); @@ -8888,7 +8986,7 @@ public void testQueryBySearchIndexWithSpecialSymbol() { Vertex vertex6 = graph.addVertex(T.label, "person", "name", "6", "city", "\u0001", "age", 15); - graph.tx().commit(); + this.commitTx(); GraphTraversalSource g = graph.traversal(); @@ -8990,7 +9088,7 @@ public void testEnhanceTextMatch() { "city", "Beijing", "age", 23); Vertex vertex5 = graph.addVertex(T.label, "person", "name", "秦始皇帝", "city", "Beijing", "age", 29); - graph.tx().commit(); + this.commitTx(); GraphTraversalSource g = graph.traversal(); @@ -9037,7 +9135,7 @@ private void init10Vertices() { graph.addVertex(T.label, "book", "name", "java-4"); graph.addVertex(T.label, "book", "name", "java-5"); - graph.tx().commit(); + this.mayCommitTx(); } private void init100Books() { @@ -9047,7 +9145,7 @@ private void init100Books() { graph.addVertex(T.label, "book", "name", "java-" + i, "price", i); } - graph.tx().commit(); + this.commitTx(); } private void init5Persons() { @@ -9069,7 +9167,7 @@ private void init5Persons() { "city", "Taipei", "age", 21, "birth", Utils.date("2016-01-01 00:00:00.000")); - graph.tx().commit(); + this.commitTx(); } private void init100Persons() { @@ -9083,7 +9181,7 @@ private void init100Persons() { "age", i % 11); } - graph.tx().commit(); + this.commitTx(); } private void init5Computers() { @@ -9107,7 +9205,7 @@ private void init5Computers() { "band", "asus", "cpu", "3.2GHz", "ram", "16GB", "price", 6999); - graph.tx().commit(); + this.commitTx(); } private void initPageTestData() { @@ -9193,7 +9291,7 @@ private void initPageTestData() { graph().addVertex(T.label, "software", T.id, id, "name", "marko", "lang", "java", "price", price); } - graph().tx().commit(); + this.commitTx(); } private Vertex vertex(String label, String pkName, Object pkValue) { From 3e1e0acc4720eb1a0ecef2917089926aa673c1c3 Mon Sep 17 00:00:00 2001 From: Zhangmei Li Date: Fri, 1 Apr 2022 21:16:31 +0800 Subject: [PATCH 7/7] check limit query with uncommitted insert Change-Id: I5429f8a8314b69c7f8fa5c8da05a5e587e87c9c8 --- .../backend/tx/GraphTransaction.java | 10 +-- .../baidu/hugegraph/core/EdgeCoreTest.java | 42 ++++++++- .../baidu/hugegraph/core/VertexCoreTest.java | 87 ++++++++++++------- 3 files changed, 103 insertions(+), 36 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java index a035a5560b..b869418812 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java @@ -778,10 +778,9 @@ public Iterator queryVertices() { public Iterator queryVertices(Query query) { if (this.hasUpdate()) { - E.checkArgument(this.removedVertices.isEmpty() || - query.noLimitAndOffset(), + E.checkArgument(query.noLimitAndOffset(), "It's not allowed to query with offser/limit " + - "when there are uncommitted delete records."); + "when there are uncommitted records."); // TODO: also add check: no SCAN, no OLAP E.checkArgument(!query.paging(), "It's not allowed to query by paging when " + @@ -943,10 +942,9 @@ public Iterator queryEdges() { @Watched public Iterator queryEdges(Query query) { if (this.hasUpdate()) { - E.checkArgument(this.removedEdges.isEmpty() || - query.noLimitAndOffset(), + E.checkArgument(query.noLimitAndOffset(), "It's not allowed to query with offser/limit " + - "when there are uncommitted delete records."); + "when there are uncommitted records."); // TODO: also add check: no SCAN, no OLAP E.checkArgument(!query.paging(), "It's not allowed to query by paging when " + diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java index 51147737b4..c202f67e5a 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/EdgeCoreTest.java @@ -1828,12 +1828,13 @@ public void testQueryAllWithLimit() { } @Test - public void testQueryAllWithLimitAfterDelete() { + public void testQueryAllWithLimitAfterUncommittedDelete() { HugeGraph graph = graph(); init18Edges(); // Query all with limit after delete graph.traversal().E().limit(14).drop().iterate(); + Assert.assertThrows(IllegalArgumentException.class, () -> { // Query count with uncommitted records graph.traversal().E().count().next(); @@ -1842,6 +1843,11 @@ public void testQueryAllWithLimitAfterDelete() { // Query with limit graph.traversal().E().limit(3).toList(); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with offset + graph.traversal().E().range(1, -1).toList(); + }); + graph.tx().commit(); Assert.assertEquals(4L, graph.traversal().E().count().next()); List edges = graph.traversal().E().limit(3).toList(); @@ -1854,6 +1860,40 @@ public void testQueryAllWithLimitAfterDelete() { Assert.assertEquals(1, edges.size()); } + @Test + public void testQueryAllWithLimitAfterUncommittedInsert() { + HugeGraph graph = graph(); + init18Edges(); + + // Query all with limit after insert + Vertex james = graph.addVertex(T.label, "author", "id", 3, + "name", "James Gosling", "age", 62, + "lived", "Canadian"); + + Vertex book = graph.addVertex(T.label, "book", "name", "Test-Book-1"); + + james.addEdge("authored", book, + "comment", "good book!", + "comment", "good book!", + "comment", "good book too!"); + + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query count with uncommitted records + graph.traversal().E().count().next(); + }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with limit + graph.traversal().E().limit(3).toList(); + }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with offset + graph.traversal().E().range(1, -1).toList(); + }); + + graph.tx().commit(); + Assert.assertEquals(19L, graph.traversal().E().count().next()); + } + @Test public void testQueryAllWithLimitByQueryEdges() { HugeGraph graph = graph(); diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java index 28f7f494f0..7ab9be2c95 100644 --- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java +++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/VertexCoreTest.java @@ -2100,8 +2100,7 @@ public void testAddOlapNoneProperties() { .writeType(WriteType.OLAP_COMMON) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2187,8 +2186,7 @@ public void testAddOlapSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2275,8 +2273,7 @@ public void testAddOlapRangeProperties() { .writeType(WriteType.OLAP_RANGE) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2401,8 +2398,7 @@ public void testAddOlapRangeAndOlapSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2577,8 +2573,7 @@ public void testQueryOlapRangeAndRegularSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2694,8 +2689,7 @@ public void testQueryOlapWithUpdates() { .writeType(WriteType.OLAP_RANGE) .ifNotExist().create(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, @@ -2768,7 +2762,7 @@ public void testQueryAllWithGraphAPI() { @Test public void testQueryAllWithLimit() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); // Query all with limit List vertices = graph.traversal().V().limit(6).toList(); @@ -2776,12 +2770,13 @@ public void testQueryAllWithLimit() { } @Test - public void testQueryAllWithLimitAfterDelete() { + public void testQueryAllWithLimitAfterUncommittedDelete() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); // Query all with limit after delete graph.traversal().V().limit(6).drop().iterate(); + Assert.assertThrows(IllegalArgumentException.class, () -> { // Query count with uncommitted records graph.traversal().V().count().next(); @@ -2790,6 +2785,10 @@ public void testQueryAllWithLimitAfterDelete() { // Query with limit graph.traversal().V().limit(3).toList(); }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with offset + graph.traversal().V().range(1, -1).toList(); + }); this.commitTx(); Assert.assertEquals(4L, graph.traversal().V().count().next()); @@ -2803,10 +2802,37 @@ public void testQueryAllWithLimitAfterDelete() { Assert.assertEquals(1, vertices.size()); } + @Test + public void testQueryAllWithLimitAfterUncommittedInsert() { + HugeGraph graph = graph(); + this.init10VerticesAndCommit(); + + // Query all with limit after insert + graph.addVertex(T.label, "author", "id", 3, + "name", "test", "age", 88, + "lived", "California"); + + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query count with uncommitted records + graph.traversal().V().count().next(); + }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with limit + graph.traversal().V().limit(3).toList(); + }); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with offset + graph.traversal().V().range(1, -1).toList(); + }); + + this.commitTx(); + Assert.assertEquals(11L, graph.traversal().V().count().next()); + } + @Test public void testQueryAllWithLimitByQueryVertices() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); Query query = new Query(HugeType.VERTEX); query.limit(1); @@ -2819,7 +2845,7 @@ public void testQueryAllWithLimitByQueryVertices() { @Test public void testQueryAllWithLimit0() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); // Query all with limit 0 List vertices = graph.traversal().V().limit(0).toList(); @@ -2840,7 +2866,7 @@ public void testQueryAllWithNoLimit() { @Test public void testQueryAllWithIllegalLimit() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); Assert.assertThrows(IllegalArgumentException.class, () -> { graph.traversal().V().limit(-2).toList(); @@ -2854,7 +2880,7 @@ public void testQueryAllWithIllegalLimit() { @Test public void testQueryAllWithOffset() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V().range(8, 100).toList(); Assert.assertEquals(2, vertices.size()); @@ -2866,7 +2892,7 @@ public void testQueryAllWithOffset() { @Test public void testQueryAllWithOffsetAndLimit() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V().range(8, 9).toList(); Assert.assertEquals(1, vertices.size()); @@ -2890,7 +2916,7 @@ public void testQueryAllWithOffsetAndLimit() { @Test public void testQueryAllWithOffsetAndLimitWithMultiTimes() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V() .range(1, 6) @@ -2924,7 +2950,7 @@ public void testQueryAllWithOffsetAndLimitWithMultiTimes() { @Test public void testQueryAllWithIllegalOffsetOrLimit() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); Assert.assertThrows(IllegalArgumentException.class, () -> { graph.traversal().V().range(8, 7).toList(); @@ -2947,6 +2973,7 @@ public void testQueryAllWithIllegalOffsetOrLimit() { public void testQueryWithSplicingId() { HugeGraph graph = graph(); init10Vertices(); + List vertices = graph.traversal().V().toList(); String bookId = graph.vertexLabel("book").id().asString(); Assert.assertTrue(Utils.containsId(vertices, @@ -3036,8 +3063,7 @@ public void testQueryByIdWithGraphAPIAndNotCommitedUpdate() { @Test public void testQueryByIdWithGraphAPIAndNotCommitedRemoved() { HugeGraph graph = graph(); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V() .hasLabel("author").toList(); @@ -3145,7 +3171,7 @@ public void testQueryByLabel() { @Test public void testQueryByLabelWithLimit() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); // Query by vertex label with limit List vertices = graph.traversal().V().hasLabel("book") @@ -7513,8 +7539,7 @@ public void testScanVertex() { Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); List vertices = new LinkedList<>(); @@ -7536,8 +7561,7 @@ public void testScanVertexInPaging() { Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); - init10Vertices(); - this.commitTx(); + this.init10VerticesAndCommit(); List vertices = new LinkedList<>(); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); @@ -9114,6 +9138,11 @@ public void testEnhanceTextMatch() { Assert.assertTrue(vertices.contains(vertex4)); } + private void init10VerticesAndCommit() { + this.init10Vertices(); + this.commitTx(); + } + private void init10Vertices() { HugeGraph graph = graph();