8175336: [TESTBUG] aot junit tests added by 8169588 are not executed.
authorrbackman
Thu, 23 Feb 2017 10:08:51 +0100
changeset 44081 5dbc6c93f9bf
parent 43980 792a70d867f4
child 44082 95196492dc31
8175336: [TESTBUG] aot junit tests added by 8169588 are not executed. Reviewed-by: kvn
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSearchTest.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSourceTest.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeFileSupport.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeSearchPath.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/SearchPathTest.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/directory/DirectorySourceProviderTest.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/jar/JarSourceProviderTest.java
hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/module/ModuleSourceProviderTest.java
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSearchTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSearchTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -20,10 +20,19 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ * @run junit/othervm jdk.tools.jaotc.test.collect.ClassSearchTest
+ */
+
 package jdk.tools.jaotc.test.collect;
 
 
 import jdk.tools.jaotc.LoadedClass;
+import jdk.tools.jaotc.collect.*;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -32,45 +41,90 @@
 import java.util.List;
 import java.util.Set;
 import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
 
 public class ClassSearchTest {
     @Test(expected = InternalError.class)
     public void itShouldThrowExceptionIfNoProvidersAvailable() {
         ClassSearch target = new ClassSearch();
         SearchPath searchPath = new SearchPath();
-        target.search(list("foo"), searchPath);
+        target.search(list(new SearchFor("foo")), searchPath);
     }
 
     @Test
     public void itShouldFindAProviderForEachEntry() {
         Set<String> searched = new HashSet<>();
         ClassSearch target = new ClassSearch();
-        target.addProvider(new SourceProvider() {
-            @Override
-            public ClassSource findSource(String name, SearchPath searchPath) {
+        target.addProvider(provider("", (name, searchPath) -> {
                 searched.add(name);
                 return new NoopSource();
+        }));
+        target.search(searchForList("foo", "bar", "foobar"), null);
+        Assert.assertEquals(hashset("foo", "bar", "foobar"), searched);
+    }
+
+    private SourceProvider provider(String supports, BiFunction<String, SearchPath, ClassSource> fn) {
+        return new SourceProvider() {
+            @Override
+            public ClassSource findSource(String name, SearchPath searchPath) {
+                return fn.apply(name, searchPath);
             }
-        });
-        target.search(list("foo", "bar", "foobar"), null);
-        Assert.assertEquals(hashset("foo", "bar", "foobar"), searched);
+
+            @Override
+            public boolean supports(String type) {
+                return supports.equals(type);
+            }
+        };
     }
 
     @Test
-    public void itShouldSearchAllProviders() {
+    public void itShouldOnlySearchSupportedProvidersForKnownType() {
         Set<String> visited = new HashSet<>();
         ClassSearch target = new ClassSearch();
-        target.addProvider((name, searchPath) -> {
+
+        target.addProvider(provider("jar", (name, searchPath) -> {
+            visited.add("jar");
+            return null;
+        }));
+
+        target.addProvider(provider("dir", (name, searchPath) -> {
+            visited.add("dir");
+            return null;
+        }));
+
+        try {
+            target.search(list(new SearchFor("some", "dir")), null);
+        } catch (InternalError e) {
+            // throws because no provider gives a source
+        }
+
+        Assert.assertEquals(hashset("dir"), visited);
+    }
+
+    @Test(expected = InternalError.class)
+    public void itShouldThrowErrorIfMultipleSourcesAreAvailable() {
+        ClassSearch target = new ClassSearch();
+        target.addProvider(provider("", (name, searchPath) -> consumer -> Assert.fail()));
+        target.addProvider(provider("", (name, searchPath) -> consumer -> Assert.fail()));
+
+        target.search(searchForList("somethign"), null);
+    }
+
+    @Test
+    public void itShouldSearchAllProvidersForUnknownType() {
+        Set<String> visited = new HashSet<>();
+        ClassSearch target = new ClassSearch();
+        target.addProvider(provider("", (name, searchPath) -> {
             visited.add("1");
             return null;
-        });
-        target.addProvider((name, searchPath) -> {
+        }));
+        target.addProvider(provider("", (name, searchPath) -> {
             visited.add("2");
             return null;
-        });
+        }));
 
         try {
-            target.search(list("foo"), null);
+            target.search(searchForList("foo"), null);
         } catch (InternalError e) {
             // throws because no provider gives a source
         }
@@ -85,6 +139,11 @@
         ClassSearch target = new ClassSearch();
         target.addProvider(new SourceProvider() {
             @Override
+            public boolean supports(String type) {
+                return true;
+            }
+
+            @Override
             public ClassSource findSource(String name, SearchPath searchPath) {
                 return new ClassSource() {
                     @Override
@@ -101,7 +160,7 @@
             }
         });
 
-        java.util.List<LoadedClass> search = target.search(list("/tmp/something"), null);
+        java.util.List<LoadedClass> search = target.search(searchForList("/tmp/something"), null);
         Assert.assertEquals(list(new LoadedClass("foo.Bar", null)), search);
     }
 
@@ -115,8 +174,16 @@
         };
 
         ClassSearch target = new ClassSearch();
-        target.addProvider((name, searchPath) -> consumer -> consumer.accept("foo.Bar", classLoader));
-        target.search(list("foobar"), null);
+        target.addProvider(provider("", (name, searchPath) -> consumer -> consumer.accept("foo.Bar", classLoader)));
+        target.search(searchForList("foobar"), null);
+    }
+
+    private List<SearchFor> searchForList(String... entries) {
+        List<SearchFor> list = new ArrayList<>();
+        for (String entry : entries) {
+            list.add(new SearchFor(entry));
+        }
+        return list;
     }
 
     private <T> List<T> list(T... entries) {
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSourceTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/ClassSourceTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -20,6 +20,14 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ * @run junit/othervm jdk.tools.jaotc.test.collect.ClassSourceTest
+ */
+
 package jdk.tools.jaotc.test.collect;
 
 import org.junit.Assert;
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeFileSupport.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeFileSupport.java	Thu Feb 23 10:08:51 2017 +0100
@@ -27,6 +27,8 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import jdk.tools.jaotc.collect.FileSupport;
+
 public class FakeFileSupport extends FileSupport {
     private final Set<String> exists = new HashSet<>();
     private final Set<String> directories = new HashSet<>();
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeSearchPath.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/FakeSearchPath.java	Thu Feb 23 10:08:51 2017 +0100
@@ -22,6 +22,8 @@
  */
 package jdk.tools.jaotc.test.collect;
 
+import jdk.tools.jaotc.collect.SearchPath;
+
 import java.nio.file.FileSystem;
 import java.nio.file.Path;
 import java.nio.file.Paths;
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/SearchPathTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/SearchPathTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -20,6 +20,17 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ *
+ * @build jdk.tools.jaotc.test.collect.Utils
+ * @build jdk.tools.jaotc.test.collect.FakeFileSupport
+ * @run junit/othervm jdk.tools.jaotc.test.collect.SearchPathTest
+ */
+
 package jdk.tools.jaotc.test.collect;
 
 import org.junit.Before;
@@ -30,6 +41,8 @@
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+import jdk.tools.jaotc.collect.*;
+
 import static jdk.tools.jaotc.test.collect.Utils.set;
 import static org.junit.Assert.*;
 
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/directory/DirectorySourceProviderTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/directory/DirectorySourceProviderTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -21,11 +21,22 @@
  * questions.
  */
 
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ *          jdk.aot/jdk.tools.jaotc.collect.directory
+ * @compile ../Utils.java
+ * @compile ../FakeFileSupport.java
+ * @run junit/othervm jdk.tools.jaotc.test.collect.directory.DirectorySourceProviderTest
+ */
+
 package jdk.tools.jaotc.test.collect.directory;
 
 import jdk.tools.jaotc.collect.ClassSource;
+import jdk.tools.jaotc.collect.directory.DirectorySourceProvider;
 import jdk.tools.jaotc.test.collect.FakeFileSupport;
-import jdk.tools.jaotc.test.collect.FileSupport;
+import jdk.tools.jaotc.collect.FileSupport;
 import org.junit.Assert;
 import org.junit.Test;
 
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/jar/JarSourceProviderTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/jar/JarSourceProviderTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -20,9 +20,23 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ *          jdk.aot/jdk.tools.jaotc.collect.jar
+ * @compile ../Utils.java
+ * @compile ../FakeFileSupport.java
+ * @compile ../FakeSearchPath.java
+ *
+ * @run junit/othervm jdk.tools.jaotc.test.collect.jar.JarSourceProviderTest
+ */
+
 package jdk.tools.jaotc.test.collect.jar;
 
 import jdk.tools.jaotc.collect.ClassSource;
+import jdk.tools.jaotc.collect.jar.JarSourceProvider;
 import jdk.tools.jaotc.test.collect.FakeFileSupport;
 import jdk.tools.jaotc.test.collect.FakeSearchPath;
 import org.junit.Assert;
--- a/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/module/ModuleSourceProviderTest.java	Thu Feb 23 16:55:59 2017 +0100
+++ b/hotspot/test/compiler/aot/jdk.tools.jaotc.test/src/jdk/tools/jaotc/test/collect/module/ModuleSourceProviderTest.java	Thu Feb 23 10:08:51 2017 +0100
@@ -20,15 +20,31 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/**
+ * @test
+ * @modules jdk.aot/jdk.tools.jaotc
+ *          jdk.aot/jdk.tools.jaotc.collect
+ *          jdk.aot/jdk.tools.jaotc.collect.module
+ * @compile ../Utils.java
+ * @run junit/othervm jdk.tools.jaotc.test.collect.module.ModuleSourceProviderTest
+ */
+
 package jdk.tools.jaotc.test.collect.module;
 
-import jdk.tools.jaotc.*;
-import jdk.tools.jaotc.test.collect.FakeSearchPath;
+import jdk.tools.jaotc.collect.FileSupport;
+import jdk.tools.jaotc.collect.module.ModuleSource;
+import jdk.tools.jaotc.collect.module.ModuleSourceProvider;
 import jdk.tools.jaotc.test.collect.Utils;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.io.IOException;
+import java.nio.file.FileSystem;
 import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.function.BiFunction;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -36,28 +52,42 @@
 public class ModuleSourceProviderTest {
     private ClassLoader classLoader;
     private ModuleSourceProvider target;
+    private FileSupport fileSupport;
+    private BiFunction<Path, Path, Path> getSubDirectory = null;
 
     @Before
     public void setUp() {
         classLoader = new FakeClassLoader();
-        target = new ModuleSourceProvider(FileSystems.getDefault(), classLoader);
+        fileSupport = new FileSupport() {
+
+            @Override
+            public boolean isDirectory(Path path) {
+                return true;
+            }
+
+            @Override
+            public Path getSubDirectory(FileSystem fileSystem, Path root, Path path) throws IOException {
+                if (getSubDirectory == null) {
+                    throw new IOException("Nope");
+                }
+                return getSubDirectory.apply(root, path);
+            }
+        };
+        target = new ModuleSourceProvider(FileSystems.getDefault(), classLoader, fileSupport);
     }
 
     @Test
-    public void itShouldUseSearchPath() {
-        FakeSearchPath searchPath = new FakeSearchPath("blah/java.base");
-        ModuleSource source = (ModuleSource) target.findSource("java.base", searchPath);
-        assertEquals(Utils.set("java.base"), searchPath.entries);
-        assertEquals("blah/java.base", source.getModulePath().toString());
-        assertEquals("module:blah/java.base", source.toString());
-    }
+    public void itShouldUseFileSupport() {
+        getSubDirectory = (root, path) -> {
+            if (root.toString().equals("modules") && path.toString().equals("test.module")) {
+                return Paths.get("modules/test.module");
+            }
+            return null;
+        };
 
-    @Test
-    public void itShouldReturnNullIfSearchPathReturnsNull() {
-        FakeSearchPath searchPath = new FakeSearchPath(null);
-        ModuleSource source = (ModuleSource) target.findSource("jdk.base", searchPath);
-        assertEquals(Utils.set("jdk.base"), searchPath.entries);
-        assertNull(source);
+        ModuleSource source = (ModuleSource) target.findSource("test.module", null);
+        assertEquals("modules/test.module", source.getModulePath().toString());
+        assertEquals("module:modules/test.module", source.toString());
     }
 
     private static class FakeClassLoader extends ClassLoader {