You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2011/08/12 01:02:11 UTC
svn commit: r1156857 - in /hadoop/common/trunk/hadoop-common: CHANGES.txt
src/test/java/org/apache/hadoop/fs/TestPath.java
Author: eli
Date: Thu Aug 11 23:02:10 2011
New Revision: 1156857
URL: http://svn.apache.org/viewvc?rev=1156857&view=rev
Log:
HADOOP-7526. Add TestPath tests for URI conversion and reserved characters. Contributed by Eli Collins
Modified:
hadoop/common/trunk/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
Modified: hadoop/common/trunk/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common/CHANGES.txt?rev=1156857&r1=1156856&r2=1156857&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common/CHANGES.txt Thu Aug 11 23:02:10 2011
@@ -319,6 +319,9 @@ Trunk (unreleased changes)
HADOOP-6158. Move CyclicIteration to HDFS. (eli)
+ HADOOP-7526. Add TestPath tests for URI conversion and reserved
+ characters. (eli)
+
OPTIMIZATIONS
HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole
Modified: hadoop/common/trunk/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java?rev=1156857&r1=1156856&r2=1156857&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java (original)
+++ hadoop/common/trunk/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java Thu Aug 11 23:02:10 2011
@@ -185,6 +185,48 @@ public class TestPath extends TestCase {
assertEquals("foo://bar/fud#boo", new Path(new Path(new URI(
"foo://bar/baz#bud")), new Path(new URI("/fud#boo"))).toString());
}
+
+ /** Test URIs created from Path objects */
+ public void testPathToUriConversion() throws URISyntaxException, IOException {
+ // Path differs from URI in that it ignores the query part..
+ assertEquals(new URI(null, null, "/foo?bar", null, null), new Path("/foo?bar").toUri());
+ assertEquals(new URI(null, null, "/foo\"bar", null, null), new Path("/foo\"bar").toUri());
+ assertEquals(new URI(null, null, "/foo bar", null, null), new Path("/foo bar").toUri());
+ // therefore "foo?bar" is a valid Path, so a URI created from a Path has path "foo?bar"
+ // where in a straight URI the path part is just "foo"
+ assertEquals("/foo?bar", new Path("http://localhost/foo?bar").toUri().getPath());
+ assertEquals("/foo", new URI("http://localhost/foo?bar").getPath());
+
+ // The path part handling in Path is equivalent to URI
+ assertEquals(new URI("/foo;bar").getPath(), new Path("/foo;bar").toUri().getPath());
+ assertEquals(new URI("/foo;bar"), new Path("/foo;bar").toUri());
+ assertEquals(new URI("/foo+bar"), new Path("/foo+bar").toUri());
+ assertEquals(new URI("/foo-bar"), new Path("/foo-bar").toUri());
+ assertEquals(new URI("/foo=bar"), new Path("/foo=bar").toUri());
+ assertEquals(new URI("/foo,bar"), new Path("/foo,bar").toUri());
+ }
+
+ /** Test reserved characters in URIs (and therefore Paths) */
+ public void testReservedCharacters() throws URISyntaxException, IOException {
+ // URI encodes the path
+ assertEquals("/foo%20bar", new URI(null, null, "/foo bar", null, null).getRawPath());
+ // URI#getPath decodes the path
+ assertEquals("/foo bar", new URI(null, null, "/foo bar", null, null).getPath());
+ // URI#toString returns an encoded path
+ assertEquals("/foo%20bar", new URI(null, null, "/foo bar", null, null).toString());
+ assertEquals("/foo%20bar", new Path("/foo bar").toUri().toString());
+ // Reserved chars are not encoded
+ assertEquals("/foo;bar", new URI("/foo;bar").getPath());
+ assertEquals("/foo;bar", new URI("/foo;bar").getRawPath());
+ assertEquals("/foo+bar", new URI("/foo+bar").getPath());
+ assertEquals("/foo+bar", new URI("/foo+bar").getRawPath());
+
+ // URI#getPath decodes the path part (and URL#getPath does not decode)
+ assertEquals("/foo bar", new Path("http://localhost/foo bar").toUri().getPath());
+ assertEquals("/foo%20bar", new Path("http://localhost/foo bar").toUri().toURL().getPath());
+ assertEquals("/foo?bar", new URI("http", "localhost", "/foo?bar", null, null).getPath());
+ assertEquals("/foo%3Fbar", new URI("http", "localhost", "/foo?bar", null, null).toURL().getPath());
+ }
public void testMakeQualified() throws URISyntaxException {
URI defaultUri = new URI("hdfs://host1/dir1");