felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1615284 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/integration/ test/resources/
Date Sat, 02 Aug 2014 03:04:12 GMT
Author: djencks
Date: Sat Aug  2 03:04:11 2014
New Revision: 1615284

URL: http://svn.apache.org/r1615284
Log:
FELIX-4585 fix factory component bugs revealed by enable fix

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
    felix/trunk/scr/src/test/resources/integration_test_persistent_factory_components.xml
    felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
Sat Aug  2 03:04:11 2014
@@ -84,7 +84,8 @@ public abstract class AbstractComponentM
     
     protected final ComponentContainer<S> m_container;
 
-    private final boolean m_factoryInstance;
+    //true for normal spec factory instances. False for "persistent" factory instances and
obsolete use of factory component with factory configurations.
+    protected final boolean m_factoryInstance;
     // the ID of this component
     private long m_componentId;
 

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/SingleComponentManager.java
Sat Aug  2 03:04:11 2014
@@ -589,18 +589,23 @@ public class SingleComponentManager<S> e
                     // FELIX-2368: cycle component immediately, reconfigure() is
                     //     called through ConfigurationListener API which itself is
                     //     called asynchronously by the Configuration Admin Service
-                    releaseActivationWriteeLock( "reconfigure.modified.1" );;
-                    deactivateInternal( reason, false, false );
-                    obtainActivationWriteLock( "reconfigure.deactivate.activate" );
-                    try
+                    releaseActivationWriteeLock( "reconfigure.modified.1" );
+                    //we have already determined that modify cannot be called. Therefore
factory instances must be disposed.
+                    boolean dispose = m_factoryInstance;
+                    deactivateInternal( reason, dispose, dispose );
+                    if ( !dispose )
                     {
-                        updateTargets( getProperties() );
-                    }
-                    finally
-                    {
-                        releaseActivationWriteeLock( "reconfigure.deactivate.activate" );
+                        obtainActivationWriteLock("reconfigure.deactivate.activate");
+                        try
+                        {
+                            updateTargets(getProperties());
+                        }
+                        finally
+                        {
+                            releaseActivationWriteeLock("reconfigure.deactivate.activate");
+                        }
+                        activateInternal(getTrackingCount().get());
                     }
-                    activateInternal( getTrackingCount().get() );
                 }
             }
             finally

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
Sat Aug  2 03:04:11 2014
@@ -19,6 +19,7 @@
 package org.apache.felix.scr.integration;
 
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
@@ -137,6 +138,44 @@ public class ComponentFactoryTest extend
         final String componentname = "factory.component.configuration";
         final String componentfactory = "factory.component.factory.configuration";
 
+        testConfiguredFactory(componentname, componentfactory, false, false);
+        
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional";
+        final String componentfactory = "factory.component.factory.configuration.optional";
+
+        testConfiguredFactory(componentname, componentfactory, true, false);
+        
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration_13() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional.13";
+        final String componentfactory = "factory.component.factory.configuration.optional.13";
+
+        testConfiguredFactory(componentname, componentfactory, true, true);
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration_nomodify() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional.nomodify";
+        final String componentfactory = "factory.component.factory.configuration.optional.nomodify";
+
+        testConfiguredFactory(componentname, componentfactory, true, false);
+        
+    }
+
+
+    private ComponentInstance testConfiguredFactory(final String componentname,
+        final String componentfactory, boolean optional, boolean expectComponent) throws
InvocationTargetException,
+        InterruptedException, InvalidSyntaxException
+    {
         // ensure there is no configuration for the component
         deleteConfig( componentname );
         delay();
@@ -147,7 +186,7 @@ public class ComponentFactoryTest extend
         // At this point, since we don't have created the configuration, then the ComponentFactory
         // should not be available.
         
-        checkNoFactory(componentfactory);
+        checkFactory(componentfactory, optional);
         
         // supply configuration now and ensure active
         configure( componentname );
@@ -172,13 +211,26 @@ public class ComponentFactoryTest extend
         //deactivates component.
         deleteConfig( componentname );
         delay();
-        checkNoFactory(componentfactory);
 
-        TestCase.assertNull( instance.getInstance() );
-        TestCase.assertNull( SimpleComponent.INSTANCE );
+        checkFactory(componentfactory, optional);
 
-        // with removal of the factory, the created instance should also be removed
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        if (expectComponent) 
+        {
+            TestCase.assertNotNull( instance.getInstance() );
+            TestCase.assertNotNull( SimpleComponent.INSTANCE );
+
+            // with removal of the factory, the created instance should also be removed
+            checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
           
+        }
+        else
+        {
+            TestCase.assertNull( instance.getInstance() );
+            TestCase.assertNull( SimpleComponent.INSTANCE );
+
+            // with removal of the factory, the created instance should also be removed
+            checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
           
+        }
+        return instance;
     }
 
 

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Sat Aug  2 03:04:11 2014
@@ -551,12 +551,21 @@ public abstract class ComponentTestBase
     }
 
 
-    protected void checkNoFactory(final String componentfactory)
+    protected void checkFactory(final String componentfactory, boolean expectFactoryPresent)
         throws InvalidSyntaxException
     {
         ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(),
"("
             + ComponentConstants.COMPONENT_FACTORY + "=" + componentfactory + ")" );
-        TestCase.assertNull( refs );
+        if ( expectFactoryPresent )
+        {
+            TestCase.assertNotNull( refs );
+            TestCase.assertEquals(1, refs.length);
+
+        }
+        else
+        {
+            TestCase.assertNull( refs );
+        }
     }
 
     protected ComponentInstance createFactoryComponentInstance(final String componentfactory)

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
Sat Aug  2 03:04:11 2014
@@ -19,6 +19,7 @@
 package org.apache.felix.scr.integration;
 
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
@@ -126,13 +127,50 @@ public class PersistentComponentFactoryT
         checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.SATISFIED);
     }
 
-
     @Test
     public void test_component_factory_require_configuration() throws Exception
     {
         final String componentname = "factory.component.configuration";
         final String componentfactory = "factory.component.factory.configuration";
 
+        testConfiguredFactory(componentname, componentfactory, false, false);
+        
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional";
+        final String componentfactory = "factory.component.factory.configuration.optional";
+
+        testConfiguredFactory(componentname, componentfactory, true, true);
+        
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration_13() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional.13";
+        final String componentfactory = "factory.component.factory.configuration.optional.13";
+
+        testConfiguredFactory(componentname, componentfactory, true, true);
+    }
+
+    @Test
+    public void test_component_factory_optional_configuration_nomodify() throws Exception
+    {
+        final String componentname = "factory.component.configuration.optional.nomodify";
+        final String componentfactory = "factory.component.factory.configuration.optional.nomodify";
+
+        testConfiguredFactory(componentname, componentfactory, true, true);
+        
+    }
+
+
+    private ComponentInstance testConfiguredFactory(final String componentname,
+        final String componentfactory, boolean optional, boolean expectComponent) throws
InvocationTargetException,
+        InterruptedException, InvalidSyntaxException
+    {
         // ensure there is no configuration for the component
         deleteConfig( componentname );
         delay();
@@ -143,7 +181,7 @@ public class PersistentComponentFactoryT
         // At this point, since we don't have created the configuration, then the ComponentFactory
         // should not be available.
         
-        checkNoFactory(componentfactory);
+        checkFactory(componentfactory, optional);
         
         // supply configuration now and ensure active
         configure( componentname );
@@ -163,19 +201,35 @@ public class PersistentComponentFactoryT
 
         checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
 
-        // delete config, ensure factory is not active anymore and component instance dropped
(config required)
+        // delete config, ensure factory is not active anymore and component instance gone

+        //(configuration required >> dispose of instance.  Also for pre-1.3 components,
removing config unconditionally
+        //deactivates component.
         deleteConfig( componentname );
         delay();
-        checkNoFactory(componentfactory);
 
-        TestCase.assertNull( instance.getInstance() );
-        TestCase.assertNull( SimpleComponent.INSTANCE );
+        checkFactory(componentfactory, optional);
+
+        if (expectComponent) 
+        {
+            TestCase.assertNotNull( instance.getInstance() );
+            TestCase.assertNotNull( SimpleComponent.INSTANCE );
 
-        // with removal of the factory, the created instance should also be removed
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.UNSATISFIED);
+            // with removal of the factory, the created instance should also be removed
+            checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
           
+        }
+        else
+        {
+            TestCase.assertNull( instance.getInstance() );
+            TestCase.assertNull( SimpleComponent.INSTANCE );
+
+            // with removal of the factory, the created instance should also be removed
+            checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
           
+        }
+        return instance;
     }
 
 
+
     @Test
     public void test_component_factory_reference() throws Exception
     {

Modified: felix/trunk/scr/src/test/resources/integration_test_persistent_factory_components.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_persistent_factory_components.xml?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_persistent_factory_components.xml
(original)
+++ felix/trunk/scr/src/test/resources/integration_test_persistent_factory_components.xml
Sat Aug  2 03:04:11 2014
@@ -38,6 +38,32 @@
         <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
     </scr:component>
     
+    <scr:component name="factory.component.configuration.optional"
+        felix:persistentFactoryComponent="true"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional"
+        modified="modified" >
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
+    <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="factory.component.configuration.optional.13"
+        felix:persistentFactoryComponent="true"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional.13"
+        modified="modified" >
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
+    <scr:component name="factory.component.configuration.optional.nomodify"
+        felix:persistentFactoryComponent="true"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional.nomodify">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
     <!-- Component Factory Instances, requiring configuration -->
     <scr:component name="factory.component.reference"
         felix:persistentFactoryComponent="true"

Modified: felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml?rev=1615284&r1=1615283&r2=1615284&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml Sat
Aug  2 03:04:11 2014
@@ -36,7 +36,29 @@
         <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
     </scr:component>
     
-    <!-- Component Factory Instances, requiring configuration -->
+    <scr:component name="factory.component.configuration.optional"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional"
+        modified="modified" >
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
+    <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="factory.component.configuration.optional.13"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional.13"
+        modified="modified" >
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
+    <scr:component name="factory.component.configuration.optional.nomodify"
+        enabled="false"
+        configuration-policy="optional"
+        factory="factory.component.factory.configuration.optional.nomodify">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent"
/>
+    </scr:component>
+    
     <scr:component name="factory.component.reference"
         enabled="false"
         configuration-policy="ignore"



Mime
View raw message