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 @@ -50,19 +50,20 @@ @Test public void backwardFromLeaf() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "backward", "*"); + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); ArrayList expectedLeaves1 = new ArrayList<>(); expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); - ArrayList actualLeaves1 = (ArrayList) endpoint.leaves(new Endpoint.Input(src1)).result; + ArrayList actualLeaves1 = (ArrayList) endpoint1.leaves(new Endpoint.Input(src1)).result; GraphTest.assertEqualsAnyOrder(expectedLeaves1, actualLeaves1); + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); 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")); - ArrayList actualLeaves2 = (ArrayList) endpoint.leaves(new Endpoint.Input(src2)).result; + ArrayList actualLeaves2 = (ArrayList) endpoint2.leaves(new Endpoint.Input(src2)).result; GraphTest.assertEqualsAnyOrder(expectedLeaves2, actualLeaves2); } 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 @@ -29,9 +29,10 @@ public void forwardFromRoot() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -134,9 +135,10 @@ public void forwardFromMiddle() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -179,9 +181,10 @@ public void forwardFromLeaf() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -197,9 +200,10 @@ public void backwardFromRoot() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); - Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -215,9 +219,10 @@ public void backwardFromMiddle() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); - Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -236,9 +241,10 @@ public void backwardFromLeaf() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); - Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -289,9 +295,10 @@ public void forwardSnpToRev() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:rev"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:rev"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -308,9 +315,10 @@ public void forwardRelToRevRevToRev() { 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(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rel:rev,rev:rev"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -328,9 +336,10 @@ public void forwardRevToAllDirToAll() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); - Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -416,9 +425,10 @@ public void forwardSnpToAllRevToAll() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "snp:*,rev:*"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "snp:*,rev:*"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -448,9 +458,10 @@ public void forwardNoEdges() { Graph graph = getGraph(); SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); - Endpoint endpoint = new Endpoint(graph, "forward", ""); - ArrayList paths = (ArrayList) endpoint.visitPaths(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", ""); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", ""); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -466,9 +477,10 @@ public void backwardRevToRevRevToRel() { 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(new Endpoint.Input(swhPID)).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(new Endpoint.Input(swhPID)).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); + ArrayList paths = (ArrayList) endpoint1.visitPaths(new Endpoint.Input(swhPID)).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev,rev:rel"); + ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhPID)).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( 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 @@ -17,7 +17,6 @@ @Test public void forwardRootToLeaf() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; @@ -39,8 +38,10 @@ "swh:1:cnt:0000000000000000000000000000000000000005" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2); Assert.assertTrue(possibleSolutions.contains(dfsPath)); @@ -50,7 +51,6 @@ @Test public void forwardLeafToLeaf() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "forward", "*"); SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); String dstFmt = "cnt"; @@ -59,8 +59,10 @@ "swh:1:cnt:0000000000000000000000000000000000000007" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -69,7 +71,6 @@ @Test public void forwardRevToRev() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; @@ -81,8 +82,10 @@ "swh:1:rev:0000000000000000000000000000000000000003" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:rev"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -91,7 +94,6 @@ @Test public void backwardRevToRev() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev"); SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; @@ -103,8 +105,10 @@ "swh:1:rev:0000000000000000000000000000000000000018" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "rev:rev"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath); @@ -113,7 +117,6 @@ @Test public void backwardCntToFirstSnp() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "backward", "*"); SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); String dstFmt = "snp"; @@ -150,8 +153,10 @@ "swh:1:snp:0000000000000000000000000000000000000020" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4); Assert.assertTrue(possibleSolutions.contains(dfsPath)); @@ -161,7 +166,6 @@ @Test public void forwardRevToFirstCnt() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); String dstFmt = "cnt"; @@ -199,8 +203,10 @@ "swh:1:cnt:0000000000000000000000000000000000000001" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); @@ -211,7 +217,6 @@ @Test public void backwardDirToFirstRel() { Graph graph = getGraph(); - Endpoint endpoint = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); String dstFmt = "rel"; @@ -223,8 +228,10 @@ "swh:1:rel:0000000000000000000000000000000000000019" ); - SwhPath dfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; - SwhPath bfsPath = (SwhPath) endpoint.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; + Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); + SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; + Endpoint endpoint2 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); + SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; Assert.assertEquals(dfsPath, expectedPath); Assert.assertEquals(bfsPath, expectedPath);