diff --git a/java/server/src/main/java/org/softwareheritage/graph/App.java b/java/server/src/main/java/org/softwareheritage/graph/App.java --- a/java/server/src/main/java/org/softwareheritage/graph/App.java +++ b/java/server/src/main/java/org/softwareheritage/graph/App.java @@ -108,7 +108,7 @@ String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); - Endpoint.Output output = endpoint.leaves(src); + Endpoint.Output output = endpoint.leaves(new Endpoint.Input(src)); ctx.json(formatEndpointOutput(output, showTimings)); }); @@ -118,7 +118,7 @@ String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); - Endpoint.Output output = endpoint.neighbors(src); + Endpoint.Output output = endpoint.neighbors(new Endpoint.Input(src)); ctx.json(formatEndpointOutput(output, showTimings)); }); @@ -128,7 +128,7 @@ String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); - Endpoint.Output output = endpoint.visitNodes(src); + Endpoint.Output output = endpoint.visitNodes(new Endpoint.Input(src)); ctx.json(formatEndpointOutput(output, showTimings)); }); @@ -138,7 +138,7 @@ String edgesFmt = ctx.queryParam("edges", "*"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); - Endpoint.Output output = endpoint.visitPaths(src); + Endpoint.Output output = endpoint.visitPaths(new Endpoint.Input(src)); ctx.json(formatEndpointOutput(output, showTimings)); }); @@ -150,7 +150,7 @@ String algorithm = ctx.queryParam("traversal", "dfs"); Endpoint endpoint = new Endpoint(graph, direction, edgesFmt); - Endpoint.Output output = endpoint.walk(src, dstFmt, algorithm); + Endpoint.Output output = endpoint.walk(new Endpoint.Input(src, dstFmt, algorithm)); ctx.json(formatEndpointOutput(output, showTimings)); }); diff --git a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java --- a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java @@ -23,9 +23,34 @@ public class Endpoint { /** + * Wrapper class to unify traversal methods input signatures. + */ + public static class Input { + /** Source node of endpoint call specified as a {@link SwhPID} */ + public SwhPID src; + /** + * Destination formatted string as described in the API + */ + public String dstFmt; + /** Traversal algorithm used in endpoint call (either "dfs" or "bfs") */ + public String algorithm; + + public Input(SwhPID src) { + this.src = src; + } + + public Input(SwhPID src, String dstFmt, String algorithm) { + this.src = src; + this.dstFmt = dstFmt; + this.algorithm = algorithm; + } + } + + /** * Wrapper class to return both the endpoint result and metadata (such as timings). */ - public class Output { + public static class Output { /** The result content itself */ public T result; /** Various metadata about the result */ @@ -129,17 +154,17 @@ /** * Leaves endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhPID} + * @param input input parameters for the underlying endpoint call * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#leaves(long) */ - public Output leaves(SwhPID src) { + public Output leaves(Input input) { Output> output = new Output<>(); long startTime; startTime = Timing.start(); - long srcNodeId = graph.getNodeId(src); + long srcNodeId = graph.getNodeId(input.src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); @@ -157,17 +182,17 @@ /** * Neighbors endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhPID} + * @param input input parameters for the underlying endpoint call * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#neighbors(long) */ - public Output neighbors(SwhPID src) { + public Output neighbors(Input input) { Output> output = new Output<>(); long startTime; startTime = Timing.start(); - long srcNodeId = graph.getNodeId(src); + long srcNodeId = graph.getNodeId(input.src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); @@ -185,39 +210,36 @@ /** * Walk endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhPID} - * @param dstFmt destination formatted string as described in the API - * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") + * @param input input parameters for the underlying endpoint call * @return the resulting {@link SwhPath} from endpoint call and operation metadata * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#walk */ - public Output walk(SwhPID src, String dstFmt, String algorithm) { + public Output walk(Input input) { Output output = new Output<>(); long startTime; startTime = Timing.start(); - long srcNodeId = graph.getNodeId(src); + long srcNodeId = graph.getNodeId(input.src); output.meta.timings.pid2node = Timing.stop(startTime); ArrayList nodeIds = new ArrayList(); // Destination is either a SWH PID or a node type try { - SwhPID dstSwhPID = new SwhPID(dstFmt); + SwhPID dstSwhPID = new SwhPID(input.dstFmt); long dstNodeId = graph.getNodeId(dstSwhPID); startTime = Timing.start(); - nodeIds = traversal.walk(srcNodeId, dstNodeId, algorithm); + nodeIds = traversal.walk(srcNodeId, dstNodeId, input.algorithm); output.meta.timings.traversal = Timing.stop(startTime); } catch (IllegalArgumentException ignored1) { try { - Node.Type dstType = Node.Type.fromStr(dstFmt); + Node.Type dstType = Node.Type.fromStr(input.dstFmt); startTime = Timing.start(); - nodeIds = traversal.walk(srcNodeId, dstType, algorithm); + nodeIds = traversal.walk(srcNodeId, dstType, input.algorithm); output.meta.timings.traversal = Timing.stop(startTime); } catch (IllegalArgumentException ignored2) { } @@ -235,17 +257,17 @@ /** * VisitNodes endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhPID} + * @param input input parameters for the underlying endpoint call * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#visitNodes(long) */ - public Output visitNodes(SwhPID src) { + public Output visitNodes(Input input) { Output> output = new Output<>(); long startTime; startTime = Timing.start(); - long srcNodeId = graph.getNodeId(src); + long srcNodeId = graph.getNodeId(input.src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); @@ -263,18 +285,18 @@ /** * VisitPaths endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhPID} + * @param input input parameters for the underlying endpoint call * @return the resulting list of {@link SwhPath} from endpoint call and operation metadata * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#visitPaths(long) */ - public Output visitPaths(SwhPID src) { + public Output visitPaths(Input input) { Output> output = new Output<>(); long startTime; startTime = Timing.start(); - long srcNodeId = graph.getNodeId(src); + long srcNodeId = graph.getNodeId(input.src); output.meta.timings.pid2node = Timing.stop(startTime); startTime = Timing.start(); diff --git a/java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java b/java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java --- a/java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java +++ b/java/server/src/main/java/org/softwareheritage/graph/benchmark/Common.java @@ -23,16 +23,21 @@ * @param graph compressed graph used in the benchmark * @param nodeIds node ids to use as starting point for the endpoint traversal * @param operation endpoint function to benchmark + * @param dstFmt destination formatted string as described in the API + * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") */ - public static void timeEndpoint( - Graph graph, long[] nodeIds, Function operation) { + public static void timeEndpoint(Graph graph, long[] nodeIds, + Function operation, String dstFmt, String algorithm) { ArrayList timings = new ArrayList<>(); ArrayList timingsNormalized = new ArrayList<>(); for (long nodeId : nodeIds) { SwhPID swhPID = graph.getSwhPID(nodeId); - Endpoint.Output output = operation.apply(swhPID); + Endpoint.Output output = (dstFmt == null) + ? operation.apply(new Endpoint.Input(swhPID)) + : operation.apply(new Endpoint.Input(swhPID, dstFmt, algorithm)); timings.add(output.meta.timings.traversal); if (output.meta.nbEdgesAccessed != 0) { @@ -48,4 +53,12 @@ Statistics statsNormalized = new Statistics(timingsNormalized); statsNormalized.printAll(); } + + /** + * Same as {@link timeEndpoint} but without destination or algorithm specified to endpoint call. + */ + public static void timeEndpoint( + Graph graph, long[] nodeIds, Function operation) { + timeEndpoint(graph, nodeIds, operation, null, null); + } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java @@ -24,7 +24,8 @@ expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); } @Test @@ -42,7 +43,8 @@ expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000011")); - GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); } @Test @@ -53,13 +55,15 @@ SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); ArrayList expectedLeaves1 = new ArrayList<>(); expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - GraphTest.assertEqualsAnyOrder(expectedLeaves1, (ArrayList) endpoint.leaves(src1).result); + ArrayList actualLeaves1 = (ArrayList) endpoint.leaves(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves1, actualLeaves1); SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); ArrayList expectedLeaves2 = new ArrayList<>(); expectedLeaves2.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); expectedLeaves2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - GraphTest.assertEqualsAnyOrder(expectedLeaves2, (ArrayList) endpoint.leaves(src2).result); + ArrayList actualLeaves2 = (ArrayList) endpoint.leaves(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves2, actualLeaves2); } @Test @@ -71,7 +75,8 @@ ArrayList expectedLeaves = new ArrayList<>(); expectedLeaves.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); - GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); } @Test @@ -86,7 +91,8 @@ expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); } @Test @@ -98,6 +104,7 @@ ArrayList expectedLeaves = new ArrayList<>(); expectedLeaves.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000012")); - GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); + ArrayList actualLeaves = (ArrayList) endpoint.leaves(new Endpoint.Input(src)).result; + GraphTest.assertEqualsAnyOrder(expectedLeaves, actualLeaves); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java @@ -19,23 +19,28 @@ SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); - GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint1.neighbors(src1).result); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals1); SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); - GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint2.neighbors(src2).result); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals2); SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); - GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint3.neighbors(src3).result); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals3); SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); - GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint4.neighbors(src4).result); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals4); SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); - GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint5.neighbors(src5).result); + ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes, actuals5); } @Test @@ -46,31 +51,36 @@ Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); ArrayList expectedNodes1 = new ArrayList<>(); expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); - GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); ArrayList expectedNodes2 = new ArrayList<>(); expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); - GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); ArrayList expectedNodes3 = new ArrayList<>(); expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); ArrayList expectedNodes4 = new ArrayList<>(); expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); ArrayList expectedNodes5 = new ArrayList<>(); expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); - GraphTest.assertEqualsAnyOrder(expectedNodes5, (ArrayList) endpoint5.neighbors(src5).result); + ArrayList actuals5 = (ArrayList) endpoint5.neighbors(new Endpoint.Input(src5)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes5, actuals5); } @Test @@ -82,28 +92,32 @@ ArrayList expectedNodes1 = new ArrayList<>(); expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); - GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); ArrayList expectedNodes2 = new ArrayList<>(); expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); ArrayList expectedNodes3 = new ArrayList<>(); expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); - GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); + ArrayList actuals3 = (ArrayList) endpoint3.neighbors(new Endpoint.Input(src3)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes3, actuals3); SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); ArrayList expectedNodes4 = new ArrayList<>(); expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); - GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); + ArrayList actuals4 = (ArrayList) endpoint4.neighbors(new Endpoint.Input(src4)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes4, actuals4); } @Test @@ -116,7 +130,8 @@ expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); - GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); + ArrayList actuals1 = (ArrayList) endpoint1.neighbors(new Endpoint.Input(src1)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes1, actuals1); SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); @@ -124,6 +139,7 @@ expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); - GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); + ArrayList actuals2 = (ArrayList) endpoint2.neighbors(new Endpoint.Input(src2)).result; + GraphTest.assertEqualsAnyOrder(expectedNodes2, actuals2); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -30,8 +30,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -135,8 +135,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -180,8 +180,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -198,8 +198,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -216,8 +216,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -237,8 +237,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -290,8 +290,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -309,8 +309,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); Endpoint endpoint = new Endpoint(graph, "forward", "rel:rev,rev:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -329,8 +329,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -417,8 +417,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -449,8 +449,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", ""); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -467,8 +467,8 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev,rev:rel"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -495,7 +495,7 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedNodes = new ArrayList(); expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); @@ -519,7 +519,7 @@ Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedNodes = new ArrayList(); expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); diff --git a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java @@ -39,8 +39,8 @@ "swh:1:cnt:0000000000000000000000000000000000000005" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2); Assert.assertTrue(possibleSolutions.contains(dfsPath)); @@ -59,8 +59,8 @@ "swh:1:cnt:0000000000000000000000000000000000000007" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -81,8 +81,8 @@ "swh:1:rev:0000000000000000000000000000000000000003" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -103,8 +103,8 @@ "swh:1:rev:0000000000000000000000000000000000000018" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -150,8 +150,8 @@ "swh:1:snp:0000000000000000000000000000000000000020" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); Assert.assertTrue(possibleSolutions.contains(dfsPath)); @@ -199,8 +199,8 @@ "swh:1:cnt:0000000000000000000000000000000000000001" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); @@ -223,8 +223,8 @@ "swh:1:rel:0000000000000000000000000000000000000019" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(src, dstFmt, "dfs").result; - SwhPath bfsPath = (SwhPath) endpoint.walk(src, dstFmt, "bfs").result; + SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath);