Skip to content

Commit

Permalink
fix: bolt layer cannot deal with EmptyPath
Browse files Browse the repository at this point in the history
Returning an EmptyPath from a stored procedure works on java level, but bolt throws some strange exceptions.
In case of an EmptyPath instead a empty result (aka no line) is returned.
Refs: #8
  • Loading branch information
sarmbruster committed Jul 7, 2024
1 parent cfd6ff0 commit bb79bb2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 81 deletions.
3 changes: 1 addition & 2 deletions src/main/java/atag/chains/ChainsProcedure.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package atag.chains;

import atag.util.EmptyPath;
import atag.util.ResultTypes;
import org.neo4j.graphalgo.impl.util.PathImpl;
import org.neo4j.graphdb.*;
Expand Down Expand Up @@ -192,7 +191,7 @@ public Stream<ResultTypes.PathResult> update(
}
currentNode.createRelationshipTo(afterNode, relationshipType);
}
return asPathResult(builder == null ? new EmptyPath() : builder.build());
return builder == null ? Stream.empty() : asPathResult(builder.build());
}

private Node findNodeOrThrow(Label textLabel, String uuidProperty, String uuidText) {
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/atag/util/EmptyPath.java

This file was deleted.

45 changes: 22 additions & 23 deletions src/test/java/atag/chains/ChainsProcedureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ChainsProcedureTest {

@RegisterExtension
static Neo4jExtension neo4j = Neo4jExtension.builder()
.withDisabledServer()
//.withDisabledServer()
.withProcedure(ChainsProcedure.class)
/*.withFixture(db -> {
try {
Expand Down Expand Up @@ -92,20 +92,26 @@ private static void validatePathLength(GraphDatabaseService db, String query, Ma
db.executeTransactionally(query,
params,
result -> {
Path path = (Path) Iterators.single(result).get("path");
if (logger.isLoggable(Level.INFO)) {
StringBuilder sb = new StringBuilder();
for (Node node: path.nodes()) {
sb.append("(").append(node.getProperty("uuid")).append(")");
if (!node.equals(path.endNode())) {
sb.append("->");
}
Map<String, Object> singleResult = Iterators.singleOrNull(result);
if (singleResult == null) {
assertEquals(expectedPathLength, 0);
return false;
} else {
Path path = (Path) singleResult.get("path");
if (logger.isLoggable(Level.INFO)) {
StringBuilder sb = new StringBuilder();
for (Node node: path.nodes()) {
sb.append("(").append(node.getProperty("uuid")).append(")");
if (!node.equals(path.endNode())) {
sb.append("->");
}

}
logger.info("path is %s".formatted(sb.toString()));
}
logger.info("path is %s".formatted(sb.toString()));
assertEquals(expectedPathLength, path.length(), "failed path length assertion for %s".formatted(query));
assertion.accept(path);
}
assertEquals(expectedPathLength, path.length(), "failed path length assertion for %s".formatted(query));
assertion.accept(path);
return true;
});
}
Expand Down Expand Up @@ -200,7 +206,7 @@ public void testTokenChain(String text, int expected, GraphDatabaseService db) {
public static Stream<Arguments> testChainUpdate() {

return Stream.of(
Arguments.of("removal of unbounded chain", 0, null, null, Collections.emptyList(), 0, 0, 0, null),
Arguments.of("removal of unbounded chain", 0, "", "", Collections.emptyList(), 0, 0, 0, null),
Arguments.of("removal of unbounded chain", 1, null, null, Collections.emptyList(), 0, 0, 0, null),
Arguments.of("removal of unbounded chain", 10, null, null, Collections.emptyList(), 0, 0, 0, null),
Arguments.of("removal of bounded chain", 10, "0", "9", Collections.emptyList(), 0, 2, 2, null),
Expand All @@ -223,8 +229,8 @@ public static Stream<Arguments> testChainUpdate() {
@ParameterizedTest(name = "{index}: {0} with fixture length {1}, boundaries ({2}, {3}")
@MethodSource
public void testChainUpdate(String name, int fixtureLength, String uuidBefore, String uuidAfter, List<Map<String,Object>> characterList,
int expectedLength, int expectedQueryLength, int expectedNumberOfTokens, Class<Exception> exceptedException,
GraphDatabaseService db) {
int expectedLength, int expectedQueryLength, int expectedNumberOfTokens, Class<Exception> exceptedException,
GraphDatabaseService db) {
String uuidText = "text";
Map<String, Object> params = Map.of(
"uuidText", uuidText,
Expand All @@ -250,14 +256,6 @@ public void testChainUpdate(String name, int fixtureLength, String uuidBefore, S

try {
// cut
db.executeTransactionally("""
CALL atag.chains.update("text", $uuidBefore, $uuidAfter, $characterList, $config) YIELD path
RETURN path
""", params);
if (exceptedException !=null) {
fail("expected a exception but did not get one.");
}

validatePathLength(db, """
CALL atag.chains.update("text", $uuidBefore, $uuidAfter, $characterList, $config) YIELD path
RETURN path
Expand All @@ -282,4 +280,5 @@ WHERE NOT (x)-[:NEXT_TOKEN]->()
}
}
}

}

0 comments on commit bb79bb2

Please sign in to comment.