hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r910726 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/HarFileSystem.java src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java
Date Tue, 16 Feb 2010 22:17:55 GMT
Author: szetszwo
Date: Tue Feb 16 22:17:54 2010
New Revision: 910726

URL: http://svn.apache.org/viewvc?rev=910726&view=rev
Log:
HADOOP-6560. Handle invalid har:// uri in HarFileSystem.

Added:
    hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java
Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/fs/HarFileSystem.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=910726&r1=910725&r2=910726&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Tue Feb 16 22:17:54 2010
@@ -202,6 +202,8 @@
 
     HADOOP-6548. Replace mortbay imports with commons logging. (cdouglas)
 
+    HADOOP-6560. Handle invalid har:// uri in HarFileSystem.  (szetszwo)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/HarFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/HarFileSystem.java?rev=910726&r1=910725&r2=910726&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/HarFileSystem.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/HarFileSystem.java Tue Feb 16 22:17:54
2010
@@ -182,12 +182,20 @@
       return FileSystem.getDefaultUri(conf);
     }
     String host = rawURI.getHost();
-    String[] str = host.split("-", 2);
-    if (str[0] == null) {
-      throw new IOException("URI: " + rawURI + " is an invalid Har URI.");
-    }
-    String underLyingScheme = str[0];
-    String underLyingHost = (str.length > 1)? str[1]:null;
+    if (host == null) {
+      throw new IOException("URI: " + rawURI
+          + " is an invalid Har URI since host==null."
+          + "  Expecting har://<scheme>-<host>/<path>.");
+    }
+    int i = host.indexOf('-');
+    if (i < 0) {
+      throw new IOException("URI: " + rawURI
+          + " is an invalid Har URI since '-' not found."
+          + "  Expecting har://<scheme>-<host>/<path>.");
+    }
+    final String underLyingScheme = host.substring(0, i);
+    i++;
+    final String underLyingHost = i == host.length()? null: host.substring(i);
     int underLyingPort = rawURI.getPort();
     String auth = (underLyingHost == null && underLyingPort == -1)?
                   null:(underLyingHost+":"+underLyingPort);

Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java?rev=910726&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestHarFileSystem.java Tue Feb
16 22:17:54 2010
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestHarFileSystem {
+  @Test
+  public void testHarUri() {
+    final Configuration conf = new Configuration();
+    checkInvalidPath("har://hdfs-/foo.har", conf);
+    checkInvalidPath("har://hdfs/foo.har", conf);
+    checkInvalidPath("har://-hdfs/foo.har", conf);
+    checkInvalidPath("har://-/foo.har", conf);
+  }
+
+  static void checkInvalidPath(String s, Configuration conf) {
+    System.out.println("\ncheckInvalidPath: " + s);
+    final Path p = new Path(s);
+    try {
+      p.getFileSystem(conf);
+      Assert.fail(p + " is an invalid path.");
+    } catch (IOException e) {
+      System.out.println("GOOD: Got an exception.");
+      e.printStackTrace(System.out);
+    }
+  }
+}



Mime
View raw message