Skip to content

Commit

Permalink
HDDS-10073. Remove unused code from GenericTestUtils and LambdaTestUt…
Browse files Browse the repository at this point in the history
…ils (#7849)
  • Loading branch information
peterxcli authored Feb 10, 2025
1 parent a8d7179 commit 6f82e7b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.apache.logging.log4j.util.StackLocatorUtil.getCallerClass;

/**
* Provides some very generic helpers which might be used across the tests.
Expand Down Expand Up @@ -93,51 +91,6 @@ public static Instant getTestStartTime() {
return Instant.ofEpochMilli(System.currentTimeMillis());
}

/**
* Get the (created) base directory for tests.
*
* @return the absolute directory
*
* @deprecated use {@link org.junit.jupiter.api.io.TempDir} instead.
*/
@Deprecated
public static File getTestDir() {
String prop =
System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_DIR);
if (prop.isEmpty()) {
// corner case: property is there but empty
prop = DEFAULT_TEST_DATA_DIR;
}
File dir = new File(prop).getAbsoluteFile();
assertDirCreation(dir);
return dir;
}

/**
* Get an uncreated directory for tests.
*
* @return the absolute directory for tests. Caller is expected to create it.
*
* @deprecated use {@link org.junit.jupiter.api.io.TempDir} instead.
*/
@Deprecated
public static File getTestDir(String subdir) {
return new File(getTestDir(), subdir).getAbsoluteFile();
}

/**
* Get an uncreated directory for tests with a randomized alphanumeric
* name. This is likely to provide a unique path for tests run in parallel
*
* @return the absolute directory for tests. Caller is expected to create it.
*
* @deprecated use {@link org.junit.jupiter.api.io.TempDir} instead.
*/
@Deprecated
public static File getRandomizedTestDir() {
return new File(getRandomizedTempPath());
}

/**
* Get a temp path. This may or may not be relative; it depends on what the
* {@link #SYSPROP_TEST_DATA_DIR} is set to. If unset, it returns a path
Expand All @@ -163,30 +116,6 @@ public static String getTempPath(String subpath) {
return prop + subpath;
}

/**
* Get a temp path. This may or may not be relative; it depends on what the
* {@link #SYSPROP_TEST_DATA_DIR} is set to. If unset, it returns a path
* under the relative path {@link #DEFAULT_TEST_DATA_PATH}
*
* @return a string to use in paths
*
* @deprecated use {@link org.junit.jupiter.api.io.TempDir} instead.
*/
@SuppressWarnings("java:S2245") // no need for secure random
@Deprecated
public static String getRandomizedTempPath() {
return getTempPath(getCallerClass(GenericTestUtils.class).getSimpleName()
+ "-" + randomAlphanumeric(10));
}

/**
* Assert that a given dir can be created or it already exists.
*/
public static void assertDirCreation(File f) {
Assertions.assertTrue(f.mkdirs() || f.exists(),
"Could not create dir " + f + ", nor does it exist");
}

/**
* Wait for the specified test to return true. The test will be performed
* initially and then every {@code checkEveryMillis} until at least
Expand Down Expand Up @@ -296,21 +225,6 @@ public static <K, V> Map<V, K> getReverseMap(Map<K, List<V>> map) {
.collect(Collectors.toMap(Pair::getKey, Pair::getValue));
}

/***
* Removed all files and dirs in the given dir recursively.
*/
public static boolean deleteDirectory(File dir) {
File[] allContents = dir.listFiles();
if (allContents != null) {
for (File content : allContents) {
if (!deleteDirectory(content)) {
return false;
}
}
}
return dir.delete();
}

/**
* Class to capture logs for doing assertions.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,42 +226,6 @@ private static String robustToString(Object o) {
}
}

/**
* Invoke a callable; wrap all checked exceptions with an
* AssertionError.
* @param closure closure to execute
* @param <T> return type of closure
* @return the value of the closure
* @throws AssertionError if the operation raised an IOE or
* other checked exception.
*/
public static <T> T eval(Callable<T> closure) {
try {
return closure.call();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new AssertionError(e.toString(), e);
}
}

/**
* Invoke a callable; wrap all checked exceptions with an
* AssertionError.
* @param closure closure to execute
* @throws AssertionError if the operation raised an IOE or
* other checked exception.
*/
public static void eval(VoidCallable closure) {
try {
closure.call();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new AssertionError(e.toString(), e);
}
}

/**
* Returns {@code TimeoutException} on a timeout. If
* there was a inner class passed in, includes it as the
Expand Down

0 comments on commit 6f82e7b

Please sign in to comment.