changeset 14520:dbd2f64d6653

Fix regression in service binding due to recent refactoring
author alanb
date Tue, 01 Dec 2015 13:22:42 +0000
parents ffe12af5613c
children 9fdbe1e7defa
files src/java.base/share/classes/java/lang/module/Resolver.java test/jdk/jigsaw/module/ConfigurationTest.java
diffstat 2 files changed, 69 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/module/Resolver.java	Tue Dec 01 12:04:53 2015 +0000
+++ b/src/java.base/share/classes/java/lang/module/Resolver.java	Tue Dec 01 13:22:42 2015 +0000
@@ -323,18 +323,18 @@
     /**
      * Poll the given {@code Deque} for modules to resolve. On completion the
      * {@code Deque} will be empty and any selected modules will be added to
-     * the given Resolution.
+     * the Selected.
      *
-     * @return The set of module selected by this invocation of resolve
+     * @return The set of module resolved by this invocation of resolve
      */
     private Set<ModuleDescriptor> resolve(Deque<ModuleDescriptor> q,
                                           Selected selected)
     {
-
-        Set<ModuleDescriptor> newlySelected = new HashSet<>();
+        Set<ModuleDescriptor> resolved = new HashSet<>();
 
         while (!q.isEmpty()) {
             ModuleDescriptor descriptor = q.poll();
+            assert selected.contains(descriptor.name());
 
             // process dependences
             for (ModuleDescriptor.Requires requires : descriptor.requires()) {
@@ -356,7 +356,7 @@
                 if (!selected.contains(dn)) {
                     selected.add(mref);
                     q.offer(mref.descriptor());
-                    newlySelected.add(mref.descriptor());
+                    resolved.add(mref.descriptor());
 
                     if (TRACE) {
                         trace("Module %s located, required by %s",
@@ -367,9 +367,11 @@
                 }
 
             }
+
+            resolved.add(descriptor);
         }
 
-        return newlySelected;
+        return resolved;
     }
 
 
--- a/test/jdk/jigsaw/module/ConfigurationTest.java	Tue Dec 01 12:04:53 2015 +0000
+++ b/test/jdk/jigsaw/module/ConfigurationTest.java	Tue Dec 01 13:22:42 2015 +0000
@@ -433,6 +433,8 @@
 
     /**
      * Basic test of binding services
+     *     m1 uses p.Service
+     *     m2 provides p.Service
      */
     public void testServiceBinding1() {
 
@@ -473,24 +475,75 @@
         assertTrue(cf.findModule("m1").isPresent());
         assertTrue(cf.findModule("m2").isPresent());
 
-        assertEquals(cf.modules().stream()
-                        .map(ModuleReference::descriptor)
-                        .collect(Collectors.toSet()),
-                cf.descriptors());
-
         assertTrue(cf.provides("p.Service").size() == 1);
         assertTrue(cf.provides("p.Service").contains(descriptor2));
     }
 
 
     /**
+     * Basic test of binding services
+     *     m1 uses p.Service1
+     *     m2 provides p.Service1, m2 uses p.Service2
+     *     m3 provides p.Service2
+     */
+    public void testServiceBinding2() {
+
+        ModuleDescriptor descriptor1
+            = new ModuleDescriptor.Builder("m1")
+                .uses("p.Service1")
+                .build();
+
+        ModuleDescriptor descriptor2
+            = new ModuleDescriptor.Builder("m2")
+                .uses("p.Service2")
+                .provides("p.Service1", "q.Service1Impl")
+                .build();
+
+        ModuleDescriptor descriptor3
+            = new ModuleDescriptor.Builder("m3")
+                .provides("p.Service2", "q.Service2Impl")
+                .build();
+
+        ModuleFinder finder
+            = ModuleUtils.finderOf(descriptor1, descriptor2, descriptor3);
+
+        Configuration cf
+            = Configuration.resolve(finder, empty(), ModuleFinder.empty(), "m1");
+
+        // only m1 in configuration
+        assertTrue(cf.descriptors().size() == 1);
+        assertTrue(cf.findModule("m1").isPresent());
+
+        assertTrue(cf.parent().get() == empty());
+
+        assertTrue(cf.provides("p.Service1").isEmpty());
+
+        // bind services, should augment graph with m2 and m3
+        cf = cf.bind();
+
+        assertTrue(cf.parent().get() == empty());
+
+        assertTrue(cf.descriptors().size() == 3);
+        assertTrue(cf.findModule("m1").isPresent());
+        assertTrue(cf.findModule("m2").isPresent());
+        assertTrue(cf.findModule("m3").isPresent());
+
+        assertTrue(cf.provides("p.Service1").size() == 1);
+        assertTrue(cf.provides("p.Service1").contains(descriptor2));
+
+        assertTrue(cf.provides("p.Service2").size() == 1);
+        assertTrue(cf.provides("p.Service2").contains(descriptor3));
+    }
+
+
+    /**
      * Basic test of binding services with configurations.
      *
      * The test consists of two configurations:
      * - Configuration cf1: m1 uses p.Service
      * - Configuration cf2: m2 provides p.Service
      */
-    public void testServiceBinding2() {
+    public void testServiceBindingWithConfigurations1() {
 
         ModuleDescriptor descriptor1
             = new ModuleDescriptor.Builder("m1")
@@ -537,7 +590,7 @@
      * - Configuration cf2: m3 provides p.Service
      *                      m4 provides p.Service
      */
-    public void testServiceBinding3() {
+    public void testServiceBindingWithConfigurations2() {
 
         ModuleDescriptor descriptor1
             = new ModuleDescriptor.Builder("m1")
@@ -609,7 +662,7 @@
      * Test configuration cf2: m1 uses p.Service
      * Test configuration cf2: m1 uses p.Service, p@2.0 uses p.Service
      */
-    public void testServiceBinding4() {
+    public void testServiceBindingWithConfigurations3() {
 
         ModuleDescriptor provider_v1
             = new ModuleDescriptor.Builder("p")