This is an automated email from the ASF dual-hosted git repository.
weichiu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 69d65219ec6 HDDS-12379. Fix spotbugs warnings in TestRadixTree (#8968)
69d65219ec6 is described below
commit 69d65219ec61c1ce9b09efd2e47d45b03959a414
Author: Neo Chien <[email protected]>
AuthorDate: Fri Sep 5 13:26:36 2025 +0800
HDDS-12379. Fix spotbugs warnings in TestRadixTree (#8968)
---
.../common/dev-support/findbugsExcludeFile.xml | 4 -
.../apache/hadoop/ozone/util/TestRadixTree.java | 97 +++++++++++++---------
2 files changed, 60 insertions(+), 41 deletions(-)
diff --git a/hadoop-ozone/common/dev-support/findbugsExcludeFile.xml
b/hadoop-ozone/common/dev-support/findbugsExcludeFile.xml
index 5c54f72ffab..0e32b4109fd 100644
--- a/hadoop-ozone/common/dev-support/findbugsExcludeFile.xml
+++ b/hadoop-ozone/common/dev-support/findbugsExcludeFile.xml
@@ -25,10 +25,6 @@
<Class name="org.apache.hadoop.ozone.security.TestGDPRSymmetricKey"/>
<Bug pattern="DLS_DEAD_LOCAL_STORE" />
</Match>
- <Match>
- <Class name="org.apache.hadoop.ozone.util.TestRadixTree"/>
- <Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME" />
- </Match>
<Match>
<Class name="org.apache.hadoop.ozone.om.lock.TestOzoneManagerLock"/>
<Bug pattern="IMSE_DONT_CATCH_IMSE" />
diff --git
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/util/TestRadixTree.java
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/util/TestRadixTree.java
index 9a3071d754b..316ae6db80e 100644
---
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/util/TestRadixTree.java
+++
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/util/TestRadixTree.java
@@ -21,6 +21,8 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -31,14 +33,19 @@
public class TestRadixTree {
static final RadixTree<Integer> ROOT = new RadixTree<>();
+ static final String BASE_PATH = "a";
+ static final Path PATH_B = Paths.get(BASE_PATH, "b");
+ static final Path PATH_BC = Paths.get(BASE_PATH, "b", "c");
+ static final Path PATH_BCD = Paths.get(BASE_PATH, "b", "c", "d");
+ static final Path PATH_BCDGH = Paths.get(BASE_PATH, "b", "c", "d", "g", "h");
@BeforeAll
public static void setupRadixTree() {
// Test prefix paths with an empty tree
assertTrue(ROOT.isEmpty());
- assertEquals("/", ROOT.getLongestPrefix("/a/b/c"));
+ assertEquals("/", ROOT.getLongestPrefix(Paths.get(BASE_PATH, "b",
"c").toString()));
assertEquals("/", RadixTree.radixPathToString(
- ROOT.getLongestPrefixPath("/a/g")));
+ ROOT.getLongestPrefixPath(Paths.get(BASE_PATH, "g").toString())));
// Build Radix tree below for testing.
// a
// |
@@ -51,12 +58,12 @@ public static void setupRadixTree() {
// g
// |
// h
- ROOT.insert("/a/b/c/d");
- ROOT.insert("/a/b/c/d/g/h");
- ROOT.insert("/a/b/c/f");
- ROOT.insert("/a/b/e/g");
- ROOT.insert("/a/b/e/dir1");
- ROOT.insert("/a/b/e/dir2", 1000);
+ ROOT.insert(Paths.get(BASE_PATH, "b", "c", "d").toString());
+ ROOT.insert(Paths.get(BASE_PATH, "b", "c", "d", "g", "h").toString());
+ ROOT.insert(Paths.get(BASE_PATH, "b", "c", "f").toString());
+ ROOT.insert(Paths.get(BASE_PATH, "b", "e", "g").toString());
+ ROOT.insert(Paths.get(BASE_PATH, "b", "e", "dir1").toString());
+ ROOT.insert(Paths.get(BASE_PATH, "b", "e", "dir2").toString(), 1000);
}
/**
@@ -64,62 +71,78 @@ public static void setupRadixTree() {
*/
@Test
public void testGetLongestPrefix() {
- assertEquals("/a/b/c", ROOT.getLongestPrefix("/a/b/c"));
- assertEquals("/a/b", ROOT.getLongestPrefix("/a/b"));
- assertEquals("/a", ROOT.getLongestPrefix("/a"));
- assertEquals("/a/b/e/g", ROOT.getLongestPrefix("/a/b/e/g/h"));
-
- assertEquals("/", ROOT.getLongestPrefix("/d/b/c"));
- assertEquals("/a/b/e", ROOT.getLongestPrefix("/a/b/e/dir3"));
- assertEquals("/a/b/c/d", ROOT.getLongestPrefix("/a/b/c/d/p"));
-
- assertEquals("/a/b/c/f", ROOT.getLongestPrefix("/a/b/c/f/p"));
+ assertEquals("/" + PATH_BC.toString(),
ROOT.getLongestPrefix(PATH_BC.toString()));
+ assertEquals("/" + PATH_B.toString(),
ROOT.getLongestPrefix(PATH_B.toString()));
+ assertEquals("/" + BASE_PATH, ROOT.getLongestPrefix(BASE_PATH));
+ assertEquals("/" + Paths.get(BASE_PATH, "b", "e", "g").toString(),
+ ROOT.getLongestPrefix(
+ Paths.get(BASE_PATH, "b", "e", "g", "h").toString()
+ )
+ );
+
+ assertEquals("/", ROOT.getLongestPrefix("d/b/c"));
+ assertEquals("/" + Paths.get(BASE_PATH, "b", "e").toString(),
+ ROOT.getLongestPrefix(
+ Paths.get(BASE_PATH, "b", "e", "dir3").toString()
+ )
+ );
+ assertEquals("/" + PATH_BCD.toString(),
+ ROOT.getLongestPrefix(
+ Paths.get(BASE_PATH, "b", "c", "d", "p").toString()
+ )
+ );
+
+ assertEquals("/" + Paths.get(BASE_PATH, "b", "c", "f").toString(),
+ ROOT.getLongestPrefix(
+ Paths.get(BASE_PATH, "b", "c", "f", "p").toString()
+ )
+ );
}
@Test
public void testGetLongestPrefixPath() {
- List<RadixNode<Integer>> lpp =
- ROOT.getLongestPrefixPath("/a/b/c/d/g/p");
+ List<RadixNode<Integer>> lpp = ROOT.getLongestPrefixPath(
+ "/" + Paths.get(BASE_PATH, "b", "c", "d", "g", "p").toString()
+ );
RadixNode<Integer> lpn = lpp.get(lpp.size() - 1);
assertEquals("g", lpn.getName());
lpn.setValue(100);
- List<RadixNode<Integer>> lpq =
- ROOT.getLongestPrefixPath("/a/b/c/d/g/q");
+ List<RadixNode<Integer>> lpq = ROOT.getLongestPrefixPath(
+ "/" + Paths.get(BASE_PATH, "b", "c", "d", "g", "q").toString()
+ );
RadixNode<Integer> lqn = lpp.get(lpq.size() - 1);
System.out.print(RadixTree.radixPathToString(lpq));
assertEquals(lpn, lqn);
assertEquals("g", lqn.getName());
assertEquals(100, (int)lqn.getValue());
- assertEquals("/a/", RadixTree.radixPathToString(
- ROOT.getLongestPrefixPath("/a/g")));
-
+ assertEquals("/" + BASE_PATH + "/", RadixTree.radixPathToString(
+ ROOT.getLongestPrefixPath(Paths.get(BASE_PATH, "g").toString())));
}
@Test
public void testGetLastNoeInPrefixPath() {
- assertNull(ROOT.getLastNodeInPrefixPath("/a/g"));
- RadixNode<Integer> ln = ROOT.getLastNodeInPrefixPath("/a/b/e/dir1");
+ assertNull(ROOT.getLastNodeInPrefixPath("/" + Paths.get(BASE_PATH,
"g").toString()));
+ RadixNode<Integer> ln = ROOT.getLastNodeInPrefixPath("/" +
Paths.get(BASE_PATH, "b", "e", "dir1").toString());
assertEquals("dir1", ln.getName());
}
@Test
public void testRemovePrefixPath() {
-
// Remove, test and restore
// Remove partially overlapped path
- ROOT.removePrefixPath("/a/b/c/d/g/h");
- assertEquals("/a/b/c", ROOT.getLongestPrefix("a/b/c/d"));
- ROOT.insert("/a/b/c/d/g/h");
+ ROOT.removePrefixPath(PATH_BCDGH.toString());
+ assertEquals("/" + PATH_BC.toString(),
ROOT.getLongestPrefix(PATH_BCD.toString()));
+ ROOT.insert(PATH_BCDGH.toString());
// Remove fully overlapped path
- ROOT.removePrefixPath("/a/b/c/d");
- assertEquals("/a/b/c/d", ROOT.getLongestPrefix("a/b/c/d"));
- ROOT.insert("/a/b/c/d");
+ ROOT.removePrefixPath(PATH_BCD.toString());
+ assertEquals("/" + PATH_BCD.toString(),
ROOT.getLongestPrefix(PATH_BCD.toString()));
+ ROOT.insert(PATH_BCD.toString());
- // Remove non existing path
- ROOT.removePrefixPath("/d/a");
- assertEquals("/a/b/c/d", ROOT.getLongestPrefix("a/b/c/d"));
+ // Remove non-existing path
+ ROOT.removePrefixPath("d/a");
+ assertEquals("/" + PATH_BCD.toString(),
ROOT.getLongestPrefix(PATH_BCD.toString()));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]