felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1371290 - in /felix/trunk/scr/src/test: java/org/apache/felix/scr/integration/CircularReferenceTest.java resources/integration_test_circular.xml
Date Thu, 09 Aug 2012 16:19:05 GMT
Author: djencks
Date: Thu Aug  9 16:19:05 2012
New Revision: 1371290

URL: http://svn.apache.org/viewvc?rev=1371290&view=rev
Log:
FELIX-3557 more circular ref tests, for b 0..1 to A

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
    felix/trunk/scr/src/test/resources/integration_test_circular.xml

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java?rev=1371290&r1=1371289&r2=1371290&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
Thu Aug  9 16:19:05 2012
@@ -189,4 +189,125 @@ public class CircularReferenceTest exten
         assertEquals( 1, b1.getAs().size() );
 
     }
+    /**
+     * A > 1.1 > B > 0..1 > A Both should start (A first), but B should not have
an A reference.
+     */
+    @Test
+    public void test_A11_B01_immediate_A_first()
+    {
+        String componentNameA = "5.A.1.1.dynamic";
+        final Component componentA = findComponentByName( componentNameA );
+        TestCase.assertNotNull( componentA );
+        TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
+        A a = ( A ) componentA.getComponentInstance().getInstance();
+        assertEquals( 1, a.getBs().size());
+
+        String componentNameB = "5.B.0.1.dynamic";
+        final Component componentB = findComponentByName( componentNameB );
+        TestCase.assertNotNull( componentB );
+        TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
+        B b = ( B ) componentB.getComponentInstance().getInstance();
+        assertEquals( 0, b.getAs().size() );
+    }
+    /**
+     * A > 1.1 > B > 0..1 > A Both should start (B first), and B should have
an A reference.
+     */
+    @Test
+    public void test_A11_B01_immediate_B_first()
+    {
+        String componentNameA = "6.A.1.1.dynamic";
+        final Component componentA = findComponentByName( componentNameA );
+        TestCase.assertNotNull( componentA );
+        TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
+        A a = ( A ) componentA.getComponentInstance().getInstance();
+        assertEquals( 1, a.getBs().size());
+
+        String componentNameB = "6.B.0.1.dynamic";
+        final Component componentB = findComponentByName( componentNameB );
+        TestCase.assertNotNull( componentB );
+        TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
+        B b = ( B ) componentB.getComponentInstance().getInstance();
+        assertEquals( 1, b.getAs().size() );
+    }
+    /**
+     * A > 1.1 > B > 0..1 > A Both should start, but B should not have an A reference.
+     */
+    @Test
+    public void test_A11_B01_delayed_A_first() throws InvalidSyntaxException
+    {
+        String componentNameA = "7.A.1.1.dynamic";
+        final Component componentA = findComponentByName( componentNameA );
+        TestCase.assertNotNull( componentA );
+        TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+
+        String componentNameB = "7.B.0.1.dynamic";
+        final Component componentB = findComponentByName( componentNameB );
+        TestCase.assertNotNull( componentB );
+        TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(),
"(service.pid=" + componentNameA + ")" );
+        TestCase.assertEquals( 1, serviceReferences.length );
+        ServiceReference serviceReference = serviceReferences[0];
+        Object service = bundleContext.getService( serviceReference );
+        assertNotNull( service );
+
+
+        A a = ( A ) componentA.getComponentInstance().getInstance();
+        assertEquals( 1, a.getBs().size() );
+        B b = ( B ) componentB.getComponentInstance().getInstance();
+        assertEquals( 0, b.getAs().size() );
+    }
+    /**
+     * A > 1.1 > B > 0..1 > A Both should start, but B should not have an A reference.
+     */
+    @Test
+    public void test_A11_B01_delayed_B_first() throws InvalidSyntaxException
+    {
+        String componentNameA = "7.A.1.1.dynamic";
+        final Component componentA = findComponentByName( componentNameA );
+        TestCase.assertNotNull( componentA );
+        TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+
+        String componentNameB = "7.B.0.1.dynamic";
+        final Component componentB = findComponentByName( componentNameB );
+        TestCase.assertNotNull( componentB );
+        TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+
+        ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(),
"(service.pid=" + componentNameB + ")" );
+        TestCase.assertEquals( 1, serviceReferencesB.length );
+        ServiceReference serviceReferenceB = serviceReferencesB[0];
+        Object serviceB = bundleContext.getService( serviceReferenceB );
+        assertNotNull( serviceB );
+
+        ServiceReference[] serviceReferencesA = bundleContext.getServiceReferences( A.class.getName(),
"(service.pid=" + componentNameA + ")" );
+        TestCase.assertEquals( 1, serviceReferencesA.length );
+        ServiceReference serviceReferenceA = serviceReferencesA[0];
+        Object serviceA = bundleContext.getService( serviceReferenceA );
+        assertNotNull( serviceA );
+
+
+        A a = ( A ) componentA.getComponentInstance().getInstance();
+        assertEquals( 1, a.getBs().size() );
+        B b = ( B ) componentB.getComponentInstance().getInstance();
+        assertEquals( 0, b.getAs().size() );
+
+
+        //disabling (removing the A service registration) and re-enabling will
+        //result in a service event to B, so B will bind A.
+        componentA.disable();
+        delay();
+        componentA.enable();
+        delay();
+        ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(),
"(service.pid=" + componentNameA + ")" );
+        TestCase.assertEquals( 1, serviceReferencesA1.length );
+        ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
+        Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
+        assertNotNull( serviceA1 );
+
+        A a1 = ( A ) componentA.getComponentInstance().getInstance();
+        assertEquals( 1, a1.getBs().size() );
+        B b1 = ( B ) componentB.getComponentInstance().getInstance();
+        assertEquals( 1, b1.getAs().size() );
+
+    }
 }

Modified: felix/trunk/scr/src/test/resources/integration_test_circular.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_circular.xml?rev=1371290&r1=1371289&r2=1371290&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_circular.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_circular.xml Thu Aug  9 16:19:05 2012
@@ -178,4 +178,125 @@
     </scr:component>
 
 
+    <!-- A 1.1 dynamic. B 0..1 dynamic  both immediate.  Both should start (A first) and
B should have no reference to A -->
+    <scr:component name="5.A.1.1.dynamic"
+        enabled="true"
+        immediate="true"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.A"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.A"
/>
+        </service>
+        <reference
+            name="b"
+            interface="org.apache.felix.scr.integration.components.circular.B"
+            cardinality="1..1"
+            policy="dynamic"
+            bind="setB"
+            unbind="unsetB"
+            target="(service.pid=5.B.0.1.dynamic)"
+        />
+        <property name="service.pid" value="5.A.1.1.dynamic" />
+    </scr:component>
+    <scr:component name="5.B.0.1.dynamic"
+        enabled="true"
+        immediate="true"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.B"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.B"
/>
+        </service>
+        <reference
+            name="a"
+            interface="org.apache.felix.scr.integration.components.circular.A"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setA"
+            unbind="unsetA"
+            target="(service.pid=5.A.1.1.dynamic)"
+        />
+        <property name="service.pid" value="5.B.0.1.dynamic" />
+    </scr:component>
+
+    <!-- A 1.1 dynamic. B 0..1 dynamic  both immediate.  Both should start (B first) and
B should have a reference to A -->
+    <scr:component name="6.B.0.1.dynamic"
+        enabled="true"
+        immediate="true"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.B"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.B"
/>
+        </service>
+        <reference
+            name="a"
+            interface="org.apache.felix.scr.integration.components.circular.A"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setA"
+            unbind="unsetA"
+            target="(service.pid=6.A.1.1.dynamic)"
+        />
+        <property name="service.pid" value="6.B.0.1.dynamic" />
+    </scr:component>
+    <scr:component name="6.A.1.1.dynamic"
+        enabled="true"
+        immediate="true"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.A"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.A"
/>
+        </service>
+        <reference
+            name="b"
+            interface="org.apache.felix.scr.integration.components.circular.B"
+            cardinality="1..1"
+            policy="dynamic"
+            bind="setB"
+            unbind="unsetB"
+            target="(service.pid=6.B.0.1.dynamic)"
+        />
+        <property name="service.pid" value="6.A.1.1.dynamic" />
+    </scr:component>
+
+    <!-- A 1.1 dynamic. B 0..1 dynamic  both delayed.  Both should start and B should
have no reference to A -->
+    <scr:component name="7.A.1.1.dynamic"
+        enabled="true"
+        immediate="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.A"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.A"
/>
+        </service>
+        <reference
+            name="b"
+            interface="org.apache.felix.scr.integration.components.circular.B"
+            cardinality="1..1"
+            policy="dynamic"
+            bind="setB"
+            unbind="unsetB"
+            target="(service.pid=7.B.0.1.dynamic)"
+        />
+        <property name="service.pid" value="7.A.1.1.dynamic" />
+    </scr:component>
+    <scr:component name="7.B.0.1.dynamic"
+        enabled="true"
+        immediate="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.circular.B"
/>
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.circular.B"
/>
+        </service>
+        <reference
+            name="a"
+            interface="org.apache.felix.scr.integration.components.circular.A"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setA"
+            unbind="unsetA"
+            target="(service.pid=7.A.1.1.dynamic)"
+        />
+        <property name="service.pid" value="7.B.0.1.dynamic" />
+    </scr:component>
+
+
 </components>



Mime
View raw message