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 wa...@apache.org on 2013/09/20 01:42:22 UTC
svn commit: r1524865 [5/5] - in
/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project: hadoop-hdfs-nfs/
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/mount/
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/
hadoop-hdfs-nfs/src/t...
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameEditsConfigs.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameEditsConfigs.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameEditsConfigs.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameEditsConfigs.java Thu Sep 19 23:42:10 2013
@@ -37,6 +37,7 @@ import org.apache.hadoop.hdfs.DFSTestUti
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Before;
import org.junit.Test;
@@ -60,7 +61,7 @@ public class TestNameEditsConfigs {
short replication = 3;
private File base_dir = new File(
- System.getProperty("test.build.data", "build/test/data"), "dfs/");
+ PathUtils.getTestDir(TestNameEditsConfigs.class), "dfs");
@Before
public void setUp() throws IOException {
@@ -68,7 +69,7 @@ public class TestNameEditsConfigs {
throw new IOException("Cannot remove directory " + base_dir);
}
}
-
+
void checkImageAndEditsFilesExistence(File dir,
boolean shouldHaveImages,
boolean shouldHaveEdits)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java Thu Sep 19 23:42:10 2013
@@ -120,6 +120,11 @@ public class TestNameNodeMXBean {
String nameJournalStatus = (String) (mbs.getAttribute(mxbeanName,
"NameJournalStatus"));
assertEquals("Bad value for NameJournalStatus", fsn.getNameJournalStatus(), nameJournalStatus);
+ // get attribute JournalTransactionInfo
+ String journalTxnInfo = (String) mbs.getAttribute(mxbeanName,
+ "JournalTransactionInfo");
+ assertEquals("Bad value for NameTxnIds", fsn.getJournalTransactionInfo(),
+ journalTxnInfo);
// get attribute "NNStarted"
String nnStarted = (String) mbs.getAttribute(mxbeanName, "NNStarted");
assertEquals("Bad value for NNStarted", fsn.getNNStarted(), nnStarted);
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java Thu Sep 19 23:42:10 2013
@@ -46,6 +46,7 @@ import org.apache.hadoop.hdfs.server.nam
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.OpInstanceCache;
import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType;
import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
@@ -57,8 +58,7 @@ import com.google.common.collect.Sets;
public class TestNameNodeRecovery {
private static final Log LOG = LogFactory.getLog(TestNameNodeRecovery.class);
private static StartupOption recoverStartOpt = StartupOption.RECOVER;
- private static final File TEST_DIR = new File(
- System.getProperty("test.build.data","build/test/data"));
+ private static final File TEST_DIR = PathUtils.getTestDir(TestNameNodeRecovery.class);
static {
recoverStartOpt.setForce(MetaRecoveryContext.FORCE_ALL);
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeResourceChecker.java Thu Sep 19 23:42:10 2013
@@ -33,12 +33,14 @@ import org.apache.hadoop.hdfs.DFSConfigK
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem.NameNodeResourceMonitor;
import org.apache.hadoop.hdfs.server.namenode.NameNodeResourceChecker.CheckedVolume;
+import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.Time;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
public class TestNameNodeResourceChecker {
+ private final static File BASE_DIR = PathUtils.getTestDir(TestNameNodeResourceChecker.class);
private Configuration conf;
private File baseDir;
private File nameDir;
@@ -46,8 +48,7 @@ public class TestNameNodeResourceChecker
@Before
public void setUp () throws IOException {
conf = new Configuration();
- baseDir = new File(System.getProperty("test.build.data"));
- nameDir = new File(baseDir, "resource-check-name-dir");
+ nameDir = new File(BASE_DIR, "resource-check-name-dir");
nameDir.mkdirs();
conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, nameDir.getAbsolutePath());
}
@@ -141,8 +142,8 @@ public class TestNameNodeResourceChecker
@Test
public void testChecking2NameDirsOnOneVolume() throws IOException {
Configuration conf = new Configuration();
- File nameDir1 = new File(System.getProperty("test.build.data"), "name-dir1");
- File nameDir2 = new File(System.getProperty("test.build.data"), "name-dir2");
+ File nameDir1 = new File(BASE_DIR, "name-dir1");
+ File nameDir2 = new File(BASE_DIR, "name-dir2");
nameDir1.mkdirs();
nameDir2.mkdirs();
conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY,
@@ -162,7 +163,7 @@ public class TestNameNodeResourceChecker
@Test
public void testCheckingExtraVolumes() throws IOException {
Configuration conf = new Configuration();
- File nameDir = new File(System.getProperty("test.build.data"), "name-dir");
+ File nameDir = new File(BASE_DIR, "name-dir");
nameDir.mkdirs();
conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, nameDir.getAbsolutePath());
conf.set(DFSConfigKeys.DFS_NAMENODE_CHECKED_VOLUMES_KEY, nameDir.getAbsolutePath());
@@ -182,8 +183,8 @@ public class TestNameNodeResourceChecker
@Test
public void testLowResourceVolumePolicy() throws IOException, URISyntaxException {
Configuration conf = new Configuration();
- File nameDir1 = new File(System.getProperty("test.build.data"), "name-dir1");
- File nameDir2 = new File(System.getProperty("test.build.data"), "name-dir2");
+ File nameDir1 = new File(BASE_DIR, "name-dir1");
+ File nameDir2 = new File(BASE_DIR, "name-dir2");
nameDir1.mkdirs();
nameDir2.mkdirs();
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNamenodeRetryCache.java Thu Sep 19 23:42:10 2013
@@ -96,7 +96,7 @@ public class TestNamenodeRetryCache {
* @throws AccessControlException */
@After
public void cleanup() throws IOException {
- namesystem.delete("/", true);
+ cluster.shutdown();
}
public static void incrementCallId() {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java Thu Sep 19 23:42:10 2013
@@ -57,6 +57,7 @@ import org.apache.hadoop.hdfs.server.pro
import org.apache.hadoop.hdfs.util.MD5FileUtils;
import org.apache.hadoop.io.MD5Hash;
import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.StringUtils;
import org.apache.log4j.Logger;
import org.junit.After;
@@ -404,8 +405,7 @@ public class TestStartup {
Configuration conf = new Configuration();
FileSystem.setDefaultUri(conf, "hdfs://localhost:0");
conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:0");
- File base_dir = new File(System.getProperty(
- "test.build.data", "build/test/data"), "dfs/");
+ File base_dir = new File(PathUtils.getTestDir(getClass()), "dfs/");
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
new File(base_dir, "name").getPath());
conf.setBoolean(DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, false);
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStorageRestore.java Thu Sep 19 23:42:10 2013
@@ -391,7 +391,8 @@ public class TestStorageRestore {
(new File(path3, "current").getAbsolutePath()) : path3.toString();
try {
- cluster = new MiniDFSCluster.Builder(config).numDataNodes(0)
+ cluster = new MiniDFSCluster.Builder(config)
+ .numDataNodes(0)
.manageNameDfsDirs(false).build();
cluster.waitActive();
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestTransferFsImage.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestTransferFsImage.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestTransferFsImage.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestTransferFsImage.java Thu Sep 19 23:42:10 2013
@@ -39,6 +39,7 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.hadoop.http.HttpServer;
import org.apache.hadoop.http.HttpServerFunctionalTest;
import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
import org.mockito.Mockito;
@@ -48,8 +49,7 @@ import com.google.common.collect.Immutab
public class TestTransferFsImage {
- private static final File TEST_DIR = new File(
- System.getProperty("test.build.data","build/test/data"));
+ private static final File TEST_DIR = PathUtils.getTestDir(TestTransferFsImage.class);
/**
* Regression test for HDFS-1997. Test that, if an exception
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestBootstrapStandby.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestBootstrapStandby.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestBootstrapStandby.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestBootstrapStandby.java Thu Sep 19 23:42:10 2013
@@ -24,8 +24,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.net.URI;
-import java.util.List;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,8 +43,6 @@ import org.junit.Before;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
public class TestBootstrapStandby {
private static final Log LOG = LogFactory.getLog(TestBootstrapStandby.class);
@@ -60,8 +56,8 @@ public class TestBootstrapStandby {
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ns1")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(20001))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(20002)));
cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
@@ -107,7 +103,7 @@ public class TestBootstrapStandby {
// Should have copied over the namespace from the active
FSImageTestUtil.assertNNHasCheckpoints(cluster, 1,
ImmutableList.of(0));
- assertNNFilesMatch();
+ FSImageTestUtil.assertNNFilesMatch(cluster);
// We should now be able to start the standby successfully.
cluster.restartNameNode(1);
@@ -138,7 +134,7 @@ public class TestBootstrapStandby {
// Should have copied over the namespace from the active
FSImageTestUtil.assertNNHasCheckpoints(cluster, 1,
ImmutableList.of((int)expectedCheckpointTxId));
- assertNNFilesMatch();
+ FSImageTestUtil.assertNNFilesMatch(cluster);
// We should now be able to start the standby successfully.
cluster.restartNameNode(1);
@@ -208,18 +204,6 @@ public class TestBootstrapStandby {
cluster.getConfiguration(1));
assertEquals(0, rc);
}
-
- private void assertNNFilesMatch() throws Exception {
- List<File> curDirs = Lists.newArrayList();
- curDirs.addAll(FSImageTestUtil.getNameNodeCurrentDirs(cluster, 0));
- curDirs.addAll(FSImageTestUtil.getNameNodeCurrentDirs(cluster, 1));
-
- // Ignore seen_txid file, since the newly bootstrapped standby
- // will have a higher seen_txid than the one it bootstrapped from.
- Set<String> ignoredFiles = ImmutableSet.of("seen_txid");
- FSImageTestUtil.assertParallelFilesAreIdentical(curDirs,
- ignoredFiles);
- }
private void removeStandbyNameDirs() {
for (URI u : cluster.getNameDirs(1)) {
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestDFSZKFailoverController.java Thu Sep 19 23:42:10 2013
@@ -70,13 +70,13 @@ public class TestDFSZKFailoverController
CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY,
0);
- conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1", 10003);
- conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2", 10004);
+ conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn1", 10023);
+ conf.setInt(DFSConfigKeys.DFS_HA_ZKFC_PORT_KEY + ".ns1.nn2", 10024);
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ns1")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(10021))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(10022)));
cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
.numDataNodes(0)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestEditLogTailer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestEditLogTailer.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestEditLogTailer.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestEditLogTailer.java Thu Sep 19 23:42:10 2013
@@ -124,8 +124,8 @@ public class TestEditLogTailer {
// Have to specify IPC ports so the NNs can talk to each other.
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ns1")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(10031))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(10032)));
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestFailureToReadEdits.java Thu Sep 19 23:42:10 2013
@@ -76,8 +76,8 @@ public class TestFailureToReadEdits {
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ns1")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10041))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10042)));
cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
.numDataNodes(0)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAFsck.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAFsck.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAFsck.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHAFsck.java Thu Sep 19 23:42:10 2013
@@ -52,8 +52,8 @@ public class TestHAFsck {
// need some HTTP ports
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ha-nn-uri-0")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10051))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10052)));
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java Thu Sep 19 23:42:10 2013
@@ -26,15 +26,22 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URI;
import java.net.UnknownHostException;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CreateFlag;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil;
@@ -43,9 +50,20 @@ import org.apache.hadoop.hdfs.HdfsConfig
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.MiniDFSNNTopology;
import org.apache.hadoop.hdfs.NameNodeProxies;
+import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;
+import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag;
import org.apache.hadoop.hdfs.protocol.ClientProtocol;
-import org.apache.hadoop.hdfs.protocol.HdfsConstants;
+import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
+import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
+import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
+import org.apache.hadoop.hdfs.protocol.LocatedBlock;
+import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
+import org.apache.hadoop.hdfs.server.namenode.INodeFile;
+import org.apache.hadoop.hdfs.server.namenode.INodeFileUnderConstruction;
+import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
+import org.apache.hadoop.io.EnumSetWritable;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.retry.FailoverProxyProvider;
import org.apache.hadoop.io.retry.RetryInvocationHandler;
@@ -60,14 +78,13 @@ import org.junit.Test;
public class TestRetryCacheWithHA {
private static final Log LOG = LogFactory.getLog(TestRetryCacheWithHA.class);
- private static MiniDFSCluster cluster;
- private static DistributedFileSystem dfs;
- private static Configuration conf = new HdfsConfiguration();
-
private static final int BlockSize = 1024;
private static final short DataNodes = 3;
- private final static Map<String, Object> results =
- new HashMap<String, Object>();
+ private static final int CHECKTIMES = 10;
+
+ private MiniDFSCluster cluster;
+ private DistributedFileSystem dfs;
+ private Configuration conf = new HdfsConfiguration();
/**
* A dummy invocation handler extending RetryInvocationHandler. We can use
@@ -120,7 +137,7 @@ public class TestRetryCacheWithHA {
* 2. Trigger the NN failover
* 3. Check the retry cache on the original standby NN
*/
- @Test
+ @Test (timeout=60000)
public void testRetryCacheOnStandbyNN() throws Exception {
// 1. run operations
DFSTestUtil.runOperations(cluster, dfs, conf, BlockSize, 0);
@@ -180,26 +197,624 @@ public class TestRetryCacheWithHA {
return client;
}
+ abstract class AtMostOnceOp {
+ private final String name;
+ final DFSClient client;
+
+ AtMostOnceOp(String name, DFSClient client) {
+ this.name = name;
+ this.client = client;
+ }
+
+ abstract void prepare() throws Exception;
+ abstract void invoke() throws Exception;
+ abstract boolean checkNamenodeBeforeReturn() throws Exception;
+ abstract Object getResult();
+ }
+
+ /** createSnapshot operaiton */
+ class CreateSnapshotOp extends AtMostOnceOp {
+ private String snapshotPath;
+ private String dir;
+ private String snapshotName;
+
+ CreateSnapshotOp(DFSClient client, String dir, String snapshotName) {
+ super("createSnapshot", client);
+ this.dir = dir;
+ this.snapshotName = snapshotName;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path dirPath = new Path(dir);
+ if (!dfs.exists(dirPath)) {
+ dfs.mkdirs(dirPath);
+ dfs.allowSnapshot(dirPath);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ this.snapshotPath = client.createSnapshot(dir, snapshotName);
+ }
+
+ @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
+ Object getResult() {
+ return snapshotPath;
+ }
+ }
+
+ /** deleteSnapshot */
+ class DeleteSnapshotOp extends AtMostOnceOp {
+ private String dir;
+ private String snapshotName;
+
+ DeleteSnapshotOp(DFSClient client, String dir, String snapshotName) {
+ super("deleteSnapshot", client);
+ this.dir = dir;
+ this.snapshotName = snapshotName;
+ }
+
+ @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
+ void invoke() throws Exception {
+ client.deleteSnapshot(dir, 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
+ Object getResult() {
+ return null;
+ }
+ }
+
+ /** renameSnapshot */
+ class RenameSnapshotOp extends AtMostOnceOp {
+ private String dir;
+ private String oldName;
+ private String newName;
+
+ RenameSnapshotOp(DFSClient client, String dir, String oldName,
+ String newName) {
+ super("renameSnapshot", client);
+ this.dir = dir;
+ this.oldName = oldName;
+ this.newName = newName;
+ }
+
+ @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
+ void invoke() throws Exception {
+ client.renameSnapshot(dir, oldName, newName);
+ }
+
+ @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
+ Object getResult() {
+ return null;
+ }
+ }
+
+ /** create file operation (without OverWrite) */
+ class CreateOp extends AtMostOnceOp {
+ private String fileName;
+ private HdfsFileStatus status;
+
+ CreateOp(DFSClient client, String fileName) {
+ super("create", client);
+ this.fileName = fileName;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path filePath = new Path(fileName);
+ if (dfs.exists(filePath)) {
+ dfs.delete(filePath, true);
+ }
+ final Path fileParent = filePath.getParent();
+ if (!dfs.exists(fileParent)) {
+ dfs.mkdirs(fileParent);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ EnumSet<CreateFlag> createFlag = EnumSet.of(CreateFlag.CREATE);
+ this.status = client.getNamenode().create(fileName,
+ FsPermission.getFileDefault(), client.getClientName(),
+ new EnumSetWritable<CreateFlag>(createFlag), false, DataNodes,
+ BlockSize);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ final Path filePath = new Path(fileName);
+ boolean fileCreated = dfs.exists(filePath);
+ for (int i = 0; i < CHECKTIMES && !fileCreated; i++) {
+ Thread.sleep(1000);
+ fileCreated = dfs.exists(filePath);
+ }
+ return fileCreated;
+ }
+
+ @Override
+ Object getResult() {
+ return status;
+ }
+ }
+
+ /** append operation */
+ class AppendOp extends AtMostOnceOp {
+ private String fileName;
+ private LocatedBlock lbk;
+
+ AppendOp(DFSClient client, String fileName) {
+ super("append", client);
+ this.fileName = fileName;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path filePath = new Path(fileName);
+ if (!dfs.exists(filePath)) {
+ DFSTestUtil.createFile(dfs, filePath, BlockSize / 2, DataNodes, 0);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ lbk = client.getNamenode().append(fileName, client.getClientName());
+ }
+
+ // check if the inode of the file is under construction
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ INodeFile fileNode = cluster.getNameNode(0).getNamesystem()
+ .getFSDirectory().getINode4Write(fileName).asFile();
+ boolean fileIsUC = fileNode.isUnderConstruction();
+ for (int i = 0; i < CHECKTIMES && !fileIsUC; i++) {
+ Thread.sleep(1000);
+ fileNode = cluster.getNameNode(0).getNamesystem().getFSDirectory()
+ .getINode4Write(fileName).asFile();
+ fileIsUC = fileNode.isUnderConstruction();
+ }
+ return fileIsUC;
+ }
+
+ @Override
+ Object getResult() {
+ return lbk;
+ }
+ }
+
+ /** rename */
+ class RenameOp extends AtMostOnceOp {
+ private String oldName;
+ private String newName;
+ private boolean renamed;
+
+ RenameOp(DFSClient client, String oldName, String newName) {
+ super("rename", client);
+ this.oldName = oldName;
+ this.newName = newName;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path filePath = new Path(oldName);
+ if (!dfs.exists(filePath)) {
+ DFSTestUtil.createFile(dfs, filePath, BlockSize, DataNodes, 0);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ void invoke() throws Exception {
+ this.renamed = client.rename(oldName, newName);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ Path targetPath = new Path(newName);
+ boolean renamed = dfs.exists(targetPath);
+ for (int i = 0; i < CHECKTIMES && !renamed; i++) {
+ Thread.sleep(1000);
+ renamed = dfs.exists(targetPath);
+ }
+ return renamed;
+ }
+
+ @Override
+ Object getResult() {
+ return new Boolean(renamed);
+ }
+ }
+
+ /** rename2 */
+ class Rename2Op extends AtMostOnceOp {
+ private String oldName;
+ private String newName;
+
+ Rename2Op(DFSClient client, String oldName, String newName) {
+ super("rename2", client);
+ this.oldName = oldName;
+ this.newName = newName;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path filePath = new Path(oldName);
+ if (!dfs.exists(filePath)) {
+ DFSTestUtil.createFile(dfs, filePath, BlockSize, DataNodes, 0);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ client.rename(oldName, newName, Rename.OVERWRITE);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ Path targetPath = new Path(newName);
+ boolean renamed = dfs.exists(targetPath);
+ for (int i = 0; i < CHECKTIMES && !renamed; i++) {
+ Thread.sleep(1000);
+ renamed = dfs.exists(targetPath);
+ }
+ return renamed;
+ }
+
+ @Override
+ Object getResult() {
+ return null;
+ }
+ }
+
+ /** concat */
+ class ConcatOp extends AtMostOnceOp {
+ private String target;
+ private String[] srcs;
+ private Path[] srcPaths;
+
+ ConcatOp(DFSClient client, Path target, int numSrc) {
+ super("concat", client);
+ this.target = target.toString();
+ this.srcs = new String[numSrc];
+ this.srcPaths = new Path[numSrc];
+ Path parent = target.getParent();
+ for (int i = 0; i < numSrc; i++) {
+ srcPaths[i] = new Path(parent, "srcfile" + i);
+ srcs[i] = srcPaths[i].toString();
+ }
+ }
+
+ @Override
+ void prepare() throws Exception {
+ DFSTestUtil.createFile(dfs, new Path(target), BlockSize, DataNodes, 0);
+ for (int i = 0; i < srcPaths.length; i++) {
+ DFSTestUtil.createFile(dfs, srcPaths[i], BlockSize, DataNodes, 0);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ client.concat(target, srcs);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ Path targetPath = new Path(target);
+ boolean done = dfs.exists(targetPath);
+ for (int i = 0; i < CHECKTIMES && !done; i++) {
+ Thread.sleep(1000);
+ done = dfs.exists(targetPath);
+ }
+ return done;
+ }
+
+ @Override
+ Object getResult() {
+ return null;
+ }
+ }
+
+ /** delete */
+ class DeleteOp extends AtMostOnceOp {
+ private String target;
+ private boolean deleted;
+
+ DeleteOp(DFSClient client, String target) {
+ super("delete", client);
+ this.target = target;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ Path p = new Path(target);
+ if (!dfs.exists(p)) {
+ DFSTestUtil.createFile(dfs, p, BlockSize, DataNodes, 0);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ deleted = client.delete(target, true);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ Path targetPath = new Path(target);
+ boolean del = !dfs.exists(targetPath);
+ for (int i = 0; i < CHECKTIMES && !del; i++) {
+ Thread.sleep(1000);
+ del = !dfs.exists(targetPath);
+ }
+ return del;
+ }
+
+ @Override
+ Object getResult() {
+ return new Boolean(deleted);
+ }
+ }
+
+ /** createSymlink */
+ class CreateSymlinkOp extends AtMostOnceOp {
+ private String target;
+ private String link;
+
+ public CreateSymlinkOp(DFSClient client, String target, String link) {
+ super("createSymlink", client);
+ this.target = target;
+ this.link = link;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ Path p = new Path(target);
+ if (!dfs.exists(p)) {
+ DFSTestUtil.createFile(dfs, p, BlockSize, DataNodes, 0);
+ }
+ }
+
+ @Override
+ void invoke() throws Exception {
+ client.createSymlink(target, link, false);
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ Path linkPath = new Path(link);
+ FileStatus linkStatus = dfs.getFileLinkStatus(linkPath);
+ for (int i = 0; i < CHECKTIMES && linkStatus == null; i++) {
+ Thread.sleep(1000);
+ linkStatus = dfs.getFileLinkStatus(linkPath);
+ }
+ return linkStatus != null;
+ }
+
+ @Override
+ Object getResult() {
+ return null;
+ }
+ }
+
+ /** updatePipeline */
+ class UpdatePipelineOp extends AtMostOnceOp {
+ private String file;
+ private ExtendedBlock oldBlock;
+ private ExtendedBlock newBlock;
+ private DatanodeInfo[] nodes;
+ private FSDataOutputStream out;
+
+ public UpdatePipelineOp(DFSClient client, String file) {
+ super("updatePipeline", client);
+ this.file = file;
+ }
+
+ @Override
+ void prepare() throws Exception {
+ final Path filePath = new Path(file);
+ DFSTestUtil.createFile(dfs, filePath, BlockSize, DataNodes, 0);
+ // append to the file and leave the last block under construction
+ out = this.client.append(file, BlockSize, null, null);
+ byte[] appendContent = new byte[100];
+ new Random().nextBytes(appendContent);
+ out.write(appendContent);
+ ((HdfsDataOutputStream) out).hsync(EnumSet.of(SyncFlag.UPDATE_LENGTH));
+
+ LocatedBlocks blks = dfs.getClient()
+ .getLocatedBlocks(file, BlockSize + 1);
+ assertEquals(1, blks.getLocatedBlocks().size());
+ nodes = blks.get(0).getLocations();
+ oldBlock = blks.get(0).getBlock();
+
+ LocatedBlock newLbk = client.getNamenode().updateBlockForPipeline(
+ oldBlock, client.getClientName());
+ newBlock = new ExtendedBlock(oldBlock.getBlockPoolId(),
+ oldBlock.getBlockId(), oldBlock.getNumBytes(),
+ newLbk.getBlock().getGenerationStamp());
+ }
+
+ @Override
+ void invoke() throws Exception {
+ DatanodeInfo[] newNodes = new DatanodeInfo[2];
+ newNodes[0] = nodes[0];
+ newNodes[1] = nodes[1];
+
+ client.getNamenode().updatePipeline(client.getClientName(), oldBlock,
+ newBlock, newNodes);
+ out.close();
+ }
+
+ @Override
+ boolean checkNamenodeBeforeReturn() throws Exception {
+ INodeFileUnderConstruction fileNode = (INodeFileUnderConstruction) cluster
+ .getNamesystem(0).getFSDirectory().getINode4Write(file).asFile();
+ BlockInfoUnderConstruction blkUC =
+ (BlockInfoUnderConstruction) (fileNode.getBlocks())[1];
+ int datanodeNum = blkUC.getExpectedLocations().length;
+ for (int i = 0; i < CHECKTIMES && datanodeNum != 2; i++) {
+ Thread.sleep(1000);
+ datanodeNum = blkUC.getExpectedLocations().length;
+ }
+ return datanodeNum == 2;
+ }
+
+ @Override
+ Object getResult() {
+ return null;
+ }
+ }
+
+ @Test (timeout=60000)
+ public void testCreateSnapshot() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new CreateSnapshotOp(client, "/test", "s1");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testDeleteSnapshot() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new DeleteSnapshotOp(client, "/test", "s1");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testRenameSnapshot() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new RenameSnapshotOp(client, "/test", "s1", "s2");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testCreate() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new CreateOp(client, "/testfile");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testAppend() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new AppendOp(client, "/testfile");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testRename() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new RenameOp(client, "/file1", "/file2");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testRename2() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new Rename2Op(client, "/file1", "/file2");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testConcat() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new ConcatOp(client, new Path("/test/file"), 5);
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testDelete() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new DeleteOp(client, "/testfile");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testCreateSymlink() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new CreateSymlinkOp(client, "/testfile", "/testlink");
+ testClientRetryWithFailover(op);
+ }
+
+ @Test (timeout=60000)
+ public void testUpdatePipeline() throws Exception {
+ final DFSClient client = genClientWithDummyHandler();
+ AtMostOnceOp op = new UpdatePipelineOp(client, "/testfile");
+ testClientRetryWithFailover(op);
+ }
+
/**
* When NN failover happens, if the client did not receive the response and
* send a retry request to the other NN, the same response should be recieved
* based on the retry cache.
- *
- * TODO: currently we only test the createSnapshot from the client side. We
- * may need to cover all the calls with "@AtMostOnce" annotation.
*/
- @Test
- public void testClientRetryWithFailover() throws Exception {
- final String dir = "/test";
- final Path dirPath = new Path(dir);
- final String sName = "s1";
- final String dirSnapshot = dir + HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR
- + Path.SEPARATOR + sName;
+ public void testClientRetryWithFailover(final AtMostOnceOp op)
+ throws Exception {
+ final Map<String, Object> results = new HashMap<String, Object>();
- dfs.mkdirs(dirPath);
- dfs.allowSnapshot(dirPath);
-
- final DFSClient client = genClientWithDummyHandler();
+ op.prepare();
// set DummyRetryInvocationHandler#block to true
DummyRetryInvocationHandler.block.set(true);
@@ -207,28 +822,25 @@ public class TestRetryCacheWithHA {
@Override
public void run() {
try {
- final String snapshotPath = client.createSnapshot(dir, "s1");
- assertEquals(dirSnapshot, snapshotPath);
- LOG.info("Created snapshot " + snapshotPath);
+ op.invoke();
+ Object result = op.getResult();
+ LOG.info("Operation " + op.name + " finished");
synchronized (TestRetryCacheWithHA.this) {
- results.put("createSnapshot", snapshotPath);
+ results.put(op.name, result == null ? "SUCCESS" : result);
TestRetryCacheWithHA.this.notifyAll();
}
- } catch (IOException e) {
- LOG.info("Got IOException " + e + " while creating snapshot");
+ } catch (Exception e) {
+ LOG.info("Got Exception while calling " + op.name, e);
} finally {
- IOUtils.cleanup(null, client);
+ IOUtils.cleanup(null, op.client);
}
}
}.start();
- // make sure the client's createSnapshot call has actually been handled by
- // the active NN
- boolean snapshotCreated = dfs.exists(new Path(dirSnapshot));
- while (!snapshotCreated) {
- Thread.sleep(1000);
- snapshotCreated = dfs.exists(new Path(dirSnapshot));
- }
+ // make sure the client's call has actually been handled by the active NN
+ assertTrue("After waiting the operation " + op.name
+ + " still has not taken effect on NN yet",
+ op.checkNamenodeBeforeReturn());
// force the failover
cluster.transitionToStandby(0);
@@ -238,11 +850,11 @@ public class TestRetryCacheWithHA {
DummyRetryInvocationHandler.block.set(false);
synchronized (this) {
- while (!results.containsKey("createSnapshot")) {
+ while (!results.containsKey(op.name)) {
this.wait();
}
- LOG.info("Got the result of createSnapshot: "
- + results.get("createSnapshot"));
+ LOG.info("Got the result of " + op.name + ": "
+ + results.get(op.name));
}
}
}
\ No newline at end of file
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestStandbyCheckpoints.java Thu Sep 19 23:42:10 2013
@@ -89,8 +89,8 @@ public class TestStandbyCheckpoints {
MiniDFSNNTopology topology = new MiniDFSNNTopology()
.addNameservice(new MiniDFSNNTopology.NSConf("ns1")
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10001))
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10002)));
+ .addNN(new MiniDFSNNTopology.NNConf("nn1").setHttpPort(10061))
+ .addNN(new MiniDFSNNTopology.NNConf("nn2").setHttpPort(10062)));
cluster = new MiniDFSCluster.Builder(conf)
.nnTopology(topology)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java Thu Sep 19 23:42:10 2013
@@ -44,6 +44,7 @@ import org.apache.hadoop.hdfs.DFSTestUti
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream;
+import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
@@ -54,6 +55,7 @@ import org.apache.hadoop.hdfs.server.nam
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper.TestDirectoryTree.Node;
import org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewer;
import org.apache.hadoop.hdfs.tools.offlineImageViewer.XmlImageVisitor;
+import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time;
import org.apache.log4j.Level;
@@ -342,6 +344,37 @@ public class TestSnapshot {
}
/**
+ * Test creating a snapshot with illegal name
+ */
+ @Test
+ public void testCreateSnapshotWithIllegalName() throws Exception {
+ final Path dir = new Path("/dir");
+ hdfs.mkdirs(dir);
+
+ final String name1 = HdfsConstants.DOT_SNAPSHOT_DIR;
+ try {
+ hdfs.createSnapshot(dir, name1);
+ fail("Exception expected when an illegal name is given");
+ } catch (RemoteException e) {
+ String errorMsg = "\"" + HdfsConstants.DOT_SNAPSHOT_DIR
+ + "\" is a reserved name.";
+ GenericTestUtils.assertExceptionContains(errorMsg, e);
+ }
+
+ String errorMsg = "Snapshot name cannot contain \"" + Path.SEPARATOR + "\"";
+ final String[] badNames = new String[] { "foo" + Path.SEPARATOR,
+ Path.SEPARATOR + "foo", Path.SEPARATOR, "foo" + Path.SEPARATOR + "bar" };
+ for (String badName : badNames) {
+ try {
+ hdfs.createSnapshot(dir, badName);
+ fail("Exception expected when an illegal name is given");
+ } catch (RemoteException e) {
+ GenericTestUtils.assertExceptionContains(errorMsg, e);
+ }
+ }
+ }
+
+ /**
* Creating snapshots for a directory that is not snapshottable must fail.
*/
@Test (timeout=60000)
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java Thu Sep 19 23:42:10 2013
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.server.na
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.List;
@@ -29,11 +30,14 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.SnapshotException;
import org.apache.hadoop.hdfs.server.namenode.FSDirectory;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.snapshot.INodeDirectoryWithSnapshot.DirectoryDiff;
import org.apache.hadoop.hdfs.util.ReadOnlyList;
+import org.apache.hadoop.ipc.RemoteException;
+import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -190,4 +194,36 @@ public class TestSnapshotRename {
exception.expectMessage(error);
hdfs.renameSnapshot(sub1, "s1", "s2");
}
+
+ /**
+ * Test renaming a snapshot with illegal name
+ */
+ @Test
+ public void testRenameWithIllegalName() throws Exception {
+ DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPLICATION, seed);
+ // Create snapshots for sub1
+ SnapshotTestHelper.createSnapshot(hdfs, sub1, "s1");
+
+ final String name1 = HdfsConstants.DOT_SNAPSHOT_DIR;
+ try {
+ hdfs.renameSnapshot(sub1, "s1", name1);
+ fail("Exception expected when an illegal name is given for rename");
+ } catch (RemoteException e) {
+ String errorMsg = "\"" + HdfsConstants.DOT_SNAPSHOT_DIR
+ + "\" is a reserved name.";
+ GenericTestUtils.assertExceptionContains(errorMsg, e);
+ }
+
+ String errorMsg = "Snapshot name cannot contain \"" + Path.SEPARATOR + "\"";
+ final String[] badNames = new String[] { "foo" + Path.SEPARATOR,
+ Path.SEPARATOR + "foo", Path.SEPARATOR, "foo" + Path.SEPARATOR + "bar" };
+ for (String badName : badNames) {
+ try {
+ hdfs.renameSnapshot(sub1, "s1", badName);
+ fail("Exception expected when an illegal name is given");
+ } catch (RemoteException e) {
+ GenericTestUtils.assertExceptionContains(errorMsg, e);
+ }
+ }
+ }
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java Thu Sep 19 23:42:10 2013
@@ -35,6 +35,7 @@ import org.apache.hadoop.hdfs.DFSTestUti
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes;
import org.apache.hadoop.hdfs.server.namenode.OfflineEditsViewerHelper;
import org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer.Flags;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Before;
import org.junit.Test;
@@ -53,7 +54,7 @@ public class TestOfflineEditsViewer {
}
private static String buildDir =
- System.getProperty("test.build.data", "build/test/data");
+ PathUtils.getTestDirName(TestOfflineEditsViewer.class);
private static String cacheDir =
System.getProperty("test.cache.data", "build/test/cache");
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestDelimitedImageVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestDelimitedImageVisitor.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestDelimitedImageVisitor.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestDelimitedImageVisitor.java Thu Sep 19 23:42:10 2013
@@ -27,6 +27,7 @@ import java.io.FileReader;
import java.io.IOException;
import org.apache.hadoop.hdfs.tools.offlineImageViewer.ImageVisitor.ImageElement;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Test;
/**
@@ -34,7 +35,7 @@ import org.junit.Test;
* on predetermined inputs
*/
public class TestDelimitedImageVisitor {
- private static String ROOT = System.getProperty("test.build.data","/tmp");
+ private static String ROOT = PathUtils.getTestDirName(TestDelimitedImageVisitor.class);
private static final String delim = "--";
// Record an element in the visitor and build the expected line in the output
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java Thu Sep 19 23:42:10 2013
@@ -53,6 +53,7 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.test.PathUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -88,8 +89,7 @@ public class TestOfflineImageViewer {
final static HashMap<String, FileStatus> writtenFiles =
new HashMap<String, FileStatus>();
- private static String ROOT = System.getProperty("test.build.data",
- "build/test/data");
+ private static String ROOT = PathUtils.getTestDirName(TestOfflineImageViewer.class);
// Create a populated namespace for later testing. Save its contents to a
// data structure and store its fsimage location.
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestAtomicFileOutputStream.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestAtomicFileOutputStream.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestAtomicFileOutputStream.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestAtomicFileOutputStream.java Thu Sep 19 23:42:10 2013
@@ -30,6 +30,7 @@ import java.io.OutputStream;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Before;
import org.junit.Test;
@@ -40,10 +41,7 @@ public class TestAtomicFileOutputStream
private static final String TEST_STRING = "hello world";
private static final String TEST_STRING_2 = "goodbye world";
- private static File BASE_DIR = new File(
- System.getProperty("test.build.data", "build/test/data"));
- private static File TEST_DIR = new File(BASE_DIR,
- TestAtomicFileOutputStream.class.getName());
+ private static File TEST_DIR = PathUtils.getTestDir(TestAtomicFileOutputStream.class);
private static File DST_FILE = new File(TEST_DIR, "test.txt");
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestMD5FileUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestMD5FileUtils.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestMD5FileUtils.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestMD5FileUtils.java Thu Sep 19 23:42:10 2013
@@ -29,14 +29,12 @@ import java.io.IOException;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.io.MD5Hash;
+import org.apache.hadoop.test.PathUtils;
import org.junit.Before;
import org.junit.Test;
public class TestMD5FileUtils {
- private static final File TEST_DIR_ROOT = new File(
- System.getProperty("test.build.data","build/test/data"));
- private static final File TEST_DIR = new File(TEST_DIR_ROOT,
- "TestMD5FileUtils");
+ private static final File TEST_DIR = PathUtils.getTestDir(TestMD5FileUtils.class);
private static final File TEST_FILE = new File(TEST_DIR,
"testMd5File.dat");
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java Thu Sep 19 23:42:10 2013
@@ -21,6 +21,7 @@ package org.apache.hadoop.hdfs.web;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -45,8 +46,11 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.hadoop.hdfs.web.resources.DoAsParam;
import org.apache.hadoop.hdfs.web.resources.GetOpParam;
import org.apache.hadoop.hdfs.web.resources.HttpOpParam;
+import org.apache.hadoop.hdfs.web.resources.LengthParam;
import org.apache.hadoop.hdfs.web.resources.NamenodeRpcAddressParam;
+import org.apache.hadoop.hdfs.web.resources.OffsetParam;
import org.apache.hadoop.hdfs.web.resources.PutOpParam;
+import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.Assert;
@@ -288,6 +292,104 @@ public class TestWebHdfsFileSystemContra
}
}
+ /**
+ * Test get with length parameter greater than actual file length.
+ */
+ public void testLengthParamLongerThanFile() throws IOException {
+ WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)fs;
+ Path dir = new Path("/test");
+ assertTrue(webhdfs.mkdirs(dir));
+
+ // Create a file with some content.
+ Path testFile = new Path("/test/testLengthParamLongerThanFile");
+ String content = "testLengthParamLongerThanFile";
+ FSDataOutputStream testFileOut = webhdfs.create(testFile);
+ try {
+ testFileOut.write(content.getBytes("US-ASCII"));
+ } finally {
+ IOUtils.closeStream(testFileOut);
+ }
+
+ // Open the file, but request length longer than actual file length by 1.
+ HttpOpParam.Op op = GetOpParam.Op.OPEN;
+ URL url = webhdfs.toUrl(op, testFile, new LengthParam(Long.valueOf(
+ content.length() + 1)));
+ HttpURLConnection conn = null;
+ InputStream is = null;
+ try {
+ conn = (HttpURLConnection)url.openConnection();
+ conn.setRequestMethod(op.getType().toString());
+ conn.setDoOutput(op.getDoOutput());
+ conn.setInstanceFollowRedirects(true);
+
+ // Expect OK response and Content-Length header equal to actual length.
+ assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
+ assertEquals(String.valueOf(content.length()), conn.getHeaderField(
+ "Content-Length"));
+
+ // Check content matches.
+ byte[] respBody = new byte[content.length()];
+ is = conn.getInputStream();
+ IOUtils.readFully(is, respBody, 0, content.length());
+ assertEquals(content, new String(respBody, "US-ASCII"));
+ } finally {
+ IOUtils.closeStream(is);
+ if (conn != null) {
+ conn.disconnect();
+ }
+ }
+ }
+
+ /**
+ * Test get with offset and length parameters that combine to request a length
+ * greater than actual file length.
+ */
+ public void testOffsetPlusLengthParamsLongerThanFile() throws IOException {
+ WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)fs;
+ Path dir = new Path("/test");
+ assertTrue(webhdfs.mkdirs(dir));
+
+ // Create a file with some content.
+ Path testFile = new Path("/test/testOffsetPlusLengthParamsLongerThanFile");
+ String content = "testOffsetPlusLengthParamsLongerThanFile";
+ FSDataOutputStream testFileOut = webhdfs.create(testFile);
+ try {
+ testFileOut.write(content.getBytes("US-ASCII"));
+ } finally {
+ IOUtils.closeStream(testFileOut);
+ }
+
+ // Open the file, but request offset starting at 1 and length equal to file
+ // length. Considering the offset, this is longer than the actual content.
+ HttpOpParam.Op op = GetOpParam.Op.OPEN;
+ URL url = webhdfs.toUrl(op, testFile, new LengthParam(Long.valueOf(
+ content.length())), new OffsetParam(1L));
+ HttpURLConnection conn = null;
+ InputStream is = null;
+ try {
+ conn = (HttpURLConnection)url.openConnection();
+ conn.setRequestMethod(op.getType().toString());
+ conn.setDoOutput(op.getDoOutput());
+ conn.setInstanceFollowRedirects(true);
+
+ // Expect OK response and Content-Length header equal to actual length.
+ assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
+ assertEquals(String.valueOf(content.length() - 1), conn.getHeaderField(
+ "Content-Length"));
+
+ // Check content matches.
+ byte[] respBody = new byte[content.length() - 1];
+ is = conn.getInputStream();
+ IOUtils.readFully(is, respBody, 0, content.length() - 1);
+ assertEquals(content.substring(1), new String(respBody, "US-ASCII"));
+ } finally {
+ IOUtils.closeStream(is);
+ if (conn != null) {
+ conn.disconnect();
+ }
+ }
+ }
+
public void testResponseCode() throws IOException {
final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem)fs;
final Path root = new Path("/");
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTimeouts.java Thu Sep 19 23:42:10 2013
@@ -58,7 +58,6 @@ public class TestWebHdfsTimeouts {
private static final int CLIENTS_TO_CONSUME_BACKLOG = 100;
private static final int CONNECTION_BACKLOG = 1;
- private static final int INITIAL_SOCKET_TIMEOUT = URLUtils.SOCKET_TIMEOUT;
private static final int SHORT_SOCKET_TIMEOUT = 5;
private static final int TEST_TIMEOUT = 10000;
@@ -67,20 +66,22 @@ public class TestWebHdfsTimeouts {
private InetSocketAddress nnHttpAddress;
private ServerSocket serverSocket;
private Thread serverThread;
+ private URLConnectionFactory connectionFactory = new URLConnectionFactory(SHORT_SOCKET_TIMEOUT);
@Before
public void setUp() throws Exception {
- URLUtils.SOCKET_TIMEOUT = SHORT_SOCKET_TIMEOUT;
Configuration conf = WebHdfsTestUtil.createConf();
nnHttpAddress = NameNode.getHttpAddress(conf);
serverSocket = new ServerSocket(nnHttpAddress.getPort(), CONNECTION_BACKLOG);
fs = WebHdfsTestUtil.getWebHdfsFileSystem(conf);
+ fs.connectionFactory = connectionFactory;
clients = new ArrayList<SocketChannel>();
serverThread = null;
}
@After
public void tearDown() throws Exception {
+ fs.connectionFactory = URLConnectionFactory.DEFAULT_CONNECTION_FACTORY;
IOUtils.cleanup(LOG, clients.toArray(new SocketChannel[clients.size()]));
IOUtils.cleanup(LOG, fs);
if (serverSocket != null) {
@@ -240,7 +241,7 @@ public class TestWebHdfsTimeouts {
*/
private void startSingleTemporaryRedirectResponseThread(
final boolean consumeConnectionBacklog) {
- URLUtils.SOCKET_TIMEOUT = INITIAL_SOCKET_TIMEOUT;
+ fs.connectionFactory = URLConnectionFactory.DEFAULT_CONNECTION_FACTORY;
serverThread = new Thread() {
@Override
public void run() {
@@ -254,7 +255,7 @@ public class TestWebHdfsTimeouts {
clientSocket = serverSocket.accept();
// Immediately setup conditions for subsequent connections.
- URLUtils.SOCKET_TIMEOUT = SHORT_SOCKET_TIMEOUT;
+ fs.connectionFactory = connectionFactory;
if (consumeConnectionBacklog) {
consumeConnectionBacklog();
}
Modified: hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml?rev=1524865&r1=1524864&r2=1524865&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml (original)
+++ hadoop/common/branches/HDFS-4949/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml Thu Sep 19 23:42:10 2013
@@ -443,6 +443,153 @@
</comparators>
</test>
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in an absolute path to a file</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "/a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "/a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -ls "/a path with/whitespaces in directories"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "/a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 1 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*/a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in a relative path to a file</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -ls "a path with/whitespaces in directories"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 1 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in a scheme-qualified path to a file</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "NAMENODE/a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "NAMENODE/a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -ls "NAMENODE/a path with/whitespaces in directories"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "NAMENODE/a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 1 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*NAMENODE/a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in an absolute path to a file, using globbing</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "/a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "/a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -touchz "/a path with/whitespaces in directories/and file names 2"</command>
+ <command>-fs NAMENODE -ls "/a*/w*"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "/a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 2 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*/a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*/a path with/whitespaces in directories/and file names 2</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in a relative path to a file, using globbing</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -touchz "a path with/whitespaces in directories/and file names 2"</command>
+ <command>-fs NAMENODE -ls "a*/w*"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 2 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*a path with/whitespaces in directories/and file names 2</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
+ <test> <!-- TESTED -->
+ <description>ls: whitespaces in a scheme-qualified path to a file, using globbing</description>
+ <test-commands>
+ <command>-fs NAMENODE -mkdir -p "NAMENODE/a path with/whitespaces in directories"</command>
+ <command>-fs NAMENODE -touchz "NAMENODE/a path with/whitespaces in directories/and file names"</command>
+ <command>-fs NAMENODE -touchz "NAMENODE/a path with/whitespaces in directories/and file names 2"</command>
+ <command>-fs NAMENODE -ls "NAMENODE/a*/w*"</command>
+ </test-commands>
+ <cleanup-commands>
+ <command>-fs NAMENODE -rm -r "NAMENODE/a path with"</command>
+ </cleanup-commands>
+ <comparators>
+ <comparator>
+ <type>TokenComparator</type>
+ <expected-output>Found 2 items</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*NAMENODE/a path with/whitespaces in directories/and file names</expected-output>
+ </comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^-rw-r--r--( )*1( )*[a-z]*( )*supergroup( )*0( )*[0-9]{4,}-[0-9]{2,}-[0-9]{2,} [0-9]{2,}:[0-9]{2,}( )*NAMENODE/a path with/whitespaces in directories/and file names 2</expected-output>
+ </comparator>
+ </comparators>
+ </test>
+
<!-- Tests for ls -R -->
<test> <!-- TESTED -->
<description>ls: files/directories using absolute path</description>
@@ -6503,23 +6650,23 @@
<comparators>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data15bytes-15"</expected-output>
+ <expected-output>data15bytes-15</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data30bytes-30"</expected-output>
+ <expected-output>data30bytes-30</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data60bytes-60"</expected-output>
+ <expected-output>data60bytes-60</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data120bytes-120"</expected-output>
+ <expected-output>data120bytes-120</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"datadir-0"</expected-output>
+ <expected-output>datadir-0</expected-output>
</comparator>
</comparators>
</test>
@@ -6542,23 +6689,23 @@
<comparators>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data15bytes-15"</expected-output>
+ <expected-output>data15bytes-15</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data30bytes-30"</expected-output>
+ <expected-output>data30bytes-30</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data60bytes-60"</expected-output>
+ <expected-output>data60bytes-60</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data120bytes-120"</expected-output>
+ <expected-output>data120bytes-120</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"datadir-0"</expected-output>
+ <expected-output>datadir-0</expected-output>
</comparator>
</comparators>
</test>
@@ -6644,23 +6791,23 @@
<comparators>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data15bytes-15"</expected-output>
+ <expected-output>data15bytes-15</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data30bytes-30"</expected-output>
+ <expected-output>data30bytes-30</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data60bytes-60"</expected-output>
+ <expected-output>data60bytes-60</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data120bytes-120"</expected-output>
+ <expected-output>data120bytes-120</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"datadir-0"</expected-output>
+ <expected-output>datadir-0</expected-output>
</comparator>
</comparators>
</test>
@@ -6731,23 +6878,23 @@
<comparators>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data15bytes-15"</expected-output>
+ <expected-output>data15bytes-15</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data30bytes-30"</expected-output>
+ <expected-output>data30bytes-30</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data60bytes-60"</expected-output>
+ <expected-output>data60bytes-60</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"data120bytes-120"</expected-output>
+ <expected-output>data120bytes-120</expected-output>
</comparator>
<comparator>
<type>TokenComparator</type>
- <expected-output>"datadir-0"</expected-output>
+ <expected-output>datadir-0</expected-output>
</comparator>
</comparators>
</test>