Skip to content

Commit

Permalink
neo4j-contrib#367: fix IllegalStateException when removing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
sarmbruster committed Apr 20, 2017
1 parent 3e4124f commit 279a7b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Collection<Consumer<Void>> beforeCommit(TransactionData data) throws Exce
getIndexesByLabelAndProperty();
Collection<Consumer<Void>> state = async ? new LinkedList<>() : null;

iterateNodePropertyChange(stream(data.assignedNodeProperties()),(index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
iterateNodePropertyChange(stream(data.assignedNodeProperties()),false, (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
if (oldValue != null) {
index.remove(node, key);
index.remove(node, FreeTextSearch.KEY);
Expand All @@ -68,7 +68,7 @@ public Collection<Consumer<Void>> beforeCommit(TransactionData data) throws Exce
}));

// filter out removedNodeProperties from node deletions
iterateNodePropertyChange(stream(data.removedNodeProperties()).filter(nodePropertyEntry -> !contains(data.deletedNodes().iterator(), nodePropertyEntry.entity())), (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
iterateNodePropertyChange(stream(data.removedNodeProperties()).filter(nodePropertyEntry -> !contains(data.deletedNodes().iterator(), nodePropertyEntry.entity())), true, (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
index.remove(node, key);
index.remove(node, FreeTextSearch.KEY);
}));
Expand Down Expand Up @@ -99,12 +99,12 @@ public void afterCommit(TransactionData data, Collection<Consumer<Void>> state)
}
}

private void iterateNodePropertyChange(Stream<PropertyEntry<Node>> stream,
private void iterateNodePropertyChange(Stream<PropertyEntry<Node>> stream, boolean propertyRemoved,
IndexFunction<Index<Node>, Node, String, Object, Object> function) {
stream.forEach(nodePropertyEntry -> {
final Node entity = nodePropertyEntry.entity();
final String key = nodePropertyEntry.key();
final Object value = nodePropertyEntry.value();
final Object value = propertyRemoved ? null : nodePropertyEntry.value();
entity.getLabels().forEach(label -> {
final String labelName = label.name();
final Map<String, Collection<Index<Node>>> propertyIndexMap = indexesByLabelAndProperty.get(labelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public void shouldDeletingIndexedNodesSucceed() {

// nothing found in the index after deletion
testCallCount(db, "start n=node:search_index('City.name:\"Made Up\"') return n", null, 0);

}

@Test
public void shouldIndexFieldsBeUsedConsistently() throws InterruptedException {
public void shouldIndexFieldsBeUsedConsistently() {
// setup: add a node, index it and add another node
testCallEmpty(db, "create (c:City{name:\"Made Up City\",url:\"/places/nowhere/made-up-city\"})", null);

Expand All @@ -58,8 +57,17 @@ public void shouldIndexFieldsBeUsedConsistently() throws InterruptedException {
testCallCount(db, "call apoc.index.search('search_index', 'City.name:Made') yield node, weight return node, weight", null, 2);
testCallCount(db, "start n=node:search_index('name:\"Made Up\"') return n", null, 0);
testCallCount(db, "start n=node:search_index('City.name:\"Made Up\"') return n", null, 2);

}

@Test
public void shouldRemovingPropertiesWork() {
//setup
testCallEmpty(db, "call apoc.index.addAllNodesExtended('submarines',{Submarine:['color']},{autoUpdate:true})", null);
testCallEmpty(db, "create (s:Submarine{color:\"yellow\",periscope:true})", null);
testCallEmpty(db, "create (s:Submarine{color:\"green\"})", null);

// when & then
testCallCount(db, "match (s:Submarine) remove s.periscope return s", null, 2);
}

}

0 comments on commit 279a7b4

Please sign in to comment.