/** * Test snapshot creation through WebHdfs */ @Test public void testWebHdfsCreateSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsFileSystem.SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); try { webHdfs.createSnapshot(foo); fail("Cannot create snapshot on a non-snapshottable directory"); } catch (Exception e) { GenericTestUtils.assertExceptionContains( "Directory is not a snapshottable directory", e); } // allow snapshots on /foo dfs.allowSnapshot(foo); // create snapshots on foo using WebHdfs webHdfs.createSnapshot(foo, "s1"); // create snapshot without specifying name final Path spath = webHdfs.createSnapshot(foo, null); Assert.assertTrue(webHdfs.exists(spath)); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Test snapshot deletion through WebHdfs */ @Test public void testWebHdfsDeleteSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsFileSystem.SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); dfs.allowSnapshot(foo); webHdfs.createSnapshot(foo, "s1"); final Path spath = webHdfs.createSnapshot(foo, null); Assert.assertTrue(webHdfs.exists(spath)); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); // delete the two snapshots webHdfs.deleteSnapshot(foo, "s1"); Assert.assertFalse(webHdfs.exists(s1path)); webHdfs.deleteSnapshot(foo, spath.getName()); Assert.assertFalse(webHdfs.exists(spath)); } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Test snapshot rename through WebHdfs */ @Test public void testWebHdfsRenameSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsFileSystem.SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); dfs.allowSnapshot(foo); webHdfs.createSnapshot(foo, "s1"); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); // rename s1 to s2 webHdfs.renameSnapshot(foo, "s1", "s2"); Assert.assertFalse(webHdfs.exists(s1path)); final Path s2path = SnapshotTestHelper.getSnapshotRoot(foo, "s2"); Assert.assertTrue(webHdfs.exists(s2path)); webHdfs.deleteSnapshot(foo, "s2"); Assert.assertFalse(webHdfs.exists(s2path)); } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Create files/directories/snapshots. */ void prepare(DistributedFileSystem dfs, short repl) throws Exception { for (Path d : dirs) { dfs.mkdirs(d); } for (Path file : files) { DFSTestUtil.createFile(dfs, file, fileSize, repl, 0L); } for (Map.Entry<Path, List<String>> entry : snapshotMap.entrySet()) { for (String snapshot : entry.getValue()) { SnapshotTestHelper.createSnapshot(dfs, entry.getKey(), snapshot); } } }
@Override boolean checkNamenodeBeforeReturn() throws Exception { final Path sPath = SnapshotTestHelper.getSnapshotRoot(new Path(dir), snapshotName); boolean snapshotCreated = dfs.exists(sPath); for (int i = 0; i < CHECKTIMES && !snapshotCreated; i++) { Thread.sleep(1000); snapshotCreated = dfs.exists(sPath); } return snapshotCreated; }
@Override void prepare() throws Exception { final Path dirPath = new Path(dir); if (!dfs.exists(dirPath)) { dfs.mkdirs(dirPath); } Path sPath = SnapshotTestHelper.getSnapshotRoot(dirPath, snapshotName); if (!dfs.exists(sPath)) { dfs.allowSnapshot(dirPath); dfs.createSnapshot(dirPath, snapshotName); } }
@Override boolean checkNamenodeBeforeReturn() throws Exception { final Path sPath = SnapshotTestHelper.getSnapshotRoot(new Path(dir), snapshotName); boolean snapshotNotDeleted = dfs.exists(sPath); for (int i = 0; i < CHECKTIMES && snapshotNotDeleted; i++) { Thread.sleep(1000); snapshotNotDeleted = dfs.exists(sPath); } return !snapshotNotDeleted; }
@Override void prepare() throws Exception { final Path dirPath = new Path(dir); if (!dfs.exists(dirPath)) { dfs.mkdirs(dirPath); } Path sPath = SnapshotTestHelper.getSnapshotRoot(dirPath, oldName); if (!dfs.exists(sPath)) { dfs.allowSnapshot(dirPath); dfs.createSnapshot(dirPath, oldName); } }
@Override boolean checkNamenodeBeforeReturn() throws Exception { final Path sPath = SnapshotTestHelper.getSnapshotRoot(new Path(dir), newName); boolean snapshotRenamed = dfs.exists(sPath); for (int i = 0; i < CHECKTIMES && !snapshotRenamed; i++) { Thread.sleep(1000); snapshotRenamed = dfs.exists(sPath); } return snapshotRenamed; }
@Override public void prepare() throws Exception { // original size: 2.5 blocks DFSTestUtil.createFile(dfs, file, BLOCKSIZE * 2 + BLOCKSIZE / 2, REPLICATION, 0L); SnapshotTestHelper.createSnapshot(dfs, dir, "s1"); // truncate to 1.5 block dfs.truncate(file, BLOCKSIZE + BLOCKSIZE / 2); TestFileTruncate.checkBlockRecovery(file, dfs); // append another 1 BLOCK DFSTestUtil.appendFile(dfs, file, BLOCKSIZE); }
private void testDeleteAddBlockRace(boolean hasSnapshot) throws Exception { try { conf.setClass(DFSConfigKeys.DFS_BLOCK_REPLICATOR_CLASSNAME_KEY, SlowBlockPlacementPolicy.class, BlockPlacementPolicy.class); cluster = new MiniDFSCluster.Builder(conf).build(); FileSystem fs = cluster.getFileSystem(); final String fileName = "/testDeleteAddBlockRace"; Path filePath = new Path(fileName); FSDataOutputStream out = null; out = fs.create(filePath); if (hasSnapshot) { SnapshotTestHelper.createSnapshot((DistributedFileSystem) fs, new Path( "/"), "s1"); } Thread deleteThread = new DeleteThread(fs, filePath); deleteThread.start(); try { // write data and syn to make sure a block is allocated. out.write(new byte[32], 0, 32); out.hsync(); Assert.fail("Should have failed."); } catch (FileNotFoundException e) { GenericTestUtils.assertExceptionContains(filePath.getName(), e); } } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Test snapshot creation through WebHdfs */ @Test public void testWebHdfsCreateSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); try { webHdfs.createSnapshot(foo); fail("Cannot create snapshot on a non-snapshottable directory"); } catch (Exception e) { GenericTestUtils.assertExceptionContains( "Directory is not a snapshottable directory", e); } // allow snapshots on /foo dfs.allowSnapshot(foo); // create snapshots on foo using WebHdfs webHdfs.createSnapshot(foo, "s1"); // create snapshot without specifying name final Path spath = webHdfs.createSnapshot(foo, null); Assert.assertTrue(webHdfs.exists(spath)); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Test snapshot deletion through WebHdfs */ @Test public void testWebHdfsDeleteSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); dfs.allowSnapshot(foo); webHdfs.createSnapshot(foo, "s1"); final Path spath = webHdfs.createSnapshot(foo, null); Assert.assertTrue(webHdfs.exists(spath)); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); // delete the two snapshots webHdfs.deleteSnapshot(foo, "s1"); Assert.assertFalse(webHdfs.exists(s1path)); webHdfs.deleteSnapshot(foo, spath.getName()); Assert.assertFalse(webHdfs.exists(spath)); } finally { if (cluster != null) { cluster.shutdown(); } } }
/** * Test snapshot rename through WebHdfs */ @Test public void testWebHdfsRenameSnapshot() throws Exception { MiniDFSCluster cluster = null; final Configuration conf = WebHdfsTestUtil.createConf(); try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); final DistributedFileSystem dfs = cluster.getFileSystem(); final FileSystem webHdfs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME); final Path foo = new Path("/foo"); dfs.mkdirs(foo); dfs.allowSnapshot(foo); webHdfs.createSnapshot(foo, "s1"); final Path s1path = SnapshotTestHelper.getSnapshotRoot(foo, "s1"); Assert.assertTrue(webHdfs.exists(s1path)); // rename s1 to s2 webHdfs.renameSnapshot(foo, "s1", "s2"); Assert.assertFalse(webHdfs.exists(s1path)); final Path s2path = SnapshotTestHelper.getSnapshotRoot(foo, "s2"); Assert.assertTrue(webHdfs.exists(s2path)); webHdfs.deleteSnapshot(foo, "s2"); Assert.assertFalse(webHdfs.exists(s2path)); } finally { if (cluster != null) { cluster.shutdown(); } } }