Changeset View
Changeset View
Standalone View
Standalone View
java/src/test/java/org/softwareheritage/graph/rpc/FindPathToTest.java
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | public class FindPathToTest extends TraversalServiceTest { | ||||
} | } | ||||
// Test path between dir 16 and any rel (backward graph) | // Test path between dir 16 and any rel (backward graph) | ||||
@Test | @Test | ||||
public void backwardDirToFirstRel() { | public void backwardDirToFirstRel() { | ||||
ArrayList<SWHID> actual = getSWHIDs(client.findPathTo( | ArrayList<SWHID> actual = getSWHIDs(client.findPathTo( | ||||
getRequestBuilder(fakeSWHID("dir", 16), "rel").setDirection(GraphDirection.BACKWARD).build())); | getRequestBuilder(fakeSWHID("dir", 16), "rel").setDirection(GraphDirection.BACKWARD).build())); | ||||
List<SWHID> expected = List.of(fakeSWHID("dir", 16), fakeSWHID("dir", 17), fakeSWHID("rev", 18), | List<SWHID> expected = List.of(fakeSWHID("dir", 16), fakeSWHID("dir", 17), fakeSWHID("rev", 18), | ||||
fakeSWHID("rel", 19)); | fakeSWHID("rel", 21)); // FIXME: rel:19 is valid too | ||||
Assertions.assertEquals(expected, actual); | Assertions.assertEquals(expected, actual); | ||||
} | } | ||||
// Test path between cnt 4 and itself (forward graph) | // Test path between cnt 4 and itself (forward graph) | ||||
@Test | @Test | ||||
public void forwardCntToItself() { | public void forwardCntToItself() { | ||||
ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 4), "cnt").build())); | ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 4), "cnt").build())); | ||||
List<SWHID> expected = List.of(fakeSWHID("cnt", 4)); | List<SWHID> expected = List.of(fakeSWHID("cnt", 4)); | ||||
Show All 20 Lines | public class FindPathToTest extends TraversalServiceTest { | ||||
// Start from all directories and find any origin (backward graph) | // Start from all directories and find any origin (backward graph) | ||||
@Test | @Test | ||||
public void backwardMultipleSourcesAllDirToOri() { | public void backwardMultipleSourcesAllDirToOri() { | ||||
ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("dir", 2), "ori") | ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("dir", 2), "ori") | ||||
.addSrc(fakeSWHID("dir", 6).toString()).addSrc(fakeSWHID("dir", 8).toString()) | .addSrc(fakeSWHID("dir", 6).toString()).addSrc(fakeSWHID("dir", 8).toString()) | ||||
.addSrc(fakeSWHID("dir", 12).toString()).addSrc(fakeSWHID("dir", 16).toString()) | .addSrc(fakeSWHID("dir", 12).toString()).addSrc(fakeSWHID("dir", 16).toString()) | ||||
.addSrc(fakeSWHID("dir", 17).toString()).setDirection(GraphDirection.BACKWARD).build())); | .addSrc(fakeSWHID("dir", 17).toString()).setDirection(GraphDirection.BACKWARD).build())); | ||||
List<SWHID> expected = List.of(fakeSWHID("dir", 8), fakeSWHID("rev", 9), fakeSWHID("snp", 20), | List<SWHID> expected1 = List.of(fakeSWHID("dir", 8), fakeSWHID("rev", 9), fakeSWHID("snp", 20), | ||||
new SWHID(TEST_ORIGIN_ID)); | new SWHID(TEST_ORIGIN_ID)); | ||||
Assertions.assertEquals(expected, actual); | List<SWHID> expected2 = List.of(fakeSWHID("dir", 8), fakeSWHID("rev", 9), fakeSWHID("snp", 22), | ||||
new SWHID(TEST_ORIGIN_ID2)); | |||||
List<List<SWHID>> expected = List.of(expected1, expected2); | |||||
Assertions.assertTrue(expected.contains(actual), String.format("Expected either %s or %s, got %s", | |||||
expected1.toString(), expected2.toString(), actual.toString())); | |||||
} | } | ||||
// Impossible path between rev 9 and any release (forward graph) | // Impossible path between rev 9 and any release (forward graph) | ||||
@Test | @Test | ||||
public void forwardImpossiblePath() { | public void forwardImpossiblePath() { | ||||
// Check that the return is STATUS.NOT_FOUND | // Check that the return is STATUS.NOT_FOUND | ||||
StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | ||||
client.findPathTo(getRequestBuilder(fakeSWHID("rev", 9), "rel").build()); | client.findPathTo(getRequestBuilder(fakeSWHID("rev", 9), "rel").build()); | ||||
}); | }); | ||||
Assertions.assertEquals(thrown.getStatus(), Status.NOT_FOUND); | Assertions.assertEquals(thrown.getStatus(), Status.NOT_FOUND); | ||||
} | } | ||||
// Path from cnt 15 to any rel with various max depths | // Path from cnt 15 to any rel with various max depths | ||||
@Test | @Test | ||||
public void maxDepth() { | public void maxDepth() { | ||||
// Works with max_depth = 2 | // Works with max_depth = 2 | ||||
ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel") | ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel") | ||||
.setDirection(GraphDirection.BACKWARD).setMaxDepth(4).build())); | .setDirection(GraphDirection.BACKWARD).setMaxDepth(4).build())); | ||||
List<SWHID> expected = List.of(fakeSWHID("cnt", 15), fakeSWHID("dir", 16), fakeSWHID("dir", 17), | List<SWHID> expected = List.of(fakeSWHID("cnt", 15), fakeSWHID("dir", 16), fakeSWHID("dir", 17), | ||||
fakeSWHID("rev", 18), fakeSWHID("rel", 19)); | fakeSWHID("rev", 18), fakeSWHID("rel", 21)); // FIXME: rel:19 is valid too | ||||
Assertions.assertEquals(expected, actual); | Assertions.assertEquals(expected, actual); | ||||
// Check that it throws NOT_FOUND with max depth = 1 | // Check that it throws NOT_FOUND with max depth = 1 | ||||
StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | ||||
client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel").setDirection(GraphDirection.BACKWARD) | client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel").setDirection(GraphDirection.BACKWARD) | ||||
.setMaxDepth(3).build()); | .setMaxDepth(3).build()); | ||||
}); | }); | ||||
Assertions.assertEquals(thrown.getStatus().getCode(), Status.NOT_FOUND.getCode()); | Assertions.assertEquals(thrown.getStatus().getCode(), Status.NOT_FOUND.getCode()); | ||||
} | } | ||||
// Path from cnt 15 to any rel with various max edges | // Path from cnt 15 to any rel with various max edges | ||||
@Test | @Test | ||||
public void maxEdges() { | public void maxEdges() { | ||||
int backtracked_edges = 2; // FIXME: Number of edges traversed but backtracked from. it changes | |||||
// nondeterministically every time the test dataset is changed. | |||||
ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel") | ArrayList<SWHID> actual = getSWHIDs(client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel") | ||||
.setDirection(GraphDirection.BACKWARD).setMaxEdges(4).build())); | .setDirection(GraphDirection.BACKWARD).setMaxEdges(4 + backtracked_edges).build())); | ||||
List<SWHID> expected = List.of(fakeSWHID("cnt", 15), fakeSWHID("dir", 16), fakeSWHID("dir", 17), | List<SWHID> expected = List.of(fakeSWHID("cnt", 15), fakeSWHID("dir", 16), fakeSWHID("dir", 17), | ||||
fakeSWHID("rev", 18), fakeSWHID("rel", 19)); | fakeSWHID("rev", 18), fakeSWHID("rel", 21)); // FIXME: rel:19 is valid too | ||||
Assertions.assertEquals(expected, actual); | Assertions.assertEquals(expected, actual); | ||||
StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | StatusRuntimeException thrown = Assertions.assertThrows(StatusRuntimeException.class, () -> { | ||||
client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel").setDirection(GraphDirection.BACKWARD) | client.findPathTo(getRequestBuilder(fakeSWHID("cnt", 15), "rel").setDirection(GraphDirection.BACKWARD) | ||||
.setMaxEdges(3).build()); | .setMaxEdges(3 + backtracked_edges).build()); | ||||
}); | }); | ||||
Assertions.assertEquals(thrown.getStatus().getCode(), Status.NOT_FOUND.getCode()); | Assertions.assertEquals(thrown.getStatus().getCode(), Status.NOT_FOUND.getCode()); | ||||
} | } | ||||
} | } |