From 349a87ac9c20958813e311b79dbf6c3faf5daec2 Mon Sep 17 00:00:00 2001 From: Weiwei Yang Date: Wed, 26 Jul 2017 17:51:05 +0800 Subject: [PATCH] HDFS-12192. Ozone: Fix the remaining failure tests for Windows caused by incorrect path generated. Contributed by Yiqun Lin. --- .../hadoop/cblock/TestBufferManager.java | 41 +++++++++---------- .../hadoop/cblock/TestCBlockReadWrite.java | 15 +++---- .../hadoop/cblock/TestLocalBlockCache.java | 7 +--- .../common/TestDatanodeStateMachine.java | 6 +-- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestBufferManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestBufferManager.java index e38ca71e284..73c8696beb1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestBufferManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestBufferManager.java @@ -25,7 +25,6 @@ import org.apache.hadoop.cblock.jscsiHelper.cache.impl.CBlockLocalCache; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConfiguration; -import org.apache.hadoop.ozone.container.ozoneimpl.TestOzoneContainer; import org.apache.hadoop.scm.XceiverClientManager; import org.apache.hadoop.scm.XceiverClientSpi; import org.apache.hadoop.scm.container.common.helpers.Pipeline; @@ -37,9 +36,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.io.File; import java.io.IOException; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.TimeoutException; @@ -69,9 +66,8 @@ public class TestBufferManager { @BeforeClass public static void init() throws IOException { config = new OzoneConfiguration(); - File p = GenericTestUtils.getTestDir(); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils.getTempPath( + TestBufferManager.class.getSimpleName()); config.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); config.setBoolean(DFS_CBLOCK_TRACE_IO, true); config.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -129,11 +125,9 @@ public class TestBufferManager { InterruptedException, TimeoutException { // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName() + - GenericTestUtils.getMethodName() + - RandomStringUtils.randomNumeric(4)); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -214,8 +208,9 @@ public class TestBufferManager { InterruptedException, TimeoutException{ // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -258,8 +253,9 @@ public class TestBufferManager { InterruptedException, TimeoutException { // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -306,8 +302,9 @@ public class TestBufferManager { InterruptedException, TimeoutException { // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -354,8 +351,9 @@ public class TestBufferManager { InterruptedException, TimeoutException{ // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -400,8 +398,9 @@ public class TestBufferManager { InterruptedException, TimeoutException{ // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestBufferManager.class.getSimpleName() + + RandomStringUtils.randomNumeric(4)); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockReadWrite.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockReadWrite.java index 94fe4cb2cba..811901fea6d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockReadWrite.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestCBlockReadWrite.java @@ -28,7 +28,6 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConfiguration; import org.apache.hadoop.ozone.OzoneConsts; -import org.apache.hadoop.ozone.container.ozoneimpl.TestOzoneContainer; import org.apache.hadoop.scm.XceiverClientManager; import org.apache.hadoop.scm.XceiverClientSpi; import org.apache.hadoop.scm.container.common.helpers.Pipeline; @@ -42,7 +41,6 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; @@ -74,9 +72,8 @@ public class TestCBlockReadWrite { @BeforeClass public static void init() throws IOException { config = new OzoneConfiguration(); - URL p = config.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestCBlockReadWrite.class.getSimpleName()); config.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); config.setBoolean(DFS_CBLOCK_TRACE_IO, true); config.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -193,8 +190,8 @@ public class TestCBlockReadWrite { InterruptedException, TimeoutException { // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestCBlockReadWrite.class.getSimpleName()); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); @@ -282,8 +279,8 @@ public class TestCBlockReadWrite { InterruptedException, TimeoutException { // Create a new config so that this tests write metafile to new location OzoneConfiguration flushTestConfig = new OzoneConfiguration(); - URL p = flushTestConfig.getClass().getResource(""); - String path = p.getPath().concat(TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestCBlockReadWrite.class.getSimpleName()); flushTestConfig.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); flushTestConfig.setBoolean(DFS_CBLOCK_TRACE_IO, true); flushTestConfig.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestLocalBlockCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestLocalBlockCache.java index eec417a2ded..75147152918 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestLocalBlockCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cblock/TestLocalBlockCache.java @@ -29,7 +29,6 @@ import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ozone.MiniOzoneCluster; import org.apache.hadoop.ozone.OzoneConfiguration; import org.apache.hadoop.ozone.OzoneConsts; -import org.apache.hadoop.ozone.container.ozoneimpl.TestOzoneContainer; import org.apache.hadoop.scm.XceiverClientManager; import org.apache.hadoop.scm.XceiverClientSpi; import org.apache.hadoop.scm.container.common.helpers.Pipeline; @@ -45,7 +44,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.LinkedList; @@ -80,9 +78,8 @@ public class TestLocalBlockCache { @BeforeClass public static void init() throws IOException { config = new OzoneConfiguration(); - URL p = config.getClass().getResource(""); - String path = p.getPath().concat( - TestOzoneContainer.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestLocalBlockCache.class.getSimpleName()); config.set(DFS_CBLOCK_DISK_CACHE_PATH_KEY, path); config.setBoolean(DFS_CBLOCK_TRACE_IO, true); config.setBoolean(DFS_CBLOCK_ENABLE_SHORT_CIRCUIT_IO, true); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java index 15b28527ef4..2ffdba7e3f0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/TestDatanodeStateMachine.java @@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; -import java.net.URL; import java.nio.file.Paths; import java.util.LinkedList; import java.util.List; @@ -94,9 +93,8 @@ public class TestDatanodeStateMachine { conf.setStrings(ScmConfigKeys.OZONE_SCM_NAMES, serverAddresses.toArray(new String[0])); - URL p = this.getClass().getResource(""); - String path = p.getPath().concat( - TestDatanodeStateMachine.class.getSimpleName()); + String path = GenericTestUtils + .getTempPath(TestDatanodeStateMachine.class.getSimpleName()); testRoot = new File(path); if (!testRoot.mkdirs()) { LOG.info("Required directories already exist.");