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 @@ -93,7 +93,10 @@ public static Instant getTestStartTime() {
* 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);
Expand All @@ -110,7 +113,10 @@ public static File getTestDir() {
* 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();
}
Expand All @@ -120,7 +126,10 @@ public static File getTestDir(String subdir) {
* 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());
}
Expand All @@ -132,7 +141,10 @@ public static File getRandomizedTestDir() {
*
* @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);
Expand All @@ -153,8 +165,11 @@ public static String getTempPath(String subpath) {
* 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
import org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.container.common.SCMTestUtils;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;
import java.util.UUID;
import java.nio.file.Path;

import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_METADATA_DIR_NAME;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SECURITY_ENABLED_KEY;
Expand Down Expand Up @@ -82,12 +82,10 @@ public static void shutdown() {

@ParameterizedTest(name = "Ozone security enabled: {0}")
@ValueSource(booleans = {false, true})
public void testCaching(boolean securityEnabled) throws IOException {
public void testCaching(boolean securityEnabled, @TempDir Path metaDir) throws IOException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setBoolean(OZONE_SECURITY_ENABLED_KEY, securityEnabled);
String metaDir = GenericTestUtils.getTempPath(
TestXceiverClientManager.class.getName() + UUID.randomUUID());
conf.set(HDDS_METADATA_DIR_NAME, metaDir);
conf.set(HDDS_METADATA_DIR_NAME, metaDir.toString());

ClientTrustManager trustManager = mock(ClientTrustManager.class);
try (XceiverClientManager clientManager = new XceiverClientManager(conf,
Expand Down Expand Up @@ -124,13 +122,11 @@ public void testCaching(boolean securityEnabled) throws IOException {
}

@Test
public void testFreeByReference() throws IOException {
public void testFreeByReference(@TempDir Path metaDir) throws IOException {
OzoneConfiguration conf = new OzoneConfiguration();
ScmClientConfig clientConfig = conf.getObject(ScmClientConfig.class);
clientConfig.setMaxSize(1);
String metaDir = GenericTestUtils.getTempPath(
TestXceiverClientManager.class.getName() + UUID.randomUUID());
conf.set(HDDS_METADATA_DIR_NAME, metaDir);
conf.set(HDDS_METADATA_DIR_NAME, metaDir.toString());
try (XceiverClientManager clientManager =
new XceiverClientManager(conf, clientConfig, null)) {
Cache<String, XceiverClientSpi> cache =
Expand Down Expand Up @@ -181,13 +177,11 @@ public void testFreeByReference() throws IOException {
}

@Test
public void testFreeByEviction() throws IOException {
public void testFreeByEviction(@TempDir Path metaDir) throws IOException {
OzoneConfiguration conf = new OzoneConfiguration();
ScmClientConfig clientConfig = conf.getObject(ScmClientConfig.class);
clientConfig.setMaxSize(1);
String metaDir = GenericTestUtils.getTempPath(
TestXceiverClientManager.class.getName() + UUID.randomUUID());
conf.set(HDDS_METADATA_DIR_NAME, metaDir);
conf.set(HDDS_METADATA_DIR_NAME, metaDir.toString());
try (XceiverClientManager clientManager =
new XceiverClientManager(conf, clientConfig, null)) {
Cache<String, XceiverClientSpi> cache =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import static org.apache.ozone.test.MetricsAsserts.getLongCounter;
import static org.apache.ozone.test.MetricsAsserts.getMetrics;

import java.nio.file.Path;
import java.util.List;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;

Expand All @@ -45,6 +45,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;

/**
* This class tests the metrics of XceiverClient.
Expand Down Expand Up @@ -76,11 +77,9 @@ public static void shutdown() {
}

@Test
public void testMetrics() throws Exception {
public void testMetrics(@TempDir Path metaDir) throws Exception {
OzoneConfiguration conf = new OzoneConfiguration();
String metaDir = GenericTestUtils.getTempPath(
TestXceiverClientManager.class.getName() + UUID.randomUUID());
conf.set(HDDS_METADATA_DIR_NAME, metaDir);
conf.set(HDDS_METADATA_DIR_NAME, metaDir.toString());

try (XceiverClientManager clientManager = new XceiverClientManager(conf)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.util.ExitUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -109,9 +109,10 @@ public final class TestBlockTokens {
private static final int EXPIRY_DURATION_IN_MS = 10000;
private static final int ROTATION_CHECK_DURATION_IN_MS = 100;

@TempDir
private static File workDir;
private static MiniKdc miniKdc;
private static OzoneConfiguration conf;
private static File workDir;
private static File ozoneKeytab;
private static File spnegoKeytab;
private static File testUserKeytab;
Expand All @@ -129,9 +130,6 @@ public static void init() throws Exception {

ExitUtils.disableSystemExit();

workDir =
GenericTestUtils.getTestDir(TestBlockTokens.class.getSimpleName());

startMiniKdc();
setSecureConfig();
createCredentialsInKDC();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.util.ExitUtils;
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -86,10 +87,12 @@
public final class TestBlockTokensCLI {
private static final Logger LOG = LoggerFactory
.getLogger(TestBlockTokensCLI.class);

@TempDir
private static File workDir;
private static MiniKdc miniKdc;
private static OzoneAdmin ozoneAdmin;
private static OzoneConfiguration conf;
private static File workDir;
private static File ozoneKeytab;
private static File spnegoKeytab;
private static String host;
Expand All @@ -105,8 +108,6 @@ public static void init() throws Exception {

ExitUtils.disableSystemExit();

workDir =
GenericTestUtils.getTestDir(TestBlockTokens.class.getSimpleName());
omServiceId = "om-service-test";
scmServiceId = "scm-service-test";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ public final class TestDelegationToken {

@TempDir
private Path folder;
@TempDir
private File workDir;

private MiniKdc miniKdc;
private OzoneConfiguration conf;
private File workDir;
private File scmKeytab;
private File spnegoKeytab;
private File omKeyTab;
Expand Down Expand Up @@ -166,8 +167,6 @@ public void init() {
conf.setBoolean(OZONE_SECURITY_ENABLED_KEY, true);
conf.set(HADOOP_SECURITY_AUTHENTICATION, KERBEROS.name());

workDir = GenericTestUtils.getTestDir(getClass().getSimpleName());

startMiniKdc();
setSecureConfig();
createCredentialsInKDC();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.hadoop.ozone;

import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hdds.DFSConfigKeysLegacy;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand All @@ -36,11 +35,11 @@
import org.apache.hadoop.ozone.om.KeyManagerImpl;
import org.apache.hadoop.ozone.om.OmTestManagers;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.util.List;
Expand All @@ -62,13 +61,14 @@
@Timeout(300)
public class TestOMSortDatanodes {

@TempDir
private static File dir;
private static OzoneConfiguration config;
private static StorageContainerManager scm;
private static NodeManager nodeManager;
private static KeyManagerImpl keyManager;
private static StorageContainerLocationProtocol mockScmContainerClient;
private static OzoneManager om;
private static File dir;
private static final int NODE_COUNT = 10;
private static final Map<String, String> EDGE_NODES = ImmutableMap.of(
"edge0", "/rack0",
Expand All @@ -80,7 +80,6 @@ public class TestOMSortDatanodes {
@BeforeAll
public static void setup() throws Exception {
config = new OzoneConfiguration();
dir = GenericTestUtils.getRandomizedTestDir();
config.set(HddsConfigKeys.OZONE_METADATA_DIRS, dir.toString());
config.set(NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
StaticMapping.class.getName());
Expand Down Expand Up @@ -128,7 +127,6 @@ public static void cleanup() throws Exception {
if (om != null) {
om.stop();
}
FileUtils.deleteDirectory(dir);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedExceptionAction;
Expand Down Expand Up @@ -195,6 +196,7 @@
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.EnumSource;
Expand Down Expand Up @@ -4810,17 +4812,13 @@ void testMultiPartUploadWithStream(ReplicationConfig replicationConfig)
}

@Test
public void testUploadWithStreamAndMemoryMappedBuffer() throws IOException {
// create a local dir
final String dir = GenericTestUtils.getTempPath(
getClass().getSimpleName());
GenericTestUtils.assertDirCreation(new File(dir));
public void testUploadWithStreamAndMemoryMappedBuffer(@TempDir Path dir) throws IOException {

// create a local file
final int chunkSize = 1024;
final byte[] data = new byte[8 * chunkSize];
ThreadLocalRandom.current().nextBytes(data);
final File file = new File(dir, "data");
final File file = new File(dir.toString(), "data");
try (FileOutputStream out = new FileOutputStream(file)) {
out.write(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyArgs;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -75,10 +73,6 @@ public class TestBCSID {
*/
@BeforeAll
public static void init() throws Exception {
String path = GenericTestUtils
.getTempPath(TestBCSID.class.getSimpleName());
File baseDir = new File(path);
baseDir.mkdirs();

conf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL, 200,
TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.HashMap;
Expand Down Expand Up @@ -80,7 +79,6 @@ public class TestContainerReplicationEndToEnd {
private static ObjectStore objectStore;
private static String volumeName;
private static String bucketName;
private static String path;
private static XceiverClientManager xceiverClientManager;
private static long containerReportInterval;

Expand All @@ -92,10 +90,7 @@ public class TestContainerReplicationEndToEnd {
@BeforeAll
public static void init() throws Exception {
conf = new OzoneConfiguration();
path = GenericTestUtils
.getTempPath(TestContainerStateMachineFailures.class.getSimpleName());
File baseDir = new File(path);
baseDir.mkdirs();

containerReportInterval = 2000;

conf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL,
Expand Down
Loading