Skip to content

Commit

Permalink
Remove graph from catalog on invalid proc input
Browse files Browse the repository at this point in the history
Co-Authored-By: Paul Horn <paul.horn@neotechnology.com>
  • Loading branch information
jjaderberg and knutwalker committed Jul 28, 2020
1 parent bd2cf24 commit 57a9c5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ public ALGO buildAlphaAlgo(
AllocationTracker tracker,
Log log
) {
GraphStoreCatalog.remove(getUsername(), SIMILARITY_FAKE_GRAPH_NAME, (gsc) -> {});
removeGraph();
return newAlgo(config);
}
};
}



// Alpha similarities don't play well with the API, so we must hook in here and hack graph creation
@Override
protected Pair<CONFIG, Optional<String>> processInput(Object graphNameOrConfig, Map<String, Object> configuration) {
Expand Down Expand Up @@ -144,7 +146,16 @@ protected Pair<CONFIG, Optional<String>> processInput(Object graphNameOrConfig,
);
}
// And finally we call super in named graph mode
return super.processInput(graphNameOrConfig, configuration);
try {
return super.processInput(graphNameOrConfig, configuration);
} catch (RuntimeException e) {
removeGraph();
throw e;
}
}

private void removeGraph() {
GraphStoreCatalog.remove(getUsername(), SIMILARITY_FAKE_GRAPH_NAME, (gsc) -> {});
}

private Stream<SimilaritySummaryResult> emptyStream(String writeRelationshipType, String writeProperty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.neo4j.graphalgo.ElementProjection.PROJECT_ALL;
Expand Down Expand Up @@ -269,4 +270,19 @@ void leavesNoTraceInGraphCatalog() {
});
});
}

@Test
void leavesNoTraceInGraphCatalogOnError() {
applyOnProcedure((proc) -> {
getProcMethods(proc).forEach(method -> {
Map<String, Object> config = minimalViableConfig();
config.put("foo", 5);
Throwable ignored = assertThrows(
InvocationTargetException.class,
() -> method.invoke(proc, config, Collections.emptyMap())
);
assertEquals(0, GraphStoreCatalog.getGraphStores(getUsername()).size());
});
});
}
}

0 comments on commit 57a9c5f

Please sign in to comment.