This is an automated email from the ASF dual-hosted git repository.
DomGarguilo pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new 9d6d54da19 Add unit test case for
GarbageCollectionAlgorithm.makeRelative() (#6643)
9d6d54da19 is described below
commit 9d6d54da19f9ea2119649c7d0bb3c9ac0600bf45
Author: Dom G. <[email protected]>
AuthorDate: Thu Nov 12 10:14:54 2026 -0500
Add unit test case for GarbageCollectionAlgorithm.makeRelative() (#6643)
Co-Authored-By: Claude Opus 5.5
---
.../accumulo/gc/GarbageCollectionAlgorithm.java | 3 +-
.../apache/accumulo/gc/GarbageCollectionTest.java | 58 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
index a484b4aafd..62284ba342 100644
---
a/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
+++
b/server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java
@@ -71,7 +71,8 @@ public class GarbageCollectionAlgorithm {
* @return the normalized table-relative path: {@code
tableId/tabletDir/fileName} for a file or
* {@code tableId/tabletDir} for a directory
*/
- private String makeRelative(String path, int expectedLen) {
+ @VisibleForTesting
+ String makeRelative(String path, int expectedLen) {
// remove prefixed old relative path
int position = path.startsWith("../") ? 3 : 0;
int componentCount = 0;
diff --git
a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
index 3548437af1..262bcd9d09 100644
--- a/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
+++ b/server/gc/src/test/java/org/apache/accumulo/gc/GarbageCollectionTest.java
@@ -1205,4 +1205,62 @@ public class GarbageCollectionTest {
assertTrue(msg.startsWith("Saw table IDs in ZK that were not in metadata
table: [3]"));
}
+
+ /**
+ * Tests makeRelative with expectedLen 0 (any), 2 (dir) and 3 (file).
+ */
+ @Test
+ public void testMakeRelative() {
+ var gca = new GarbageCollectionAlgorithm();
+ String fullFile = "hdfs://foo:6000/accumulo/tables/4/t0/F000.rf";
+ String fullDir = "hdfs://foo:6000/accumulo/tables/4/t0";
+
+ // full paths
+ assertRelative(gca, fullFile, 0, "4/t0/F000.rf");
+ assertRelative(gca, fullFile, 3, "4/t0/F000.rf");
+ assertRelative(gca, "hdfs://foo.com:6000/accumulo/tables/4//t0//F001.rf",
0, "4/t0/F001.rf");
+ assertRelative(gca, fullDir, 0, "4/t0");
+ assertRelative(gca, fullDir, 2, "4/t0");
+ assertRelative(gca, fullDir + "/", 0, "4/t0");
+ assertRelative(gca, fullDir + "//", 2, "4/t0");
+
+ // relative paths
+ assertRelative(gca, "4/t0/F000.rf", 0, "4/t0/F000.rf");
+ assertRelative(gca, "4/t0/F000.rf", 3, "4/t0/F000.rf");
+ assertRelative(gca, "../4/t0/F000.rf", 0, "4/t0/F000.rf");
+ assertRelative(gca, "/4/t0/F000.rf", 0, "4/t0/F000.rf");
+ assertRelative(gca, "4//t0///F000.rf/", 0, "4/t0/F000.rf");
+ assertRelative(gca, "4/t0", 0, "4/t0");
+ assertRelative(gca, "4/t0", 2, "4/t0");
+ assertRelative(gca, "4/b-0", 2, "4/b-0");
+ assertRelative(gca, "4/B-0", 2, "4/B-0");
+ assertRelative(gca, "//4//t0//", 0, "4/t0");
+ assertRelative(gca, "../4/t0", 2, "4/t0");
+
+ // wrong expectedLen
+ assertInvalid(gca, fullFile, 2);
+ assertInvalid(gca, fullDir, 3);
+ assertInvalid(gca, "4/t0/F000.rf", 2);
+ assertInvalid(gca, "4/t0", 3);
+
+ // malformed paths
+ assertInvalid(gca, "", 0);
+ assertInvalid(gca, "/", 0);
+ assertInvalid(gca, "4", 0);
+ assertInvalid(gca, "a/b/c/d", 0);
+ assertInvalid(gca, "../../4/t0/F000.rf", 0);
+ assertInvalid(gca, "hdfs://foo:6000/accumulo/nottables/4/t0/F000.rf", 0);
+ assertInvalid(gca, "hdfs://foo:6000/tables", 0);
+ assertInvalid(gca, "4:x/t0", 0);
+ assertInvalid(gca, "a:/t0/F000.rf", 0);
+ }
+
+ private static void assertRelative(GarbageCollectionAlgorithm gca, String
path, int len,
+ String expected) {
+ assertEquals(expected, gca.makeRelative(path, len), path);
+ }
+
+ private static void assertInvalid(GarbageCollectionAlgorithm gca, String
path, int len) {
+ assertThrows(IllegalArgumentException.class, () -> gca.makeRelative(path,
len), path);
+ }
}