Permalink
Browse files

ACCUMULO-908 Fix VFS unit test cases which fail when run on any syste…

…m which specifies a FQDN for 127.0.0.1 other than "localhost"

git-svn-id: https://svn.apache.org/repos/asf/accumulo/trunk@1425709 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
joshelser committed Dec 25, 2012
1 parent 1039b9e commit fd54a83971d2aea07c13b72433205e2ddc366b18
@@ -100,7 +100,8 @@ public void testDefaultContextConfigured() throws Exception {
Assert.assertTrue((acl instanceof AccumuloReloadingVFSClassLoader));
AccumuloReloadingVFSClassLoader arvcl = (AccumuloReloadingVFSClassLoader) acl;
Assert.assertEquals(1, arvcl.getFiles().length);
- Assert.assertTrue(arvcl.getFiles()[0].getURL().toString().equals(AccumuloDFSBase.HDFS_URI + "/accumulo/classpath/HelloWorld.jar"));
+ // We can't be sure what the authority/host will be due to FQDN mappings, so just check the path
+ Assert.assertTrue(arvcl.getFiles()[0].getURL().toString().endsWith("/accumulo/classpath/HelloWorld.jar"));
Class<?> clazz1 = arvcl.loadClass("test.HelloWorld");
Object o1 = clazz1.newInstance();
Assert.assertEquals("Hello World!", o1.toString());
@@ -19,6 +19,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.net.URI;
import org.apache.commons.vfs2.CacheStrategy;
import org.apache.commons.vfs2.FileSystemException;
@@ -29,7 +30,6 @@
import org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory;
import org.apache.commons.vfs2.provider.ReadOnlyHdfsFileProvider;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.log4j.Level;
@@ -41,16 +41,20 @@
static {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
}
-
+
+ protected static Configuration conf = null;
+ protected static DefaultFileSystemManager vfs = null;
+ protected static MiniDFSCluster cluster = null;
+
// Choose an IANA unassigned port
// http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml
+ // TODO Given that the URI for the NameNode is statically declared in config files
+ // in src/test/resources, we have to assert the given port. It would be better to let
+ // MiniDFSCluster find a free port to use and then update the URI to be used in the VFS tests
protected static final Integer HDFS_PORT = 8620;
+ protected static final URI HDFS_URI;
- protected static final String HDFS_URI = "hdfs://localhost:" + HDFS_PORT;
- protected static Configuration conf = null;
- protected static DefaultFileSystemManager vfs = null;
- protected static MiniDFSCluster cluster = null;
static {
Logger.getRootLogger().setLevel(Level.ERROR);
@@ -59,7 +63,6 @@
//Setup HDFS
conf = new Configuration();
- conf.set(FileSystem.FS_DEFAULT_NAME_KEY, HDFS_URI);
conf.set("hadoop.security.token.service.use_ip", "true");
// MiniDFSCluster will check the permissions on the data directories, but does not
@@ -88,6 +91,9 @@
try {
cluster = new MiniDFSCluster(HDFS_PORT, conf, 1, true, true, true, null, null, null, null);
cluster.waitActive();
+ // We can't assume that the hostname of "localhost" will still be "localhost" after
+ // starting up the NameNode. We may get mapped into a FQDN via settings in /etc/hosts.
+ HDFS_URI = cluster.getFileSystem().getUri();
} catch (IOException e) {
throw new RuntimeException("Error setting up mini cluster", e);
}

0 comments on commit fd54a83

Please sign in to comment.