HDFS-11831. Ozone: Improve the way of getting test file path in unit tests for Windows. Contributed by Yiqun Lin.

This commit is contained in:
Xiaoyu Yao 2017-05-16 15:48:51 -07:00 committed by Owen O'Malley
parent c9e6d4378d
commit 7f0be64284
10 changed files with 35 additions and 48 deletions

View File

@ -19,14 +19,13 @@
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 void testWriteToPersistentStore() throws Exception {
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");

View File

@ -26,6 +26,7 @@
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 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);

View File

@ -29,6 +29,7 @@
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.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 @@ private static OzoneConfiguration initOzoneConfiguration(Pipeline pipeline) {
}
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 @@ private XceiverClient createClientForTesting(OzoneConfiguration conf)
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);

View File

@ -25,6 +25,7 @@
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 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();

View File

@ -21,6 +21,7 @@
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 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");

View File

@ -22,6 +22,7 @@
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.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);

View File

@ -24,6 +24,7 @@
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 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)

View File

@ -26,6 +26,7 @@
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 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 static void init() throws IOException,
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);

View File

@ -27,6 +27,7 @@
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.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);

View File

@ -20,7 +20,6 @@
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.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 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));