/** * Tests the {@link AlluxioURI#isPathAbsolute()} method. */ @Test public void isPathAbsoluteTests() { assertFalse(new AlluxioURI(".").isPathAbsolute()); assertTrue(new AlluxioURI("/").isPathAbsolute()); assertTrue(new AlluxioURI("file:/").isPathAbsolute()); assertTrue(new AlluxioURI("file://localhost/").isPathAbsolute()); assertTrue(new AlluxioURI("file://localhost/a/b").isPathAbsolute()); assertFalse(new AlluxioURI("a/b").isPathAbsolute()); assertTrue(new AlluxioURI("C:\\\\a\\b").isPathAbsolute()); }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor for URI with spaces. */ @Test public void pathWithWhiteSpaces() { String[] paths = new String[]{ "/ ", "/ ", "/ path", "/path ", "/pa th", "/ pa th ", "/pa/ th", "/pa / th", "/ pa / th ", }; for (String path : paths) { AlluxioURI uri = new AlluxioURI(path); assertEquals(path, uri.getPath()); assertEquals(path, uri.toString()); assertTrue(uri.isPathAbsolute()); } }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor for an empty URI. */ @Test public void emptyURI() { AlluxioURI uri = new AlluxioURI(""); assertEquals("", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof NoAuthority); assertEquals(0, uri.getDepth()); assertEquals("", uri.getName()); assertEquals("", uri.getPath()); assertEquals(null, uri.getScheme()); assertFalse(uri.hasAuthority()); assertFalse(uri.hasScheme()); assertFalse(uri.isAbsolute()); assertFalse(uri.isPathAbsolute()); assertEquals("/d", uri.join("/d").toString()); assertEquals("/d", uri.join(new AlluxioURI("/d")).toString()); assertEquals("", uri.toString()); }
@Test public void basicMultiMasterUri() { AlluxioURI uri = new AlluxioURI("alluxio://host1:19998,host2:19998,host3:19998/xy z/a b c"); assertTrue(uri.hasAuthority()); assertEquals("host1:19998,host2:19998,host3:19998", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof MultiMasterAuthority); assertEquals(2, uri.getDepth()); assertEquals("a b c", uri.getName()); assertEquals("alluxio://host1:19998,host2:19998,host3:19998/xy z", uri.getParent().toString()); assertEquals("alluxio://host1:19998,host2:19998,host3:19998/", uri.getParent().getParent().toString()); assertEquals("/xy z/a b c", uri.getPath()); assertEquals("alluxio", uri.getScheme()); assertTrue(uri.hasScheme()); assertTrue(uri.isAbsolute()); assertTrue(uri.isPathAbsolute()); assertEquals("alluxio://host1:19998,host2:19998,host3:19998/xy z/a b c/d", uri.join("/d").toString()); assertEquals("alluxio://host1:19998,host2:19998,host3:19998/xy z/a b c/d", uri.join(new AlluxioURI("/d")).toString()); assertEquals("alluxio://host1:19998,host2:19998,host3:19998/xy z/a b c", uri.toString()); }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor for basic Alluxio paths. */ @Test public void basicAlluxioUri() { AlluxioURI uri = new AlluxioURI("alluxio://localhost:19998/xy z/a b c"); assertTrue(uri.hasAuthority()); assertEquals("localhost:19998", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof SingleMasterAuthority); SingleMasterAuthority authority = (SingleMasterAuthority) uri.getAuthority(); assertEquals("localhost", authority.getHost()); assertEquals(19998, authority.getPort()); assertEquals(2, uri.getDepth()); assertEquals("a b c", uri.getName()); assertEquals("alluxio://localhost:19998/xy z", uri.getParent().toString()); assertEquals("alluxio://localhost:19998/", uri.getParent().getParent().toString()); assertEquals("/xy z/a b c", uri.getPath()); assertEquals("alluxio", uri.getScheme()); assertTrue(uri.hasScheme()); assertTrue(uri.isAbsolute()); assertTrue(uri.isPathAbsolute()); assertEquals("alluxio://localhost:19998/xy z/a b c/d", uri.join("/d").toString()); assertEquals("alluxio://localhost:19998/xy z/a b c/d", uri.join(new AlluxioURI("/d")) .toString()); assertEquals("alluxio://localhost:19998/xy z/a b c", uri.toString()); }
/** * Tests the {@link AlluxioURI#AlluxioURI(String)} constructor for basic HDFS paths. */ @Test public void basicHdfsUri() { AlluxioURI uri = new AlluxioURI("hdfs://localhost:8020/xy z/a b c"); assertTrue(uri.hasAuthority()); assertEquals("localhost:8020", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof SingleMasterAuthority); SingleMasterAuthority authority = (SingleMasterAuthority) uri.getAuthority(); assertEquals("localhost", authority.getHost()); assertEquals(8020, authority.getPort()); assertEquals(2, uri.getDepth()); assertEquals("a b c", uri.getName()); assertEquals("hdfs://localhost:8020/xy z", uri.getParent().toString()); assertEquals("hdfs://localhost:8020/", uri.getParent().getParent().toString()); assertEquals("/xy z/a b c", uri.getPath()); assertEquals("hdfs", uri.getScheme()); assertTrue(uri.hasScheme()); assertTrue(uri.isAbsolute()); assertTrue(uri.isPathAbsolute()); assertEquals("hdfs://localhost:8020/xy z/a b c/d", uri.join("/d").toString()); assertEquals("hdfs://localhost:8020/xy z/a b c/d", uri.join(new AlluxioURI("/d")) .toString()); assertEquals("hdfs://localhost:8020/xy z/a b c", uri.toString()); }
@Test public void basicTwoPartUri() { AlluxioURI uri = new AlluxioURI("scheme:part2://localhost:8000/xy z/a b c"); assertEquals(uri, new AlluxioURI("scheme:part2//localhost:8000/xy z/a b c")); assertEquals("scheme:part2", uri.getScheme()); assertTrue(uri.hasAuthority()); assertEquals("localhost:8000", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof SingleMasterAuthority); SingleMasterAuthority authority = (SingleMasterAuthority) uri.getAuthority(); assertEquals("localhost", authority.getHost()); assertEquals(8000, authority.getPort()); assertEquals(2, uri.getDepth()); assertEquals("a b c", uri.getName()); assertEquals("scheme:part2://localhost:8000/xy z", uri.getParent().toString()); assertEquals("scheme:part2://localhost:8000/", uri.getParent().getParent().toString()); assertEquals("/xy z/a b c", uri.getPath()); assertTrue(uri.hasScheme()); assertTrue(uri.isAbsolute()); assertTrue(uri.isPathAbsolute()); assertEquals("scheme:part2://localhost:8000/xy z/a b c/d", uri.join("/d").toString()); assertEquals("scheme:part2://localhost:8000/xy z/a b c/d", uri.join(new AlluxioURI("/d")) .toString()); assertEquals("scheme:part2://localhost:8000/xy z/a b c", uri.toString()); }
@Test public void basicZookeeperUri() { AlluxioURI uri = new AlluxioURI("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c"); assertEquals(uri, new AlluxioURI("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c")); assertEquals("alluxio", uri.getScheme()); assertEquals("zk@host1:2181,host2:2181,host3:2181", uri.getAuthority().toString()); assertTrue(uri.getAuthority() instanceof ZookeeperAuthority); ZookeeperAuthority zkAuthority = (ZookeeperAuthority) uri.getAuthority(); assertEquals("host1:2181,host2:2181,host3:2181", zkAuthority.getZookeeperAddress()); assertEquals(2, uri.getDepth()); assertEquals("a b c", uri.getName()); assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z", uri.getParent().toString()); assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/", uri.getParent().getParent().toString()); assertEquals("/xy z/a b c", uri.getPath()); assertTrue(uri.hasAuthority()); assertTrue(uri.hasScheme()); assertTrue(uri.isAbsolute()); assertTrue(uri.isPathAbsolute()); assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c/d", uri.join("/d").toString()); assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c/d", uri.join(new AlluxioURI("/d")) .toString()); assertEquals("alluxio://zk@host1:2181,host2:2181,host3:2181/xy z/a b c", uri.toString()); }
/** * Returns an HDFS path for the given Alluxio path and under filesystem address. * * @param path Alluxio path * @param ufsAddress under filesystem address * @return an HDFS path */ public static Path getHDFSPath(AlluxioURI path, String ufsAddress) { if (path.isPathAbsolute()) { return new Path(ufsAddress + path.getPath()); } else { return new Path(ufsAddress + AlluxioURI.SEPARATOR + path.getPath()); } }