Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
* 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)}.
Expand All @@ -68,16 +66,8 @@ public abstract class GenericTestUtils {
public static final String ERROR_INVALID_ARGUMENT =
"Total wait time should be greater than check interval time";

public static final boolean WINDOWS =
System.getProperty("os.name").startsWith("Windows");

private static final long NANOSECONDS_PER_MILLISECOND = 1_000_000;

static {
DEFAULT_TEST_DATA_DIR =
"target" + File.separator + "test" + File.separator + "data";
}

/**
* Return current time in millis as an {@code Instant}. This may be
* before {@link Instant#now()}, since the latter includes nanoseconds, too.
Expand All @@ -90,31 +80,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.apache.hadoop.hdds.protocol.DatanodeDetails.Port;
import static org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails;
import static org.apache.hadoop.ozone.MiniOzoneCluster.getTempPath;
import static org.apache.hadoop.ozone.OzoneConfigKeys.HDDS_CONTAINER_RATIS_IPC_RANDOM_PORT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -45,7 +46,6 @@
import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine;
import org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine;
import org.apache.hadoop.ozone.container.common.volume.StorageVolume;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -267,7 +267,7 @@ public void testMultipleDataDirs() throws Exception {
+ "-" + cluster.getClusterId();
assertEquals(name, cluster.getName());

final String baseDir = GenericTestUtils.getTempPath(name);
final String baseDir = getTempPath(name);
assertEquals(baseDir, cluster.getBaseDir());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
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.
Expand Down Expand Up @@ -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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving the method as protected and related constants as private to MiniOzoneCluster.Builder for a cleaner MiniOzoneCluster interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion


/**
Expand Down Expand Up @@ -303,7 +327,7 @@ public Builder setSCMConfigurator(SCMConfigurator configurator) {

private void setClusterId() {
clusterId = UUID.randomUUID().toString();
path = GenericTestUtils.getTempPath(
path = getTempPath(
MiniOzoneClusterImpl.class.getSimpleName() + "-" + clusterId);
}

Expand Down