Repository: hadoop
Updated Branches:
  refs/heads/trunk 0afc036de -> ba4011d64


HADOOP-15217. FsUrlConnection does not handle paths with spaces. Contributed by 
Joseph Fourny and Zsolt Venczel.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ba4011d6
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ba4011d6
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ba4011d6

Branch: refs/heads/trunk
Commit: ba4011d64fadef3bee5920ccedbcdac01794cc23
Parents: 0afc036
Author: Xiao Chen <x...@apache.org>
Authored: Tue Jun 5 21:17:42 2018 -0700
Committer: Xiao Chen <x...@apache.org>
Committed: Tue Jun 5 21:18:31 2018 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/fs/FsUrlConnection.java   |  2 +-
 .../hadoop/fs/TestUrlStreamHandlerFactory.java  | 36 +++++++++++++++-----
 2 files changed, 29 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ba4011d6/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlConnection.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlConnection.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlConnection.java
index 03c7aed..e62c86f 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlConnection.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlConnection.java
@@ -57,7 +57,7 @@ class FsUrlConnection extends URLConnection {
     try {
       LOG.debug("Connecting to {}", url);
       FileSystem fs = FileSystem.get(url.toURI(), conf);
-      is = fs.open(new Path(url.getPath()));
+      is = fs.open(new Path(url.toURI()));
     } catch (URISyntaxException e) {
       throw new IOException(e.toString());
     }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ba4011d6/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java
 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java
index 910fee2..53cd557 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/fs/TestUrlStreamHandlerFactory.java
@@ -18,14 +18,19 @@
 
 package org.apache.hadoop.fs;
 
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.Timeout;
 
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Random;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Test of the URL stream handler factory.
@@ -35,7 +40,9 @@ public class TestUrlStreamHandlerFactory {
   private static final int RUNS = 20;
   private static final int THREADS = 10;
   private static final int TASKS = 200;
-  private static final int TIMEOUT = 30;
+
+  @Rule
+  public Timeout globalTimeout = new Timeout(30000);
 
   @Test
   public void testConcurrency() throws Exception {
@@ -62,12 +69,6 @@ public class TestUrlStreamHandlerFactory {
     }
 
     executor.shutdown();
-    try {
-      executor.awaitTermination(TIMEOUT, TimeUnit.SECONDS);
-      executor.shutdownNow();
-    } catch (InterruptedException e) {
-      // pass
-    }
 
     // check for exceptions
     for (Future future : futures) {
@@ -77,4 +78,23 @@ public class TestUrlStreamHandlerFactory {
       future.get();
     }
   }
+
+  @Test
+  public void testFsUrlStreamHandlerFactory() throws IOException {
+    File myFile = new File(GenericTestUtils.getTestDir(), "foo bar.txt");
+    myFile.createNewFile();
+
+    // Create URL directly from File (JRE builds it).
+    URL myUrl = myFile.toURI().toURL();
+
+    // Succeeds.
+    myUrl.openStream().close();
+
+    // Replace handling of file: scheme with FsUrlStreamHandler.
+    URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
+
+    URL myUrl2 = myFile.toURI().toURL();
+
+    myUrl2.openStream();
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to