Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -21,7 +21,6 @@

import com.google.common.base.Preconditions;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
Expand Down Expand Up @@ -56,9 +55,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 +65,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 +79,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 @@ -45,7 +45,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 +266,7 @@ public void testMultipleDataDirs() throws Exception {
+ "-" + cluster.getClusterId();
assertEquals(name, cluster.getName());

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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;

Expand Down Expand Up @@ -250,7 +249,7 @@ default String getName() {
}

default String getBaseDir() {
return GenericTestUtils.getTempPath(getName());
return Builder.getTempPath(getName());
}

/**
Expand All @@ -263,6 +262,10 @@ abstract class Builder {
protected static final int ACTIVE_SCMS_NOT_SET = -1;
protected static final int DEFAULT_RATIS_RPC_TIMEOUT_SEC = 1;

private static final String SYSPROP_TEST_DATA_DIR = "test.build.data";
private static final String DEFAULT_TEST_DATA_PATH = "target/test/data/";
private static final boolean WINDOWS = System.getProperty("os.name").startsWith("Windows");

protected OzoneConfiguration conf;
protected String path;

Expand Down Expand Up @@ -296,14 +299,36 @@ protected void prepareForNextBuild() {
setClusterId();
}

/**
* 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
*/
protected 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;
}

public Builder setSCMConfigurator(SCMConfigurator configurator) {
this.scmConfigurator = configurator;
return this;
}

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

Expand Down