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/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 a2fda90dad..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,14 +631,29 @@ public OptimizedType optimized() { return this.optimizedType; } - public void registerResultsFilter(Function filter) { + public void registerResultsFilter(ResultsFilter 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(ResultsFilter filter) { + this.resultsFilter = filter; + Query originQuery = this.originQuery(); + if (originQuery instanceof ConditionQuery) { + ConditionQuery originCQ = ((ConditionQuery) originQuery); + originCQ.updateResultsFilter(filter); } } @@ -638,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()); @@ -717,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); @@ -733,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); @@ -758,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; @@ -767,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; @@ -804,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; } } @@ -847,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 d497cb9e6a..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) { @@ -1053,7 +1054,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 +1175,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 +1628,25 @@ private static class IndexQueries extends HashMap { private static final long serialVersionUID = 1400326138090922676L; + private static final IndexQueries EMPTY = new IndexQueries(null); + + private final ConditionQuery parentQuery; - public static final IndexQueries EMPTY = new IndexQueries(); + 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 +1671,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 @@ -1712,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 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..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 @@ -777,9 +777,15 @@ 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(query.noLimitAndOffset(), + "It's not allowed to query with offser/limit " + + "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 " + + "there are uncommitted records."); + } query.resetActualOffset(); @@ -935,9 +941,15 @@ 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(query.noLimitAndOffset(), + "It's not allowed to query with offser/limit " + + "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 " + + "there are uncommitted records."); + } query.resetActualOffset(); 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", 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..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 @@ -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,17 @@ private void clearSchema() { }); } + protected void mayCommitTx() { + // Commit tx probabilistically for test + if (new Random().nextBoolean()) { + graph().tx().commit(); + } + } + + protected void commitTx() { + graph().tx().commit(); + } + protected BackendFeatures storeFeatures() { return graph().backendStoreFeatures(); } 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 674f0e1ec5..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 @@ -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"), @@ -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,8 @@ public void testAddVertexWithCollectionIndex() { ImmutableList.of("hello graph", "graph database"), "tags", ImmutableList.of("graphdb", "gremlin")); - graph.tx().commit(); + // TODO: test mayCommitTx() after support textContains(collection, str) + this.commitTx(); List vertices; vertices = graph.traversal().V() @@ -643,47 +645,45 @@ 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 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")).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")); - graph.tx().commit(); + "category", ImmutableList.of("hello graph", + "graph database"), + "tags", ImmutableList.of("graphdb", + "new_tag")); + this.mayCommitTx(); vertices = graph.traversal().V() .has("soft", "tags", ConditionP.contains("gremlin")) @@ -702,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")) @@ -780,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 @@ -807,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()); @@ -881,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()); @@ -891,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()); @@ -921,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()); @@ -931,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()); @@ -974,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"); @@ -997,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()); @@ -1053,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()); @@ -1116,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"); @@ -1193,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); @@ -1215,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); @@ -1230,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); @@ -1248,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); @@ -1283,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()); @@ -1304,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); @@ -1347,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"); @@ -1378,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); @@ -1417,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); @@ -1443,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 { @@ -1459,7 +1462,7 @@ public void testAddVertexWithUniqueIndexAndTtl() { graph().addVertex(T.label, "fan", "name", "Baby2", "age", 3, "city", "Beijing"); - graph().tx().commit(); + this.commitTx(); } @Test @@ -1469,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); @@ -1486,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 @@ -1496,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); @@ -1528,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()); @@ -1549,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); @@ -1570,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 @@ -1597,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); @@ -1644,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"); @@ -1675,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); @@ -1700,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"); @@ -1738,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); @@ -1785,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); @@ -1801,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", @@ -1812,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); @@ -1830,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"); @@ -1842,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); @@ -1865,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"); @@ -1874,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); @@ -1902,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", @@ -1935,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); @@ -1977,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", @@ -2022,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); @@ -2062,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"); @@ -2071,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); @@ -2097,7 +2100,8 @@ public void testAddOlapNoneProperties() { .writeType(WriteType.OLAP_COMMON) .ifNotExist().create(); - init10Vertices(); + this.init10VerticesAndCommit(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2127,7 +2131,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, () -> { @@ -2182,7 +2186,8 @@ public void testAddOlapSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); + this.init10VerticesAndCommit(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2212,7 +2217,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, () -> { @@ -2268,7 +2273,8 @@ public void testAddOlapRangeProperties() { .writeType(WriteType.OLAP_RANGE) .ifNotExist().create(); - init10Vertices(); + this.init10VerticesAndCommit(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2298,7 +2304,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, () -> { @@ -2392,7 +2398,8 @@ public void testAddOlapRangeAndOlapSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); + this.init10VerticesAndCommit(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2422,7 +2429,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"); @@ -2435,7 +2442,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, () -> { @@ -2566,7 +2573,8 @@ public void testQueryOlapRangeAndRegularSecondaryProperties() { .writeType(WriteType.OLAP_SECONDARY) .ifNotExist().create(); - init10Vertices(); + this.init10VerticesAndCommit(); + String author = graph.vertexLabel("author").id().asString(); Id id1 = SplicingIdGenerator.splicing(author, LongEncoding.encodeNumber(1)); @@ -2576,12 +2584,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, () -> { @@ -2669,6 +2677,50 @@ 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(); + + this.init10VerticesAndCommit(); + + 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(); @@ -2710,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(); @@ -2718,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(); @@ -2732,22 +2785,54 @@ public void testQueryAllWithLimitAfterDelete() { // Query with limit graph.traversal().V().limit(3).toList(); }); - graph.tx().commit(); + Assert.assertThrows(IllegalArgumentException.class, () -> { + // Query with offset + graph.traversal().V().range(1, -1).toList(); + }); + + 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()); } + @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); @@ -2760,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(); @@ -2781,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(); @@ -2795,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()); @@ -2807,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()); @@ -2831,7 +2916,7 @@ public void testQueryAllWithOffsetAndLimit() { @Test public void testQueryAllWithOffsetAndLimitWithMultiTimes() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V() .range(1, 6) @@ -2865,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(); @@ -2888,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, @@ -2977,7 +3063,7 @@ public void testQueryByIdWithGraphAPIAndNotCommitedUpdate() { @Test public void testQueryByIdWithGraphAPIAndNotCommitedRemoved() { HugeGraph graph = graph(); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = graph.traversal().V() .hasLabel("author").toList(); @@ -3085,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") @@ -3094,7 +3180,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(); @@ -3312,7 +3398,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()); @@ -3659,7 +3746,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(); @@ -3690,7 +3777,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") @@ -3749,7 +3836,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(); @@ -3831,7 +3918,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(); @@ -3926,7 +4013,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(); @@ -4039,7 +4126,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(); @@ -4126,7 +4213,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) @@ -4234,7 +4321,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(); @@ -4370,7 +4458,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(); @@ -4399,7 +4487,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(); @@ -4431,7 +4519,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")) @@ -4464,7 +4552,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() @@ -4508,7 +4596,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") @@ -4577,7 +4665,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") @@ -4603,14 +4691,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") @@ -4632,7 +4720,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") @@ -4688,7 +4776,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()); @@ -4705,7 +4793,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(); @@ -4803,9 +4891,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)) @@ -4891,7 +4980,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(); @@ -4902,6 +4991,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(); @@ -4934,6 +5027,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) @@ -4958,7 +5052,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") @@ -4990,7 +5084,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(); @@ -5007,7 +5101,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(); @@ -5032,7 +5126,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() @@ -5079,7 +5173,7 @@ public void testQueryByJointIndexesWithSearchAndRangeAndSecondaryIndexes() { "city", "Shanghai", "description", "yellow hair golden tail"); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V() @@ -5141,7 +5235,7 @@ public void testQueryByJointIndexesWithTwoSearchAndOneRangeIndexes() { "city", "Shanghai Pudong", "description", "yellow hair golden tail"); - graph().tx().commit(); + this.commitTx(); List vertices; vertices = graph().traversal().V() @@ -5191,6 +5285,70 @@ 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); + + this.mayCommitTx(); + + 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(); @@ -5210,7 +5368,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") @@ -5693,15 +5851,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 @@ -5715,7 +5874,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(); }); } @@ -5730,16 +5889,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 @@ -5754,38 +5914,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 " + @@ -5793,16 +5953,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(); }); } @@ -5823,7 +5983,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(); @@ -5848,7 +6008,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()); @@ -5873,7 +6033,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()); @@ -5884,7 +6044,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()); @@ -5895,7 +6055,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()); @@ -5914,7 +6074,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()); @@ -5924,7 +6084,7 @@ public void testRemoveVertexOfNotExists() { // Remove again vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); } @Test @@ -5954,7 +6114,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()); } } @@ -5964,13 +6124,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()); @@ -5983,13 +6143,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()); @@ -6000,13 +6160,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"); @@ -6029,7 +6189,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"); @@ -6041,7 +6201,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, () -> { @@ -6061,7 +6221,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; @@ -6084,7 +6244,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()); @@ -6095,7 +6255,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()); @@ -6111,7 +6271,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()); @@ -6120,7 +6280,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()); @@ -6129,7 +6289,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()); @@ -6138,7 +6298,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()); @@ -6151,10 +6311,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"), @@ -6163,7 +6323,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")); @@ -6172,7 +6332,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")); @@ -6185,14 +6345,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()); @@ -6202,7 +6362,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()); @@ -6266,7 +6426,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")); @@ -6280,7 +6440,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()); @@ -6295,7 +6455,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()); @@ -6316,7 +6476,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()); @@ -6325,7 +6485,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()); @@ -6341,7 +6501,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()); @@ -6350,7 +6510,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()); @@ -6366,8 +6526,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()); @@ -6384,11 +6543,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()); @@ -6399,7 +6558,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(); @@ -6407,7 +6566,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()); @@ -6422,7 +6581,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()); @@ -6433,7 +6592,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, () -> { @@ -6457,9 +6616,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"); @@ -6477,7 +6640,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(); @@ -6494,7 +6657,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(); @@ -6542,7 +6705,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(); @@ -6557,7 +6720,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(); @@ -6572,7 +6735,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(); @@ -6588,7 +6751,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(); @@ -6651,7 +6814,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(); @@ -6686,7 +6849,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")); @@ -6765,7 +6928,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(); @@ -6802,7 +6965,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(); @@ -6840,7 +7003,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(); @@ -6878,7 +7041,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(); @@ -6916,19 +7079,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(); @@ -7014,7 +7177,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(); @@ -7045,7 +7208,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(); @@ -7068,7 +7231,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()); @@ -7081,7 +7244,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)); } @@ -7093,7 +7256,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()); @@ -7106,7 +7269,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()); @@ -7123,7 +7286,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()); @@ -7138,7 +7301,7 @@ public void testDeleteAndDeleteVertex() { "name", "Tom", "lived", "Beijing"); vertex.remove(); vertex.remove(); - graph.tx().commit(); + this.mayCommitTx(); Assert.assertNull(vertex("author", "id", 1)); } @@ -7151,7 +7314,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)); } @@ -7164,7 +7327,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)); } @@ -7179,7 +7342,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()); @@ -7194,7 +7357,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)); } @@ -7206,7 +7369,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()); @@ -7219,7 +7382,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()); @@ -7233,7 +7396,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()); @@ -7246,7 +7409,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()); @@ -7263,7 +7426,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()); @@ -7278,7 +7441,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)); } @@ -7290,7 +7453,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()); @@ -7305,7 +7468,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()); @@ -7319,7 +7482,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()); @@ -7332,7 +7495,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()); @@ -7345,7 +7508,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")); @@ -7353,7 +7516,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()); @@ -7361,7 +7524,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")); @@ -7369,7 +7532,6 @@ public void testOverrideVertex() { Assert.assertEquals("Shanghai", vertex.value("city")); } - @SuppressWarnings("unchecked") @Test public void testScanVertex() { HugeGraph graph = graph(); @@ -7377,13 +7539,14 @@ public void testScanVertex() { Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); - init10Vertices(); + this.init10VerticesAndCommit(); 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))); @@ -7398,7 +7561,7 @@ public void testScanVertexInPaging() { Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange()); - init10Vertices(); + this.init10VerticesAndCommit(); List vertices = new LinkedList<>(); ConditionQuery query = new ConditionQuery(HugeType.VERTEX); @@ -7895,6 +8058,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", @@ -8542,16 +8726,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(); }); } @@ -8565,7 +8749,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; @@ -8600,7 +8784,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; @@ -8738,7 +8922,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(); @@ -8826,7 +9010,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(); @@ -8928,7 +9112,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(); @@ -8954,6 +9138,11 @@ public void testEnhanceTextMatch() { Assert.assertTrue(vertices.contains(vertex4)); } + private void init10VerticesAndCommit() { + this.init10Vertices(); + this.commitTx(); + } + private void init10Vertices() { HugeGraph graph = graph(); @@ -8975,7 +9164,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() { @@ -8985,7 +9174,7 @@ private void init100Books() { graph.addVertex(T.label, "book", "name", "java-" + i, "price", i); } - graph.tx().commit(); + this.commitTx(); } private void init5Persons() { @@ -9007,7 +9196,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() { @@ -9021,7 +9210,7 @@ private void init100Persons() { "age", i % 11); } - graph.tx().commit(); + this.commitTx(); } private void init5Computers() { @@ -9045,7 +9234,7 @@ private void init5Computers() { "band", "asus", "cpu", "3.2GHz", "ram", "16GB", "price", 6999); - graph.tx().commit(); + this.commitTx(); } private void initPageTestData() { @@ -9131,7 +9320,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) {