Author: cos
Date: Wed Dec 16 03:30:51 2009
New Revision: 891109
URL: http://svn.apache.org/viewvc?rev=891109&view=rev
Log:
HDFS-832. HDFS side of HADOOP-6222. Contributed by Konstantin Boudnik.
Added:
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/CmdFactoryDFS.java
Modified:
hadoop/hdfs/trunk/CHANGES.txt
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/TestHDFSCLI.java
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java
Modified: hadoop/hdfs/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=891109&r1=891108&r2=891109&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Wed Dec 16 03:30:51 2009
@@ -36,6 +36,8 @@
HDFS-804. New unit tests for concurrent lease recovery (cos)
+ HDFS-832. HDFS side of HADOOP-6222. (cos)
+
OPTIMIZATIONS
BUG FIXES
Added: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/CmdFactoryDFS.java
URL:
http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/CmdFactoryDFS.java?rev=891109&view=auto
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/CmdFactoryDFS.java
(added)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/CmdFactoryDFS.java
Wed Dec 16 03:30:51 2009
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.cli;
+
+import org.apache.hadoop.cli.util.CLICommands;
+import org.apache.hadoop.cli.util.CLITestData;
+import org.apache.hadoop.cli.util.CmdFactory;
+import org.apache.hadoop.cli.util.CommandExecutor;
+import org.apache.hadoop.hdfs.tools.DFSAdmin;
+
+public abstract class CmdFactoryDFS extends CmdFactory {
+ public static CommandExecutor getCommandExecutor(CLITestData.TestCmd cmd,
+ String tag)
+ throws IllegalArgumentException {
+ CommandExecutor executor;
+ switch (cmd.getType()) {
+ case DFSADMIN:
+ executor = new CLICommands.FSCmdExecutor(tag, new DFSAdmin());
+ break;
+ default:
+ executor = CmdFactory.getCommandExecutor(cmd, tag);
+ }
+ return executor;
+ }
+}
Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/TestHDFSCLI.java
URL:
http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/TestHDFSCLI.java?rev=891109&r1=891108&r2=891109&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/TestHDFSCLI.java
(original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/TestHDFSCLI.java Wed
Dec 16 03:30:51 2009
@@ -18,27 +18,27 @@
package org.apache.hadoop.cli;
-import org.apache.hadoop.cli.util.CommandExecutor;
import org.apache.hadoop.cli.util.CLITestData.TestCmd;
import org.apache.hadoop.cli.util.CommandExecutor.Result;
import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.HDFSPolicyProvider;
import org.apache.hadoop.hdfs.MiniDFSCluster;
-import org.apache.hadoop.hdfs.tools.DFSAdmin;
import org.apache.hadoop.security.authorize.PolicyProvider;
-import org.apache.hadoop.util.ToolRunner;
+import org.junit.After;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
-public class TestHDFSCLI extends TestCLI{
+public class TestHDFSCLI extends CLITestHelper {
protected MiniDFSCluster dfsCluster = null;
protected DistributedFileSystem dfs = null;
protected String namenode = null;
- protected DFSAdminCmdExecutor dfsAdmCmdExecutor = null;
- protected FSCmdExecutor fsCmdExecutor = null;
+ @Before
+ @Override
public void setUp() throws Exception {
super.setUp();
conf.setClass(PolicyProvider.POLICY_PROVIDER_CONFIG,
@@ -57,8 +57,6 @@
namenode = conf.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "file:///");
username = System.getProperty("user.name");
- dfsAdmCmdExecutor = new DFSAdminCmdExecutor(namenode);
- fsCmdExecutor = new FSCmdExecutor(namenode);
FileSystem fs = dfsCluster.getFileSystem();
assertTrue("Not a HDFS: "+fs.getUri(),
@@ -66,10 +64,13 @@
dfs = (DistributedFileSystem) fs;
}
+ @Override
protected String getTestFile() {
return "testHDFSConf.xml";
}
+ @After
+ @Override
public void tearDown() throws Exception {
dfs.close();
dfsCluster.shutdown();
@@ -77,6 +78,7 @@
super.tearDown();
}
+ @Override
protected String expandCommand(final String cmd) {
String expCmd = cmd;
expCmd = expCmd.replaceAll("NAMENODE", namenode);
@@ -84,43 +86,14 @@
return expCmd;
}
+ @Override
protected Result execute(TestCmd cmd) throws Exception {
- CommandExecutor executor = null;
- switch(cmd.getType()) {
- case DFSADMIN:
- executor = dfsAdmCmdExecutor;
- break;
- case FS:
- executor = fsCmdExecutor;
- break;
- default:
- throw new Exception("Unknow type of Test command:"+ cmd.getType());
- }
- return executor.executeCommand(cmd.getCmd());
+ return CmdFactoryDFS.getCommandExecutor(cmd,
namenode).executeCommand(cmd.getCmd());
}
-
- public static class DFSAdminCmdExecutor extends CommandExecutor {
- private String namenode = null;
- public DFSAdminCmdExecutor(String namenode) {
- this.namenode = namenode;
- }
-
- protected void execute(final String cmd) throws Exception{
- DFSAdmin shell = new DFSAdmin();
- String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
- ToolRunner.run(shell, args);
- }
- }
-
- public static class FSCmdExecutor extends CommandExecutor {
- private String namenode = null;
- public FSCmdExecutor(String namenode) {
- this.namenode = namenode;
- }
- protected void execute(final String cmd) throws Exception{
- FsShell shell = new FsShell();
- String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
- ToolRunner.run(shell, args);
- }
+
+ @Test
+ @Override
+ public void testAll () {
+ super.testAll();
}
}
Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
URL:
http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml?rev=891109&r1=891108&r2=891109&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml
(original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/cli/testHDFSConf.xml Wed
Dec 16 03:30:51 2009
@@ -16688,7 +16688,7 @@
<!-- No cleanup -->
</cleanup-commands>
<comparators>
- <!-- miniDFS cluster started in TestCLI is set to match this output -->
+ <!-- miniDFS cluster started in CLITestHelper is set to match this
output -->
<comparator>
<type>RegexpAcrossOutputComparator</type>
<expected-output>^Rack:
\/rack1\s*127\.0\.0\.1:\d+\s\(localhost.*\)\s*127\.0\.0\.1:\d+\s\(localhost.*\)</expected-output>
Modified:
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java
URL:
http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java?rev=891109&r1=891108&r2=891109&view=diff
==============================================================================
---
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java
(original)
+++
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java
Wed Dec 16 03:30:51 2009
@@ -33,7 +33,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.cli.TestHDFSCLI;
+import org.apache.hadoop.cli.CmdFactoryDFS;
+import org.apache.hadoop.cli.util.CLITestData;
import org.apache.hadoop.cli.util.CommandExecutor;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
@@ -132,8 +133,8 @@
Iterator<StorageDirectory> it = fi.dirIterator();
while(it.hasNext()) {
StorageDirectory sd = it.next();
- if(sd.getRoot().getCanonicalPath().equals(path2.getCanonicalPath()) ||
- sd.getRoot().getCanonicalPath().equals(path3.getCanonicalPath())) {
+ if(sd.getRoot().getAbsolutePath().equals(path2.getAbsolutePath()) ||
+ sd.getRoot().getAbsolutePath().equals(path3.getAbsolutePath())) {
al.add(sd);
}
}
@@ -351,25 +352,25 @@
String cmd = "-fs NAMENODE -restoreFailedStorage false";
String namenode = config.get(DFSConfigKeys.FS_DEFAULT_NAME_KEY,
"file:///");
- CommandExecutor executor = new TestHDFSCLI.DFSAdminCmdExecutor(namenode);
+ CommandExecutor executor =
+ CmdFactoryDFS.getCommandExecutor(
+ new CLITestData.TestCmd(cmd,
CLITestData.TestCmd.CommandType.DFSADMIN),
+ namenode);
executor.executeCommand(cmd);
restore = fsi.getRestoreFailedStorage();
- LOG.info("After set true call restore is " + restore);
- assertEquals(restore, false);
+ assertFalse("After set true call restore is " + restore, restore);
// run one more time - to set it to true again
cmd = "-fs NAMENODE -restoreFailedStorage true";
executor.executeCommand(cmd);
restore = fsi.getRestoreFailedStorage();
- LOG.info("After set false call restore is " + restore);
- assertEquals(restore, true);
+ assertTrue("After set false call restore is " + restore, restore);
// run one more time - no change in value
cmd = "-fs NAMENODE -restoreFailedStorage check";
CommandExecutor.Result cmdResult = executor.executeCommand(cmd);
restore = fsi.getRestoreFailedStorage();
- LOG.info("After check call restore is " + restore);
- assertEquals(restore, true);
+ assertTrue("After check call restore is " + restore, restore);
String commandOutput = cmdResult.getCommandOutput();
commandOutput.trim();
assertTrue(commandOutput.contains("restoreFailedStorage is set to
true"));