-
Notifications
You must be signed in to change notification settings - Fork 624
HDDS-10284. Move GenericTestUtils#getTempPath to MiniOzoneCluster #8300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
046d6a8
05cf7c0
944571b
e8e4a1e
0740425
a3bdd8c
a630951
d2ab079
859b67d
269928e
cf949bf
9944fb1
1336686
8488bfd
b06a0ef
7e358d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,9 +56,8 @@ | |
| * Provides some very generic helpers which might be used across the tests. | ||
| */ | ||
| public abstract class GenericTestUtils { | ||
| public static final String SYSPROP_TEST_DATA_DIR = "test.build.data"; | ||
| public static final String DEFAULT_TEST_DATA_DIR; | ||
| public static final String DEFAULT_TEST_DATA_PATH = "target/test/data/"; | ||
|
|
||
| /** | ||
| * Error string used in | ||
| * {@link GenericTestUtils#waitFor(BooleanSupplier, int, int)}. | ||
|
|
@@ -90,31 +89,6 @@ public static Instant getTestStartTime() { | |
| return Instant.ofEpochMilli(System.currentTimeMillis()); | ||
| } | ||
|
|
||
| /** | ||
| * 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} | ||
| * | ||
| * @param subpath sub path, with no leading "/" character | ||
| * @return a string to use in paths | ||
| * | ||
| * @deprecated use {@link org.junit.jupiter.api.io.TempDir} instead. | ||
| */ | ||
| @Deprecated | ||
| public static String getTempPath(String subpath) { | ||
| String prop = WINDOWS ? DEFAULT_TEST_DATA_PATH | ||
| : System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_PATH); | ||
|
|
||
| if (prop.isEmpty()) { | ||
| // corner case: property is there but empty | ||
| prop = DEFAULT_TEST_DATA_PATH; | ||
| } | ||
| if (!prop.endsWith("/")) { | ||
| prop = prop + "/"; | ||
| } | ||
| return prop + subpath; | ||
| } | ||
|
|
||
| /** | ||
| * Wait for the specified test to return true. The test will be performed | ||
| * initially and then every {@code checkEveryMillis} until at least | ||
|
|
@@ -133,7 +107,7 @@ public static String getTempPath(String subpath) { | |
| * @throws InterruptedException if the method is interrupted while waiting | ||
| */ | ||
| public static void waitFor(BooleanSupplier check, int checkEveryMillis, | ||
| int waitForMillis) throws TimeoutException, InterruptedException { | ||
| int waitForMillis) throws TimeoutException, InterruptedException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do not format changes that are not related to the jira ticket
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to being unrelated, this specific formatting should be avoided. Whenever visibility / return type / method name / other modifiers are changed, we would have to reindent all parameters.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the review. Yes, I'll revert the format changes and take into account that they should be avoided. |
||
| Preconditions.checkNotNull(check, ERROR_MISSING_ARGUMENT); | ||
| Preconditions.checkArgument(waitForMillis >= checkEveryMillis, | ||
| ERROR_INVALID_ARGUMENT); | ||
|
|
@@ -176,7 +150,7 @@ public static void setLogLevel(Logger logger, Level level) { | |
| } | ||
|
|
||
| public static void setLogLevel(org.slf4j.Logger logger, | ||
| org.slf4j.event.Level level) { | ||
| org.slf4j.event.Level level) { | ||
| setLogLevel(toLog4j(logger), Level.toLevel(level.toString())); | ||
| } | ||
|
|
||
|
|
@@ -197,7 +171,7 @@ public static void withLogDisabled(Class<?> clazz, Runnable task) { | |
| } | ||
|
|
||
| public static <T> T mockFieldReflection(Object object, String fieldName) | ||
| throws NoSuchFieldException, IllegalAccessException { | ||
| throws NoSuchFieldException, IllegalAccessException { | ||
| Field field = object.getClass().getDeclaredField(fieldName); | ||
| boolean isAccessible = field.isAccessible(); | ||
|
|
||
|
|
@@ -217,7 +191,7 @@ public static <T> T mockFieldReflection(Object object, String fieldName) | |
| } | ||
|
|
||
| public static <T> T getFieldReflection(Object object, String fieldName) | ||
| throws NoSuchFieldException, IllegalAccessException { | ||
| throws NoSuchFieldException, IllegalAccessException { | ||
| Field field = object.getClass().getDeclaredField(fieldName); | ||
| boolean isAccessible = field.isAccessible(); | ||
|
|
||
|
|
@@ -237,7 +211,7 @@ public static <T> T getFieldReflection(Object object, String fieldName) | |
| public static <K, V> Map<V, K> getReverseMap(Map<K, List<V>> map) { | ||
| return map.entrySet().stream().flatMap(entry -> entry.getValue().stream() | ||
| .map(v -> Pair.of(v, entry.getKey()))) | ||
| .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); | ||
| .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -281,6 +255,7 @@ public void clearOutput() { | |
| writer().getBuffer().setLength(0); | ||
| } | ||
| } | ||
|
|
||
| @Deprecated | ||
| public static Logger toLog4j(org.slf4j.Logger logger) { | ||
| return LogManager.getLogger(logger.getName()); | ||
|
|
@@ -298,7 +273,9 @@ public static PrintStreamCapturer captureErr() { | |
| return new SystemErrCapturer(); | ||
| } | ||
|
|
||
| /** Capture contents of a {@code PrintStream}, until {@code close()}d. */ | ||
| /** | ||
| * Capture contents of a {@code PrintStream}, until {@code close()}d. | ||
| */ | ||
| public abstract static class PrintStreamCapturer implements AutoCloseable, Supplier<String> { | ||
| private final ByteArrayOutputStream bytes; | ||
| private final PrintStream bytesPrintStream; | ||
|
|
@@ -377,6 +354,7 @@ public SystemOutCapturer() { | |
|
|
||
| /** | ||
| * Replaces {@link System#in} with a stream that provides {@code lines} as input. | ||
| * | ||
| * @return an {@code AutoCloseable} to restore the original {@link System#in} stream | ||
| */ | ||
| public static AutoCloseable supplyOnSystemIn(String... lines) { | ||
|
|
@@ -456,9 +434,10 @@ public static final class ReflectionUtils { | |
| /** | ||
| * This method provides the modifiers field using reflection approach which is compatible | ||
| * for both pre Java 9 and post java 9 versions. | ||
| * | ||
| * @return modifiers field | ||
| * @throws IllegalAccessException illegalAccessException, | ||
| * @throws NoSuchFieldException noSuchFieldException. | ||
| * @throws NoSuchFieldException noSuchFieldException. | ||
| */ | ||
| public static Field getModifiersField() throws IllegalAccessException, NoSuchFieldException { | ||
| Field modifiersField = null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,20 +35,22 @@ | |
| import org.apache.hadoop.ozone.om.OzoneManager; | ||
| import org.apache.hadoop.ozone.recon.ReconServer; | ||
| import org.apache.hadoop.security.authentication.client.AuthenticationException; | ||
| import org.apache.ozone.test.GenericTestUtils; | ||
| import org.apache.ratis.util.ExitUtils; | ||
| import org.apache.ratis.util.function.CheckedFunction; | ||
|
|
||
| /** | ||
| * Interface used for MiniOzoneClusters. | ||
| */ | ||
| public interface MiniOzoneCluster extends AutoCloseable { | ||
| String SYSPROP_TEST_DATA_DIR = "test.build.data"; | ||
| String DEFAULT_TEST_DATA_PATH = "target/test/data/"; | ||
|
|
||
| boolean WINDOWS = System.getProperty("os.name").startsWith("Windows"); | ||
|
|
||
| /** | ||
| * Returns the Builder to construct MiniOzoneCluster. | ||
| * | ||
| * @param conf OzoneConfiguration | ||
| * | ||
| * @return MiniOzoneCluster builder | ||
| */ | ||
| static Builder newBuilder(OzoneConfiguration conf) { | ||
|
|
@@ -59,7 +61,6 @@ static Builder newBuilder(OzoneConfiguration conf) { | |
| * Returns the Builder to construct MiniOzoneHACluster. | ||
| * | ||
| * @param conf OzoneConfiguration | ||
| * | ||
| * @return MiniOzoneCluster builder | ||
| */ | ||
| static MiniOzoneHAClusterImpl.Builder newHABuilder(OzoneConfiguration conf) { | ||
|
|
@@ -78,7 +79,7 @@ static MiniOzoneHAClusterImpl.Builder newHABuilder(OzoneConfiguration conf) { | |
| * configured {@link HddsDatanodeService} registers with | ||
| * {@link StorageContainerManager}. | ||
| * | ||
| * @throws TimeoutException In case of timeout | ||
| * @throws TimeoutException In case of timeout | ||
| * @throws InterruptedException In case of interrupt while waiting | ||
| */ | ||
| void waitForClusterToBeReady() throws TimeoutException, InterruptedException; | ||
|
|
@@ -87,14 +88,14 @@ static MiniOzoneHAClusterImpl.Builder newHABuilder(OzoneConfiguration conf) { | |
| * Waits for at least one RATIS pipeline of given factor to be reported in open | ||
| * state. | ||
| * | ||
| * @param factor replication factor | ||
| * @param factor replication factor | ||
| * @param timeoutInMs timeout value in milliseconds | ||
| * @throws TimeoutException In case of timeout | ||
| * @throws TimeoutException In case of timeout | ||
| * @throws InterruptedException In case of interrupt while waiting | ||
| */ | ||
| void waitForPipelineTobeReady(HddsProtos.ReplicationFactor factor, | ||
| int timeoutInMs) | ||
| throws TimeoutException, InterruptedException; | ||
| throws TimeoutException, InterruptedException; | ||
|
|
||
| /** | ||
| * Sets the timeout value after which | ||
|
|
@@ -107,7 +108,7 @@ void waitForPipelineTobeReady(HddsProtos.ReplicationFactor factor, | |
| /** | ||
| * Waits/blocks till the cluster is out of safe mode. | ||
| * | ||
| * @throws TimeoutException TimeoutException In case of timeout | ||
| * @throws TimeoutException TimeoutException In case of timeout | ||
| * @throws InterruptedException In case of interrupt while waiting | ||
| */ | ||
| void waitTobeOutOfSafeMode() throws TimeoutException, InterruptedException; | ||
|
|
@@ -194,6 +195,7 @@ void restartHddsDatanode(int i, boolean waitForDatanode) | |
| */ | ||
| void restartHddsDatanode(DatanodeDetails dn, boolean waitForDatanode) | ||
| throws InterruptedException, TimeoutException, IOException; | ||
|
|
||
| /** | ||
| * Shutdown a particular HddsDatanode. | ||
| * | ||
|
|
@@ -250,7 +252,29 @@ default String getName() { | |
| } | ||
|
|
||
| default String getBaseDir() { | ||
| return GenericTestUtils.getTempPath(getName()); | ||
| return getTempPath(getName()); | ||
| } | ||
|
|
||
| /** | ||
| * 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} | ||
| * | ||
| * @param subpath sub path, with no leading "/" character | ||
| * @return a string to use in paths | ||
| */ | ||
| static String getTempPath(String subpath) { | ||
| String prop = WINDOWS ? DEFAULT_TEST_DATA_PATH | ||
| : System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_PATH); | ||
|
|
||
| if (prop.isEmpty()) { | ||
| // corner case: property is there but empty | ||
| prop = DEFAULT_TEST_DATA_PATH; | ||
| } | ||
| if (!prop.endsWith("/")) { | ||
| prop = prop + "/"; | ||
| } | ||
| return prop + subpath; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest moving the method as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the suggestion |
||
|
|
||
| /** | ||
|
|
@@ -275,7 +299,7 @@ abstract class Builder { | |
| protected boolean includeRecon = false; | ||
|
|
||
| protected int numOfDatanodes = 3; | ||
| protected boolean startDataNodes = true; | ||
| protected boolean startDataNodes = true; | ||
| protected CertificateClient certClient; | ||
| protected SecretKeyClient secretKeyClient; | ||
| protected DatanodeFactory dnFactory = UniformDatanodesFactory.newBuilder().build(); | ||
|
|
@@ -289,8 +313,10 @@ protected Builder(OzoneConfiguration conf) { | |
| ExitUtils.disableSystemExit(); | ||
| } | ||
|
|
||
| /** Prepare the builder for another call to {@link #build()}, avoiding conflict | ||
| * between the clusters created. */ | ||
| /** | ||
| * Prepare the builder for another call to {@link #build()}, avoiding conflict | ||
| * between the clusters created. | ||
| */ | ||
| protected void prepareForNextBuild() { | ||
| conf = new OzoneConfiguration(conf); | ||
| setClusterId(); | ||
|
|
@@ -303,8 +329,7 @@ public Builder setSCMConfigurator(SCMConfigurator configurator) { | |
|
|
||
| private void setClusterId() { | ||
| clusterId = UUID.randomUUID().toString(); | ||
| path = GenericTestUtils.getTempPath( | ||
| MiniOzoneClusterImpl.class.getSimpleName() + "-" + clusterId); | ||
| path = getTempPath(MiniOzoneClusterImpl.class.getSimpleName() + "-" + clusterId); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -338,7 +363,6 @@ public Builder setSecretKeyClient(SecretKeyClient client) { | |
| * MiniOzoneCluster. | ||
| * | ||
| * @param val number of datanodes | ||
| * | ||
| * @return MiniOzoneCluster.Builder | ||
| */ | ||
| public Builder setNumDatanodes(int val) { | ||
|
|
@@ -380,9 +404,12 @@ interface DatanodeFactory extends CheckedFunction<OzoneConfiguration, OzoneConfi | |
| // marker | ||
| } | ||
|
|
||
| /** Service to manage as part of the mini cluster. */ | ||
| /** | ||
| * Service to manage as part of the mini cluster. | ||
| */ | ||
| interface Service { | ||
| void start(OzoneConfiguration conf) throws Exception; | ||
|
|
||
| void stop() throws Exception; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems
DEFAULT_TEST_DATA_DIRcan be removed as well, it's not used anymore