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 vi...@apache.org on 2013/09/03 20:30:16 UTC
svn commit: r1519787 [4/4] - in
/hadoop/common/branches/YARN-321/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/
hadoop...
Modified: hadoop/common/branches/YARN-321/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/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java?rev=1519787&r1=1519786&r2=1519787&view=diff
==============================================================================
--- hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java (original)
+++ hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java Tue Sep 3 18:30:05 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/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java?rev=1519787&r1=1519786&r2=1519787&view=diff
==============================================================================
--- hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java (original)
+++ hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsFileSystemContract.java Tue Sep 3 18:30:05 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/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml?rev=1519787&r1=1519786&r2=1519787&view=diff
==============================================================================
--- hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml (original)
+++ hadoop/common/branches/YARN-321/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml Tue Sep 3 18:30:05 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>