You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by el...@apache.org on 2012/09/05 21:44:48 UTC
svn commit: r1381321 - in
/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs:
TestDFSShell.java TestHDFSTrash.java
Author: eli
Date: Wed Sep 5 19:44:47 2012
New Revision: 1381321
URL: http://svn.apache.org/viewvc?rev=1381321&view=rev
Log:
HADOOP-8770. NN should not RPC to self to find trash defaults. Contributed by Eli Collins
Modified:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSTrash.java
Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java?rev=1381321&r1=1381320&r2=1381321&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java (original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java Wed Sep 5 19:44:47 2012
@@ -57,6 +57,8 @@ import org.apache.hadoop.util.StringUtil
import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;
+
/**
* This class tests commands from DFSShell.
*/
@@ -1480,4 +1482,95 @@ public class TestDFSShell {
}
+ /**
+ * Delete a file optionally configuring trash on the server and client.
+ */
+ private void deleteFileUsingTrash(
+ boolean serverTrash, boolean clientTrash) throws Exception {
+ // Run a cluster, optionally with trash enabled on the server
+ Configuration serverConf = new HdfsConfiguration();
+ if (serverTrash) {
+ serverConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
+ }
+
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(serverConf)
+ .numDataNodes(1).format(true).build();
+ Configuration clientConf = new Configuration(serverConf);
+
+ // Create a client, optionally with trash enabled
+ if (clientTrash) {
+ clientConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
+ } else {
+ clientConf.setLong(FS_TRASH_INTERVAL_KEY, 0);
+ }
+
+ FsShell shell = new FsShell(clientConf);
+ FileSystem fs = null;
+
+ try {
+ // Create and delete a file
+ fs = cluster.getFileSystem();
+ writeFile(fs, new Path(TEST_ROOT_DIR, "foo"));
+ final String testFile = TEST_ROOT_DIR + "/foo";
+ final String trashFile = shell.getCurrentTrashDir() + "/" + testFile;
+ String[] argv = new String[] { "-rm", testFile };
+ int res = ToolRunner.run(shell, argv);
+ assertEquals("rm failed", 0, res);
+
+ if (serverTrash) {
+ // If the server config was set we should use it unconditionally
+ assertTrue("File not in trash", fs.exists(new Path(trashFile)));
+ } else if (clientTrash) {
+ // If the server config was not set but the client config was
+ // set then we should use it
+ assertTrue("File not in trashed", fs.exists(new Path(trashFile)));
+ } else {
+ // If neither was set then we should not have trashed the file
+ assertFalse("File was not removed", fs.exists(new Path(testFile)));
+ assertFalse("File was trashed", fs.exists(new Path(trashFile)));
+ }
+ } finally {
+ if (fs != null) {
+ fs.close();
+ }
+ if (cluster != null) {
+ cluster.shutdown();
+ }
+ }
+ }
+
+ /**
+ * Test that the server trash configuration is respected when
+ * the client configuration is not set.
+ */
+ @Test
+ public void testServerConfigRespected() throws Exception {
+ deleteFileUsingTrash(true, false);
+ }
+
+ /**
+ * Test that server trash configuration is respected even when the
+ * client configuration is set.
+ */
+ @Test
+ public void testServerConfigRespectedWithClient() throws Exception {
+ deleteFileUsingTrash(true, true);
+ }
+
+ /**
+ * Test that the client trash configuration is respected when
+ * the server configuration is not set.
+ */
+ @Test
+ public void testClientConfigRespected() throws Exception {
+ deleteFileUsingTrash(false, true);
+ }
+
+ /**
+ * Test that trash is disabled by default.
+ */
+ @Test
+ public void testNoTrashConfig() throws Exception {
+ deleteFileUsingTrash(false, false);
+ }
}
Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSTrash.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSTrash.java?rev=1381321&r1=1381320&r2=1381321&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSTrash.java (original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSTrash.java Wed Sep 5 19:44:47 2012
@@ -23,11 +23,6 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.TestTrash;
-import org.apache.hadoop.fs.Trash;
-
-import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -62,53 +57,4 @@ public class TestHDFSTrash {
conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, fs.getUri().toString());
TestTrash.trashNonDefaultFS(conf);
}
-
- /** Clients should always use trash if enabled server side */
- @Test
- public void testTrashEnabledServerSide() throws IOException {
- Configuration serverConf = new HdfsConfiguration();
- Configuration clientConf = new Configuration();
-
- // Enable trash on the server and client
- serverConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
- clientConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
-
- MiniDFSCluster cluster2 = null;
- try {
- cluster2 = new MiniDFSCluster.Builder(serverConf).numDataNodes(1).build();
- FileSystem fs = cluster2.getFileSystem();
- assertTrue(new Trash(fs, clientConf).isEnabled());
-
- // Disabling trash on the client is ignored
- clientConf.setLong(FS_TRASH_INTERVAL_KEY, 0);
- assertTrue(new Trash(fs, clientConf).isEnabled());
- } finally {
- if (cluster2 != null) cluster2.shutdown();
- }
- }
-
- /** Clients should always use trash if enabled client side */
- @Test
- public void testTrashEnabledClientSide() throws IOException {
- Configuration serverConf = new HdfsConfiguration();
- Configuration clientConf = new Configuration();
-
- // Disable server side
- serverConf.setLong(FS_TRASH_INTERVAL_KEY, 0);
-
- MiniDFSCluster cluster2 = null;
- try {
- cluster2 = new MiniDFSCluster.Builder(serverConf).numDataNodes(1).build();
-
- // Client side is disabled by default
- FileSystem fs = cluster2.getFileSystem();
- assertFalse(new Trash(fs, clientConf).isEnabled());
-
- // Enabling on the client works even though its disabled on the server
- clientConf.setLong(FS_TRASH_INTERVAL_KEY, 1);
- assertTrue(new Trash(fs, clientConf).isEnabled());
- } finally {
- if (cluster2 != null) cluster2.shutdown();
- }
- }
}