diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockServerPersistence.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockServerPersistence.java index 0dee7bbcd4d..f4f927f0f4e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockServerPersistence.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockServerPersistence.java @@ -19,14 +19,13 @@ package org.apache.hadoop.cblock; import org.apache.hadoop.cblock.meta.VolumeDescriptor; import org.apache.hadoop.scm.client.ScmClient; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.cblock.util.MockStorageClient; import org.apache.hadoop.ozone.OzoneConfiguration; -import org.apache.hadoop.ozone.container.ozoneimpl.TestOzoneContainer; import org.junit.Test; import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.List; import static org.apache.hadoop.cblock.CBlockConfigKeys.DFS_CBLOCK_SERVICE_LEVELDB_PATH_KEY; @@ -54,9 +53,8 @@ public class TestCBlockServerPersistence { int blockSize = 4096; CBlockManager cBlockManager = null; CBlockManager cBlockManager1 = null; - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestCBlockServerPersistence.class.getSimpleName()); File filePath = new File(path); if(!filePath.exists() && !filePath.mkdirs()) { throw new IOException("Unable to create test DB dir"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java index e01e7f084a1..0bc7c771edd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java @@ -26,6 +26,7 @@ import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfiguration; import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.scm.container.common.helpers.StorageContainerException; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.ozone.container.common.helpers.ChunkInfo; import org.apache.hadoop.ozone.container.common.helpers.ContainerData; import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; @@ -46,7 +47,6 @@ import org.junit.rules.Timeout; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.URL; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; @@ -92,9 +92,8 @@ public class TestContainerPersistence { @BeforeClass public static void init() throws Throwable { conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - path = p.getPath().concat( - TestContainerPersistence.class.getSimpleName()); + path = GenericTestUtils + .getTempPath(TestContainerPersistence.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainer.java index 8d33feb5ed8..73829d3584a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/ozoneimpl/TestOzoneContainer.java @@ -29,6 +29,7 @@ import org.apache.hadoop.scm.XceiverClient; import org.apache.hadoop.scm.XceiverClientRatis; import org.apache.hadoop.scm.XceiverClientSpi; import org.apache.hadoop.scm.container.common.helpers.Pipeline; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.ratis.rpc.RpcType; import org.apache.ratis.rpc.SupportedRpcType; import org.junit.Assert; @@ -36,7 +37,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; -import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -54,9 +54,8 @@ public class TestOzoneContainer { public void testCreateOzoneContainer() throws Exception { String containerName = OzoneUtils.getRequestID(); OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestOzoneContainer.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path); @@ -141,8 +140,8 @@ public class TestOzoneContainer { } private static void setOzoneLocalStorageRoot(OzoneConfiguration conf) { - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestOzoneContainer.class.getSimpleName()); path += conf.getTrimmed( OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); @@ -475,9 +474,8 @@ public class TestOzoneContainer { throws Exception { String containerName = OzoneUtils.getRequestID(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestOzoneContainer.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/block/TestBlockManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/block/TestBlockManager.java index 28839608c90..78daad49c32 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/block/TestBlockManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/block/TestBlockManager.java @@ -25,6 +25,7 @@ import org.apache.hadoop.ozone.scm.container.ContainerMapping; import org.apache.hadoop.ozone.scm.container.MockNodeManager; import org.apache.hadoop.scm.container.common.helpers.AllocatedBlock; import org.apache.hadoop.scm.container.common.helpers.Pipeline; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -35,7 +36,6 @@ import org.junit.rules.ExpectedException; import java.io.File; import java.io.IOException; -import java.net.URL; import java.nio.file.Paths; import java.util.UUID; @@ -59,10 +59,8 @@ public class TestBlockManager { public static void setUp() throws Exception { Configuration conf = SCMTestUtils.getConf(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat( - org.apache.hadoop.ozone.scm.container.TestContainerMapping - .class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBlockManager.class.getSimpleName()); conf.set(OzoneConfigKeys.OZONE_CONTAINER_METADATA_DIRS, path); testDir = Paths.get(path).toFile(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/container/TestContainerMapping.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/container/TestContainerMapping.java index 0b9b76f365d..c35e76fe49a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/container/TestContainerMapping.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/scm/container/TestContainerMapping.java @@ -21,6 +21,7 @@ import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.container.common.SCMTestUtils; import org.apache.hadoop.scm.container.common.helpers.Pipeline; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -31,8 +32,6 @@ import org.junit.rules.ExpectedException; import java.io.File; import java.io.IOException; -import java.net.URL; -import java.nio.file.Paths; import java.util.Set; import java.util.TreeSet; import java.util.UUID; @@ -51,12 +50,10 @@ public class TestContainerMapping { public static void setUp() throws Exception { Configuration conf = SCMTestUtils.getConf(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat( - TestContainerMapping.class.getSimpleName()); - - conf.set(OzoneConfigKeys.OZONE_CONTAINER_METADATA_DIRS, path); - testDir = Paths.get(path).toFile(); + testDir = GenericTestUtils + .getTestDir(TestContainerMapping.class.getSimpleName()); + conf.set(OzoneConfigKeys.OZONE_CONTAINER_METADATA_DIRS, + testDir.getAbsolutePath()); boolean folderExisted = testDir.exists() || testDir.mkdirs(); if (!folderExisted) { throw new IOException("Unable to create test directory path"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestLocalOzoneVolumes.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestLocalOzoneVolumes.java index 78e6c0f9484..561eaf37b39 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestLocalOzoneVolumes.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestLocalOzoneVolumes.java @@ -22,6 +22,7 @@ import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfiguration; import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.junit.AfterClass; @@ -31,7 +32,6 @@ import org.junit.Test; import org.junit.rules.Timeout; import java.io.IOException; -import java.net.URL; /** * Test ozone volume in the local storage handler scenario. @@ -59,9 +59,8 @@ public class TestLocalOzoneVolumes extends TestOzoneHelper { public static void init() throws Exception { OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - String path = p.getPath() - .concat(TestLocalOzoneVolumes.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestLocalOzoneVolumes.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java index b734c86b997..639c80cc9a3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java @@ -24,6 +24,7 @@ import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfiguration; import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.web.headers.Header; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.Time; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -37,7 +38,6 @@ import org.junit.rules.Timeout; import javax.ws.rs.core.HttpHeaders; import java.io.IOException; -import java.net.URL; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -69,8 +69,8 @@ public class TestOzoneWebAccess { public static void init() throws Exception { OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneWebAccess.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestOzoneWebAccess.class.getSimpleName()); conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path); cluster = new MiniOzoneCluster.Builder(conf) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestBuckets.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestBuckets.java index c115052c572..ef0a2fee61f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestBuckets.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestBuckets.java @@ -26,6 +26,7 @@ import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.web.exceptions.OzoneException; import org.apache.hadoop.ozone.web.request.OzoneQuota; import org.apache.hadoop.ozone.web.utils.OzoneUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; @@ -34,7 +35,6 @@ import org.junit.rules.Timeout; import java.io.IOException; import java.net.URISyntaxException; -import java.net.URL; import java.util.List; import static org.junit.Assert.assertEquals; @@ -65,8 +65,8 @@ public class TestBuckets { URISyntaxException, OzoneException { OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat(TestBuckets.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBuckets.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestKeys.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestKeys.java index cd61cb8bdb7..958e59ad111 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestKeys.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestKeys.java @@ -27,6 +27,7 @@ import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.web.exceptions.ErrorTable; import org.apache.hadoop.ozone.web.exceptions.OzoneException; import org.apache.hadoop.ozone.web.utils.OzoneUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.junit.AfterClass; @@ -40,7 +41,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; @@ -74,8 +74,7 @@ public class TestKeys { public static void init() throws Exception { OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - path = p.getPath().concat(TestKeys.class.getSimpleName()); + path = GenericTestUtils.getTempPath(TestKeys.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); conf.set(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, path); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestVolume.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestVolume.java index 79dc6934dc7..d4d8617fa8f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestVolume.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/client/TestVolume.java @@ -20,7 +20,6 @@ package org.apache.hadoop.ozone.web.client; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.RandomStringUtils; -import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConfigKeys; @@ -29,6 +28,7 @@ import org.apache.hadoop.ozone.web.exceptions.OzoneException; import org.apache.hadoop.ozone.web.request.OzoneQuota; import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.web.utils.OzoneUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.junit.AfterClass; @@ -38,7 +38,6 @@ import org.junit.Test; import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.List; import static org.junit.Assert.assertEquals; @@ -63,8 +62,8 @@ public class TestVolume { public static void init() throws Exception { OzoneConfiguration conf = new OzoneConfiguration(); - URL p = conf.getClass().getResource(""); - String path = p.getPath().concat(TestVolume.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestVolume.class.getSimpleName()); path += conf.getTrimmed(OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT, OzoneConfigKeys.OZONE_LOCALSTORAGE_ROOT_DEFAULT); FileUtils.deleteDirectory(new File(path));