Skip to content

Commit 57a9c5f

Browse files
Remove graph from catalog on invalid proc input
Co-Authored-By: Paul Horn <[email protected]>
1 parent bd2cf24 commit 57a9c5f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

alpha/alpha-proc/src/main/java/org/neo4j/graphalgo/similarity/SimilarityProc.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public ALGO buildAlphaAlgo(
104104
AllocationTracker tracker,
105105
Log log
106106
) {
107-
GraphStoreCatalog.remove(getUsername(), SIMILARITY_FAKE_GRAPH_NAME, (gsc) -> {});
107+
removeGraph();
108108
return newAlgo(config);
109109
}
110110
};
111111
}
112112

113+
114+
113115
// Alpha similarities don't play well with the API, so we must hook in here and hack graph creation
114116
@Override
115117
protected Pair<CONFIG, Optional<String>> processInput(Object graphNameOrConfig, Map<String, Object> configuration) {
@@ -144,7 +146,16 @@ protected Pair<CONFIG, Optional<String>> processInput(Object graphNameOrConfig,
144146
);
145147
}
146148
// And finally we call super in named graph mode
147-
return super.processInput(graphNameOrConfig, configuration);
149+
try {
150+
return super.processInput(graphNameOrConfig, configuration);
151+
} catch (RuntimeException e) {
152+
removeGraph();
153+
throw e;
154+
}
155+
}
156+
157+
private void removeGraph() {
158+
GraphStoreCatalog.remove(getUsername(), SIMILARITY_FAKE_GRAPH_NAME, (gsc) -> {});
148159
}
149160

150161
private Stream<SimilaritySummaryResult> emptyStream(String writeRelationshipType, String writeProperty) {

alpha/alpha-proc/src/test/java/org/neo4j/graphalgo/similarity/SimilarityProcTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.stream.Stream;
5454

5555
import static org.junit.jupiter.api.Assertions.assertEquals;
56+
import static org.junit.jupiter.api.Assertions.assertThrows;
5657
import static org.junit.jupiter.api.Assertions.assertTrue;
5758
import static org.junit.jupiter.api.Assertions.fail;
5859
import static org.neo4j.graphalgo.ElementProjection.PROJECT_ALL;
@@ -269,4 +270,19 @@ void leavesNoTraceInGraphCatalog() {
269270
});
270271
});
271272
}
273+
274+
@Test
275+
void leavesNoTraceInGraphCatalogOnError() {
276+
applyOnProcedure((proc) -> {
277+
getProcMethods(proc).forEach(method -> {
278+
Map<String, Object> config = minimalViableConfig();
279+
config.put("foo", 5);
280+
Throwable ignored = assertThrows(
281+
InvocationTargetException.class,
282+
() -> method.invoke(proc, config, Collections.emptyMap())
283+
);
284+
assertEquals(0, GraphStoreCatalog.getGraphStores(getUsername()).size());
285+
});
286+
});
287+
}
272288
}

0 commit comments

Comments
 (0)