|
@@ -61,6 +61,8 @@ import static org.junit.Assert.*;
|
|
|
public class TestDFSShell {
|
|
|
private static final Log LOG = LogFactory.getLog(TestDFSShell.class);
|
|
|
private static AtomicInteger counter = new AtomicInteger();
|
|
|
+ private final int SUCCESS = 0;
|
|
|
+ private final int ERROR = 1;
|
|
|
|
|
|
static final String TEST_ROOT_DIR = PathUtils.getTestDirName(TestDFSShell.class);
|
|
|
|
|
@@ -1619,9 +1621,6 @@ public class TestDFSShell {
|
|
|
// force Copy Option is -f
|
|
|
@Test (timeout = 30000)
|
|
|
public void testCopyCommandsWithForceOption() throws Exception {
|
|
|
- final int SUCCESS = 0;
|
|
|
- final int ERROR = 1;
|
|
|
-
|
|
|
Configuration conf = new Configuration();
|
|
|
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
|
|
.format(true).build();
|
|
@@ -1682,7 +1681,55 @@ public class TestDFSShell {
|
|
|
}
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // setrep for file and directory.
|
|
|
+ @Test (timeout = 30000)
|
|
|
+ public void testSetrep() throws Exception {
|
|
|
+
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
|
|
+ .format(true).build();
|
|
|
+ FsShell shell = null;
|
|
|
+ FileSystem fs = null;
|
|
|
+
|
|
|
+ final String testdir1 = "/tmp/TestDFSShell-testSetrep-" + counter.getAndIncrement();
|
|
|
+ final String testdir2 = testdir1 + "/nestedDir";
|
|
|
+ final Path hdfsFile1 = new Path(testdir1, "testFileForSetrep");
|
|
|
+ final Path hdfsFile2 = new Path(testdir2, "testFileForSetrep");
|
|
|
+ final Short oldRepFactor = new Short((short) 1);
|
|
|
+ final Short newRepFactor = new Short((short) 3);
|
|
|
+ try {
|
|
|
+ String[] argv;
|
|
|
+ cluster.waitActive();
|
|
|
+ fs = cluster.getFileSystem();
|
|
|
+ assertThat(fs.mkdirs(new Path(testdir2)), is(true));
|
|
|
+ shell = new FsShell(conf);
|
|
|
+
|
|
|
+ fs.create(hdfsFile1, true).close();
|
|
|
+ fs.create(hdfsFile2, true).close();
|
|
|
+
|
|
|
+ // Tests for setrep on a file.
|
|
|
+ argv = new String[] { "-setrep", newRepFactor.toString(), hdfsFile1.toString() };
|
|
|
+ assertThat(shell.run(argv), is(SUCCESS));
|
|
|
+ assertThat(fs.getFileStatus(hdfsFile1).getReplication(), is(newRepFactor));
|
|
|
+ assertThat(fs.getFileStatus(hdfsFile2).getReplication(), is(oldRepFactor));
|
|
|
|
|
|
+ // Tests for setrep
|
|
|
+
|
|
|
+ // Tests for setrep on a directory and make sure it is applied recursively.
|
|
|
+ argv = new String[] { "-setrep", newRepFactor.toString(), testdir1 };
|
|
|
+ assertThat(shell.run(argv), is(SUCCESS));
|
|
|
+ assertThat(fs.getFileStatus(hdfsFile1).getReplication(), is(newRepFactor));
|
|
|
+ assertThat(fs.getFileStatus(hdfsFile2).getReplication(), is(newRepFactor));
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ if (shell != null) {
|
|
|
+ shell.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|