Java Code Examples for org.apache.hadoop.test.PathUtils#getTestDirName()
The following examples show how to use
org.apache.hadoop.test.PathUtils#getTestDirName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestClusterId.java From hadoop with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IOException { ExitUtil.disableSystemExit(); String baseDir = PathUtils.getTestDirName(getClass()); hdfsDir = new File(baseDir, "dfs/name"); if (hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir)) { throw new IOException("Could not delete test directory '" + hdfsDir + "'"); } LOG.info("hdfsdir is " + hdfsDir.getAbsolutePath()); // as some tests might change these values we reset them to defaults before // every test StartupOption.FORMAT.setForceFormat(false); StartupOption.FORMAT.setInteractiveFormat(true); config = new Configuration(); config.set(DFS_NAMENODE_NAME_DIR_KEY, hdfsDir.getPath()); }
Example 2
Source File: TestDecommission.java From hadoop with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { conf = new HdfsConfiguration(); // Set up the hosts/exclude files. localFileSys = FileSystem.getLocal(conf); Path workingDir = localFileSys.getWorkingDirectory(); dir = new Path(workingDir, PathUtils.getTestDirName(getClass()) + "/work-dir/decommission"); hostsFile = new Path(dir, "hosts"); excludeFile = new Path(dir, "exclude"); // Setup conf conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_REPLICATION_CONSIDERLOAD_KEY, false); conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath()); conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); conf.setInt(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 2000); conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, HEARTBEAT_INTERVAL); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, 1); conf.setInt(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, BLOCKREPORT_INTERVAL_MSEC); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_PENDING_TIMEOUT_SEC_KEY, 4); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, NAMENODE_REPLICATION_INTERVAL); writeConfigFile(hostsFile, null); writeConfigFile(excludeFile, null); }
Example 3
Source File: TestClusterId.java From big-c with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IOException { ExitUtil.disableSystemExit(); String baseDir = PathUtils.getTestDirName(getClass()); hdfsDir = new File(baseDir, "dfs/name"); if (hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir)) { throw new IOException("Could not delete test directory '" + hdfsDir + "'"); } LOG.info("hdfsdir is " + hdfsDir.getAbsolutePath()); // as some tests might change these values we reset them to defaults before // every test StartupOption.FORMAT.setForceFormat(false); StartupOption.FORMAT.setInteractiveFormat(true); config = new Configuration(); config.set(DFS_NAMENODE_NAME_DIR_KEY, hdfsDir.getPath()); }
Example 4
Source File: TestDecommission.java From big-c with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { conf = new HdfsConfiguration(); // Set up the hosts/exclude files. localFileSys = FileSystem.getLocal(conf); Path workingDir = localFileSys.getWorkingDirectory(); dir = new Path(workingDir, PathUtils.getTestDirName(getClass()) + "/work-dir/decommission"); hostsFile = new Path(dir, "hosts"); excludeFile = new Path(dir, "exclude"); // Setup conf conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_REPLICATION_CONSIDERLOAD_KEY, false); conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath()); conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); conf.setInt(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 2000); conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, HEARTBEAT_INTERVAL); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, 1); conf.setInt(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, BLOCKREPORT_INTERVAL_MSEC); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_PENDING_TIMEOUT_SEC_KEY, 4); conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, NAMENODE_REPLICATION_INTERVAL); writeConfigFile(hostsFile, null); writeConfigFile(excludeFile, null); }
Example 5
Source File: TestFSImage.java From hadoop with Apache License 2.0 | 5 votes |
/** * In this test case, I have created an image with a file having * preferredblockSize = 0. We are trying to read this image (since file with * preferredblockSize = 0 was allowed pre 2.1.0-beta version. The namenode * after 2.6 version will not be able to read this particular file. * See HDFS-7788 for more information. * @throws Exception */ @Test public void testZeroBlockSize() throws Exception { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_2_7_ZER0_BLOCK_SIZE_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-with-zero-block-size"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .waitSafeMode(false) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/tmp/zeroBlockFile"); assertTrue("File /tmp/zeroBlockFile doesn't exist ", fs.exists(testPath)); assertTrue("Name node didn't come up", cluster.isNameNodeUp(0)); } finally { cluster.shutdown(); //Clean up FileUtil.fullyDelete(dfsDir); } }
Example 6
Source File: TestFileAppendRestart.java From hadoop with Apache License 2.0 | 5 votes |
/** * Earlier versions of HDFS had a bug (HDFS-2991) which caused * append(), when called exactly at a block boundary, * to not log an OP_ADD. This ensures that we can read from * such buggy versions correctly, by loading an image created * using a namesystem image created with 0.23.1-rc2 exhibiting * the issue. */ @Test public void testLoadLogsFromBuggyEarlierVersions() throws IOException { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_23_BROKEN_APPEND_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-with-buggy-append"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .numDataNodes(0) .waitSafeMode(false) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/tmp/io_data/test_io_0"); assertEquals(2*1024*1024, fs.getFileStatus(testPath).getLen()); } finally { cluster.shutdown(); } }
Example 7
Source File: TestFSInputChecker.java From hadoop with Apache License 2.0 | 5 votes |
private void testFileCorruption(LocalFileSystem fileSys) throws IOException { // create a file and verify that checksum corruption results in // a checksum exception on LocalFS String dir = PathUtils.getTestDirName(getClass()); Path file = new Path(dir + "/corruption-test.dat"); Path crcFile = new Path(dir + "/.corruption-test.dat.crc"); writeFile(fileSys, file); int fileLen = (int)fileSys.getFileStatus(file).getLen(); byte [] buf = new byte[fileLen]; InputStream in = fileSys.open(file); IOUtils.readFully(in, buf, 0, buf.length); in.close(); // check .crc corruption checkFileCorruption(fileSys, file, crcFile); fileSys.delete(file, true); writeFile(fileSys, file); // check data corrutpion checkFileCorruption(fileSys, file, file); fileSys.delete(file, true); }
Example 8
Source File: TestFSImage.java From big-c with Apache License 2.0 | 5 votes |
/** * In this test case, I have created an image with a file having * preferredblockSize = 0. We are trying to read this image (since file with * preferredblockSize = 0 was allowed pre 2.1.0-beta version. The namenode * after 2.6 version will not be able to read this particular file. * See HDFS-7788 for more information. * @throws Exception */ @Test public void testZeroBlockSize() throws Exception { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_2_7_ZER0_BLOCK_SIZE_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-with-zero-block-size"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .waitSafeMode(false) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/tmp/zeroBlockFile"); assertTrue("File /tmp/zeroBlockFile doesn't exist ", fs.exists(testPath)); assertTrue("Name node didn't come up", cluster.isNameNodeUp(0)); } finally { cluster.shutdown(); //Clean up FileUtil.fullyDelete(dfsDir); } }
Example 9
Source File: TestFileAppendRestart.java From big-c with Apache License 2.0 | 5 votes |
/** * Earlier versions of HDFS had a bug (HDFS-2991) which caused * append(), when called exactly at a block boundary, * to not log an OP_ADD. This ensures that we can read from * such buggy versions correctly, by loading an image created * using a namesystem image created with 0.23.1-rc2 exhibiting * the issue. */ @Test public void testLoadLogsFromBuggyEarlierVersions() throws IOException { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_23_BROKEN_APPEND_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-with-buggy-append"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .numDataNodes(0) .waitSafeMode(false) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/tmp/io_data/test_io_0"); assertEquals(2*1024*1024, fs.getFileStatus(testPath).getLen()); } finally { cluster.shutdown(); } }
Example 10
Source File: TestFSInputChecker.java From big-c with Apache License 2.0 | 5 votes |
private void testFileCorruption(LocalFileSystem fileSys) throws IOException { // create a file and verify that checksum corruption results in // a checksum exception on LocalFS String dir = PathUtils.getTestDirName(getClass()); Path file = new Path(dir + "/corruption-test.dat"); Path crcFile = new Path(dir + "/.corruption-test.dat.crc"); writeFile(fileSys, file); int fileLen = (int)fileSys.getFileStatus(file).getLen(); byte [] buf = new byte[fileLen]; InputStream in = fileSys.open(file); IOUtils.readFully(in, buf, 0, buf.length); in.close(); // check .crc corruption checkFileCorruption(fileSys, file, crcFile); fileSys.delete(file, true); writeFile(fileSys, file); // check data corrutpion checkFileCorruption(fileSys, file, file); fileSys.delete(file, true); }
Example 11
Source File: TestPersistBlocks.java From hadoop with Apache License 2.0 | 4 votes |
/** * Earlier versions of HDFS didn't persist block allocation to the edit log. * This makes sure that we can still load an edit log when the OP_CLOSE * is the opcode which adds all of the blocks. This is a regression * test for HDFS-2773. * This test uses a tarred pseudo-distributed cluster from Hadoop 1.0 * which has a multi-block file. This is similar to the tests in * {@link TestDFSUpgradeFromImage} but none of those images include * a multi-block file. */ @Test public void testEarlierVersionEditLog() throws Exception { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_1_0_MULTIBLOCK_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-1.0"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); File dataDir = new File(dfsDir, "data"); GenericTestUtils.assertExists(dataDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dataDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .numDataNodes(1) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/user/todd/4blocks"); // Read it without caring about the actual data within - we just need // to make sure that the block states and locations are OK. DFSTestUtil.readFile(fs, testPath); // Ensure that we can append to it - if the blocks were in some funny // state we'd get some kind of issue here. FSDataOutputStream stm = fs.append(testPath); try { stm.write(1); } finally { IOUtils.closeStream(stm); } } finally { cluster.shutdown(); } }
Example 12
Source File: TestPersistBlocks.java From big-c with Apache License 2.0 | 4 votes |
/** * Earlier versions of HDFS didn't persist block allocation to the edit log. * This makes sure that we can still load an edit log when the OP_CLOSE * is the opcode which adds all of the blocks. This is a regression * test for HDFS-2773. * This test uses a tarred pseudo-distributed cluster from Hadoop 1.0 * which has a multi-block file. This is similar to the tests in * {@link TestDFSUpgradeFromImage} but none of those images include * a multi-block file. */ @Test public void testEarlierVersionEditLog() throws Exception { final Configuration conf = new HdfsConfiguration(); String tarFile = System.getProperty("test.cache.data", "build/test/cache") + "/" + HADOOP_1_0_MULTIBLOCK_TGZ; String testDir = PathUtils.getTestDirName(getClass()); File dfsDir = new File(testDir, "image-1.0"); if (dfsDir.exists() && !FileUtil.fullyDelete(dfsDir)) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } FileUtil.unTar(new File(tarFile), new File(testDir)); File nameDir = new File(dfsDir, "name"); GenericTestUtils.assertExists(nameDir); File dataDir = new File(dfsDir, "data"); GenericTestUtils.assertExists(dataDir); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dataDir.getAbsolutePath()); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0) .format(false) .manageDataDfsDirs(false) .manageNameDfsDirs(false) .numDataNodes(1) .startupOption(StartupOption.UPGRADE) .build(); try { FileSystem fs = cluster.getFileSystem(); Path testPath = new Path("/user/todd/4blocks"); // Read it without caring about the actual data within - we just need // to make sure that the block states and locations are OK. DFSTestUtil.readFile(fs, testPath); // Ensure that we can append to it - if the blocks were in some funny // state we'd get some kind of issue here. FSDataOutputStream stm = fs.append(testPath); try { stm.write(1); } finally { IOUtils.closeStream(stm); } } finally { cluster.shutdown(); } }