Repository: hive Updated Branches: refs/heads/branch-1.2 1e0088fc6 -> 8fece5b4a
HIVE-10696 : TestAddResource tests are non-portable (Hari Subramaniyan reviewed by Alexander Pivovarov, Thejas Nair) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/8fece5b4 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/8fece5b4 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/8fece5b4 Branch: refs/heads/branch-1.2 Commit: 8fece5b4a95b51a37f4528d4a6a8fa0a89dfa97b Parents: 1e0088f Author: Hari Subramaniyan <harisan...@apache.org> Authored: Mon May 18 13:12:23 2015 -0700 Committer: Hari Subramaniyan <harisan...@apache.org> Committed: Mon May 18 13:17:44 2015 -0700 ---------------------------------------------------------------------- .../hadoop/hive/ql/session/TestAddResource.java | 98 ++++++++++++-------- 1 file changed, 57 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/8fece5b4/ql/src/test/org/apache/hadoop/hive/ql/session/TestAddResource.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/session/TestAddResource.java b/ql/src/test/org/apache/hadoop/hive/ql/session/TestAddResource.java index 6176b2d..1f07235 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/session/TestAddResource.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/session/TestAddResource.java @@ -31,6 +31,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; import org.junit.After; import org.junit.Before; @@ -38,6 +39,7 @@ import org.junit.Test; import org.mockito.Mockito; import org.apache.hadoop.hive.ql.session.SessionState.ResourceType; import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.util.Shell; import java.io.BufferedWriter; import java.io.FileWriter; @@ -45,7 +47,7 @@ import java.io.FileWriter; public class TestAddResource { - private static final String TEST_JAR_DIR = System.getProperty("test.tmp.dir", ".") + "/"; + private static final String TEST_JAR_DIR = System.getProperty("test.tmp.dir", ".") + File.pathSeparator; private HiveConf conf; private ResourceType t; @@ -74,11 +76,11 @@ public class TestAddResource { // add all the dependencies to a list List<URI> list = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); - list.add(new URI(TEST_JAR_DIR + "testjar1.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar5.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar1.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar5.jar")); //return all the dependency urls Mockito.when(ss.resolveAndDownload(t, query, false)).thenReturn(list); @@ -87,7 +89,7 @@ public class TestAddResource { Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } // sort both the lists @@ -109,11 +111,11 @@ public class TestAddResource { List<URI> list = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); - list.add(new URI(TEST_JAR_DIR + "testjar1.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list.add(new URI(TEST_JAR_DIR + "testjar5.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar1.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list.add(createURI(TEST_JAR_DIR + "testjar5.jar")); Collections.sort(list); @@ -125,7 +127,7 @@ public class TestAddResource { Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } Collections.sort(actual); @@ -147,13 +149,13 @@ public class TestAddResource { // add dependencies for the jars List<URI> list1 = new LinkedList<URI>(); List<URI> list2 = new LinkedList<URI>(); - list1.add(new URI(TEST_JAR_DIR + "testjar1.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar5.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar4.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar1.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar5.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar4.jar")); Mockito.when(ss.resolveAndDownload(t, query1, false)).thenReturn(list1); Mockito.when(ss.resolveAndDownload(t, query2, false)).thenReturn(list2); @@ -164,7 +166,7 @@ public class TestAddResource { Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List<URI> expected = union(list1, list2); @@ -176,6 +178,20 @@ public class TestAddResource { } + /** + * @param path + * @return URI corresponding to the path. + */ + private static URI createURI(String path) throws URISyntaxException { + if (!Shell.WINDOWS) { + // If this is not windows shell, path better follow unix convention. + // Else, the below call will throw an URISyntaxException + return new URI(path); + } else { + return new Path(path).toUri(); + } + } + // Test when two jars are added with shared dependencies and one jar is deleted, the shared dependencies should not be deleted @Test public void testDeleteJar() throws URISyntaxException, IOException { @@ -187,13 +203,13 @@ public class TestAddResource { List<URI> list1 = new LinkedList<URI>(); List<URI> list2 = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); - list1.add(new URI(TEST_JAR_DIR + "testjar1.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar5.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar4.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar1.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar5.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar4.jar")); Collections.sort(list1); Collections.sort(list2); @@ -211,7 +227,7 @@ public class TestAddResource { Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List<URI> expected = list2; Collections.sort(expected); @@ -242,16 +258,16 @@ public class TestAddResource { List<URI> list2 = new LinkedList<URI>(); List<URI> list3 = new LinkedList<URI>(); List<String> addList = new LinkedList<String>(); - list1.add(new URI(TEST_JAR_DIR + "testjar1.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list1.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar5.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar3.jar")); - list2.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list3.add(new URI(TEST_JAR_DIR + "testjar4.jar")); - list3.add(new URI(TEST_JAR_DIR + "testjar2.jar")); - list3.add(new URI(TEST_JAR_DIR + "testjar5.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar1.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list1.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar5.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar3.jar")); + list2.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list3.add(createURI(TEST_JAR_DIR + "testjar4.jar")); + list3.add(createURI(TEST_JAR_DIR + "testjar2.jar")); + list3.add(createURI(TEST_JAR_DIR + "testjar5.jar")); Collections.sort(list1); Collections.sort(list2); @@ -273,7 +289,7 @@ public class TestAddResource { Set<String> dependencies = ss.list_resource(t, null); LinkedList<URI> actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List<URI> expected = union(list2, list3); Collections.sort(expected); @@ -290,7 +306,7 @@ public class TestAddResource { dependencies = ss.list_resource(t, null); actual = new LinkedList<URI>(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } expected = new LinkedList<URI>(list3); Collections.sort(expected);