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 c63498d..b898666 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 @@ -13,6 +13,7 @@ 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; @@ -20,6 +21,7 @@ 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; @@ -27,7 +29,7 @@ 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; @@ -56,11 +58,11 @@ public void testSanity() throws URISyntaxException, IOException { // add all the dependencies to a list List list = new LinkedList(); List addList = new LinkedList(); - 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); @@ -69,7 +71,7 @@ public void testSanity() throws URISyntaxException, IOException { Set dependencies = ss.list_resource(t, null); LinkedList actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } // sort both the lists @@ -91,11 +93,11 @@ public void testDuplicateAdds() throws URISyntaxException, IOException { List list = new LinkedList(); List addList = new LinkedList(); - 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); @@ -107,7 +109,7 @@ public void testDuplicateAdds() throws URISyntaxException, IOException { Set dependencies = ss.list_resource(t, null); LinkedList actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } Collections.sort(actual); @@ -129,13 +131,13 @@ public void testUnion() throws URISyntaxException, IOException { // add dependencies for the jars List list1 = new LinkedList(); List list2 = new LinkedList(); - 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); @@ -146,7 +148,7 @@ public void testUnion() throws URISyntaxException, IOException { Set dependencies = ss.list_resource(t, null); LinkedList actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List expected = union(list1, list2); @@ -158,6 +160,20 @@ public void testUnion() throws URISyntaxException, IOException { } + /** + * @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 { @@ -169,13 +185,13 @@ public void testDeleteJar() throws URISyntaxException, IOException { List list1 = new LinkedList(); List list2 = new LinkedList(); List addList = new LinkedList(); - 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); @@ -193,7 +209,7 @@ public void testDeleteJar() throws URISyntaxException, IOException { Set dependencies = ss.list_resource(t, null); LinkedList actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List expected = list2; Collections.sort(expected); @@ -224,16 +240,16 @@ public void testDeleteJarMultiple() throws URISyntaxException, IOException { List list2 = new LinkedList(); List list3 = new LinkedList(); List addList = new LinkedList(); - 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); @@ -255,7 +271,7 @@ public void testDeleteJarMultiple() throws URISyntaxException, IOException { Set dependencies = ss.list_resource(t, null); LinkedList actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } List expected = union(list2, list3); Collections.sort(expected); @@ -272,7 +288,7 @@ public void testDeleteJarMultiple() throws URISyntaxException, IOException { dependencies = ss.list_resource(t, null); actual = new LinkedList(); for (String dependency : dependencies) { - actual.add(new URI(dependency)); + actual.add(createURI(dependency)); } expected = new LinkedList(list3); Collections.sort(expected);