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 at...@apache.org on 2012/04/09 08:02:27 UTC
svn commit: r1311134 -
/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java
Author: atm
Date: Mon Apr 9 06:02:26 2012
New Revision: 1311134
URL: http://svn.apache.org/viewvc?rev=1311134&view=rev
Log:
HADOOP-8261. Har file system doesn't deal with FS URIs with a host but no port. Contributed by Aaron T. Myers.
Added:
hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java
Added: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java?rev=1311134&view=auto
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java (added)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestHarFileSystemWithHA.java Mon Apr 9 06:02:26 2012
@@ -0,0 +1,80 @@
+/**
+ * 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.hdfs.server.namenode.ha;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.HarFileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.MiniDFSNNTopology;
+import org.junit.Test;
+
+public class TestHarFileSystemWithHA {
+
+ private static final Path TEST_HAR_PATH = new Path("/input.har");
+
+ /**
+ * Test that the HarFileSystem works with underlying HDFS URIs that have no
+ * port specified, as is often the case with an HA setup.
+ */
+ @Test
+ public void testHarUriWithHaUriWithNoPort() throws Exception {
+ Configuration conf = new HdfsConfiguration();
+ MiniDFSCluster cluster = null;
+ try {
+ cluster = new MiniDFSCluster.Builder(conf)
+ .numDataNodes(1)
+ .nnTopology(MiniDFSNNTopology.simpleHATopology())
+ .build();
+ cluster.transitionToActive(0);
+ HATestUtil.setFailoverConfigurations(cluster, conf);
+
+ createEmptyHarArchive(HATestUtil.configureFailoverFs(cluster, conf),
+ TEST_HAR_PATH);
+
+ URI failoverUri = FileSystem.getDefaultUri(conf);
+ Path p = new Path("har://hdfs-" + failoverUri.getAuthority() + TEST_HAR_PATH);
+ p.getFileSystem(conf);
+ } finally {
+ cluster.shutdown();
+ }
+ }
+
+ /**
+ * Create an empty Har archive in the FileSystem fs at the Path p.
+ *
+ * @param fs the file system to create the Har archive in
+ * @param p the path to create the Har archive at
+ * @throws IOException in the event of error
+ */
+ private static void createEmptyHarArchive(FileSystem fs, Path p)
+ throws IOException {
+ fs.mkdirs(p);
+ OutputStream out = fs.create(new Path(p, "_masterindex"));
+ out.write(Integer.toString(HarFileSystem.VERSION).getBytes());
+ out.close();
+ fs.create(new Path(p, "_index")).close();
+ }
+
+}