Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 107eb26

Browse files
committed
check for correct interfaces instead of relying on string comparison when deleting indexes on cleanup
1 parent 2a7ac1d commit 107eb26

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/test/java/org/neo4j/rest/graphdb/Neo4jDatabaseCleaner.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import org.neo4j.graphdb.Node;
2929
import org.neo4j.graphdb.Relationship;
3030
import org.neo4j.graphdb.Transaction;
31+
import org.neo4j.graphdb.index.Index;
3132
import org.neo4j.graphdb.index.IndexManager;
33+
import org.neo4j.graphdb.index.ReadableIndex;
34+
import org.neo4j.graphdb.index.RelationshipIndex;
3235
import org.neo4j.rest.graphdb.index.RestAutoIndexer;
3336
import org.neo4j.tooling.GlobalGraphOperations;
3437

@@ -79,13 +82,15 @@ private void clearIndex(Map<String, Object> result) {
7982
result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
8083
result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
8184
for (String ix : indexManager.nodeIndexNames()) {
82-
if (!(RestAutoIndexer.NODE_AUTO_INDEX).equals(ix)) { // autoindex is not deletable
83-
indexManager.forNodes(ix).delete();
85+
Index<Node> nodeIndex = indexManager.forNodes(ix);
86+
if (!(nodeIndex instanceof ReadableIndex)) {
87+
nodeIndex.delete();
8488
}
8589
}
8690
for (String ix : indexManager.relationshipIndexNames()) {
87-
if (!(RestAutoIndexer.RELATIONSHIP_AUTO_INDEX).equals(ix)) { // autoindex is not deletable
88-
indexManager.forRelationships(ix).delete();
91+
RelationshipIndex relationshipIndex = indexManager.forRelationships(ix);
92+
if (!(relationshipIndex instanceof ReadableIndex)) {
93+
relationshipIndex.delete();
8994
}
9095
}
9196
}

0 commit comments

Comments
 (0)