felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r884122 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/manager/ test/java/org/apache/felix/scr/integration/ test/java/org/apache/felix/scr/integration/components/ test/resources/
Date Wed, 25 Nov 2009 14:51:22 GMT
Author: fmeschbe
Date: Wed Nov 25 14:51:21 2009
New Revision: 884122

URL: http://svn.apache.org/viewvc?rev=884122&view=rev
Log:
FELIX-1841 Apply DependencyManager part of FELIX-1841.patch.2 supplied by Pierre de Rop (thanks) with the slight modification of guarding the rebind with a configuration setting. Also added integration tests validating this fix.

Added:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java   (with props)
Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
    felix/trunk/scr/src/test/resources/integration_test_simple_components_service_binding.xml

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=884122&r1=884121&r2=884122&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java Wed Nov 25 14:51:21 2009
@@ -171,24 +171,49 @@
                 m_componentManager.log( LogService.LOG_DEBUG, "Dependency Manager: Updating {0}", new Object[]
                     { serviceString }, null );
 
-                // remove the service first
-                // only continue with further event handling if the service
-                // removal did not cause the component to be deactivated
-                if ( serviceRemoved( ref ) )
+                if ( getBoundService( ref ) == null )
                 {
-                    // recalculate the number of services matching the filter
-                    // because we don't know whether this service previously matched
-                    // or not
-                    ServiceReference refs[] = getFrameworkServiceReferences();
-                    m_size = ( refs == null ) ? 0 : refs.length;
-
-                    // now try to bind the service - if it matches the target filter
-                    // without recalculating the size (already done).
+                    // service not currently bound --- what to do ?
+                    // if static
+                    //    if inactive and target match: activate
+                    // if dynamic
+                    //    if multiple and target match: bind
                     if ( targetFilterMatch( ref ) )
                     {
-                        serviceAdded( ref );
+                        // new filter match, so increase the counter
+                        m_size++;
+
+                        if ( isStatic() )
+                        {
+                            // if static reference: activate if currentl unsatisifed, otherwise no influence
+                            if ( m_componentManager.getState() == AbstractComponentManager.STATE_UNSATISFIED )
+                            {
+                                m_componentManager.log( LogService.LOG_INFO,
+                                    "Dependency Manager: Service {0} registered, activate component", new Object[]
+                                        { m_dependencyMetadata.getName() }, null );
+
+                                m_componentManager.activate();
+                            }
+                        }
+                        else if ( isMultiple() )
+                        {
+                            // if dynamic and multiple reference, bind, otherwise ignore
+                            serviceAdded( ref );
+                        }
                     }
                 }
+                else if ( !targetFilterMatch( ref ) )
+                {
+                    // service reference does not match target any more, remove
+                    m_size--;
+                    serviceRemoved( ref );
+                }
+                else if ( "true".equalsIgnoreCase( m_componentManager.getBundle().getBundleContext().getProperty(
+                    "ds.rebind.enabled" ) ) )
+                {
+                    // service is bound, bind again to update reference properties
+                    bind();
+                }
 
                 break;
 
@@ -390,6 +415,7 @@
                 ungetService( reference );
             }
         }
+
         else
         {
             m_componentManager.log( LogService.LOG_DEBUG,

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java?rev=884122&r1=884121&r2=884122&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java Wed Nov 25 14:51:21 2009
@@ -42,113 +42,7 @@
     @Test
     public void test_SimpleComponent_configuration_ignore()
     {
-        test_configuration_ignore( "SimpleComponent" );
-    }
-
-
-    @Test
-    public void test_SimpleComponent_configuration_optional()
-    {
-        test_configuration_optional( "SimpleComponent" );
-    }
-
-
-    @Test
-    public void test_SimpleComponent_configuration_require()
-    {
-        test_configuration_require( "SimpleComponent" );
-    }
-
-
-    @Test
-    public void test_SimpleComponent_dynamic_configuration()
-    {
-        test_dynamic_configuration( "DynamicConfigurationComponent" );
-    }
-
-
-    @Test
-    public void test_SimpleComponent_factory_configuration()
-    {
-        final String factoryPid = "FactoryConfigurationComponent";
-
-        deleteFactoryConfigurations( factoryPid );
-        delay();
-
-        // one single component exists without configuration
-        final Component[] noConfigurations = findComponentsByName( factoryPid );
-        TestCase.assertNotNull( noConfigurations );
-        TestCase.assertEquals( 1, noConfigurations.length );
-        TestCase.assertEquals( Component.STATE_DISABLED, noConfigurations[0].getState() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
-
-        // enable the component, configuration required, hence unsatisfied
-        noConfigurations[0].enable();
-        delay();
-
-        final Component[] enabledNoConfigs = findComponentsByName( factoryPid );
-        TestCase.assertNotNull( enabledNoConfigs );
-        TestCase.assertEquals( 1, enabledNoConfigs.length );
-        TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
-
-        // create two factory configurations expecting two components
-        final String pid0 = createFactoryConfiguration( factoryPid );
-        final String pid1 = createFactoryConfiguration( factoryPid );
-        delay();
-
-        // expect two components, only first is active, second is disabled
-        final Component[] twoConfigs = findComponentsByName( factoryPid );
-        TestCase.assertNotNull( twoConfigs );
-        TestCase.assertEquals( 2, twoConfigs.length );
-        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
-        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[1].getState() );
-        TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
-
-        // enable second component
-        twoConfigs[1].enable();
-        delay();
-
-        // ensure both components active
-        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
-        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
-        TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
-
-        // delete a configuration
-        deleteConfig( pid0 );
-        delay();
-
-        // expect one component
-        final Component[] oneConfig = findComponentsByName( factoryPid );
-        TestCase.assertNotNull( oneConfig );
-        TestCase.assertEquals( 1, oneConfig.length );
-        TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
-        TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
-        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
-
-        // delete second configuration
-        deleteConfig( pid1 );
-        delay();
-
-        // expect a single unsatisfied component
-        final Component[] configsDeleted = findComponentsByName( factoryPid );
-        TestCase.assertNotNull( configsDeleted );
-        TestCase.assertEquals( 1, configsDeleted.length );
-        TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState() );
-        TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
-        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
-    }
-
-
-    private void test_configuration_ignore( final String componentName )
-    {
-        final String pid = componentName + ".configuration.ignore";
+        final String pid = "SimpleComponent.configuration.ignore";
         final Component component = findComponentByName( pid );
 
         deleteConfig( pid );
@@ -189,9 +83,10 @@
     }
 
 
-    private void test_configuration_optional( final String componentName )
+    @Test
+    public void test_SimpleComponent_configuration_optional()
     {
-        final String pid = componentName + ".configuration.optional";
+        final String pid = "SimpleComponent.configuration.optional";
         final Component component = findComponentByName( pid );
 
         deleteConfig( pid );
@@ -241,9 +136,10 @@
     }
 
 
-    private void test_configuration_require( final String componentName )
+    @Test
+    public void test_SimpleComponent_configuration_require()
     {
-        final String pid = componentName + ".configuration.require";
+        final String pid = "SimpleComponent.configuration.require";
         final Component component = findComponentByName( pid );
 
         deleteConfig( pid );
@@ -282,9 +178,10 @@
     }
 
 
-    private void test_dynamic_configuration( final String componentName )
+    @Test
+    public void test_SimpleComponent_dynamic_configuration()
     {
-        final String pid = componentName;
+        final String pid = "DynamicConfigurationComponent";
         final Component component = findComponentByName( pid );
 
         deleteConfig( pid );
@@ -328,4 +225,84 @@
         TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
         TestCase.assertNull( SimpleComponent.INSTANCE );
     }
+
+
+    @Test
+    public void test_SimpleComponent_factory_configuration()
+    {
+        final String factoryPid = "FactoryConfigurationComponent";
+
+        deleteFactoryConfigurations( factoryPid );
+        delay();
+
+        // one single component exists without configuration
+        final Component[] noConfigurations = findComponentsByName( factoryPid );
+        TestCase.assertNotNull( noConfigurations );
+        TestCase.assertEquals( 1, noConfigurations.length );
+        TestCase.assertEquals( Component.STATE_DISABLED, noConfigurations[0].getState() );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
+
+        // enable the component, configuration required, hence unsatisfied
+        noConfigurations[0].enable();
+        delay();
+
+        final Component[] enabledNoConfigs = findComponentsByName( factoryPid );
+        TestCase.assertNotNull( enabledNoConfigs );
+        TestCase.assertEquals( 1, enabledNoConfigs.length );
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
+
+        // create two factory configurations expecting two components
+        final String pid0 = createFactoryConfiguration( factoryPid );
+        final String pid1 = createFactoryConfiguration( factoryPid );
+        delay();
+
+        // expect two components, only first is active, second is disabled
+        final Component[] twoConfigs = findComponentsByName( factoryPid );
+        TestCase.assertNotNull( twoConfigs );
+        TestCase.assertEquals( 2, twoConfigs.length );
+        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
+        TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[1].getState() );
+        TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+
+        // enable second component
+        twoConfigs[1].enable();
+        delay();
+
+        // ensure both components active
+        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
+        TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
+        TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+
+        // delete a configuration
+        deleteConfig( pid0 );
+        delay();
+
+        // expect one component
+        final Component[] oneConfig = findComponentsByName( factoryPid );
+        TestCase.assertNotNull( oneConfig );
+        TestCase.assertEquals( 1, oneConfig.length );
+        TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
+        TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+        TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+
+        // delete second configuration
+        deleteConfig( pid1 );
+        delay();
+
+        // expect a single unsatisfied component
+        final Component[] configsDeleted = findComponentsByName( factoryPid );
+        TestCase.assertNotNull( configsDeleted );
+        TestCase.assertEquals( 1, configsDeleted.length );
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState() );
+        TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+        TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+    }
+
 }

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java?rev=884122&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java Wed Nov 25 14:51:21 2009
@@ -0,0 +1,633 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.integration.components.SimpleComponent;
+import org.apache.felix.scr.integration.components.SimpleServiceImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+
+@RunWith(JUnit4TestRunner.class)
+public class ServiceChangedTest extends ComponentTestBase
+{
+    static
+    {
+        // uncomment to enable debugging of this test class
+        // paxRunnerVmOption = DEBUG_VM_OPTION;
+
+        descriptorFile = "/integration_test_simple_components_service_binding.xml";
+    }
+
+
+    @Test
+    public void test_optional_single_dynamic()
+    {
+        final Component component = findComponentByName( "test_optional_single_dynamic_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // set target to not match any more
+        srv1.setFilterProperty( "don't match" );
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertSame( comp10, comp11 );
+        TestCase.assertNull( comp11.m_singleRef );
+        TestCase.assertTrue( comp11.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertSame( comp10, comp12 );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 2, comp10.m_singleRefBind );
+        TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 2, comp10.m_singleRefBind );
+        TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        TestCase.assertEquals( srv1, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 3, comp10.m_singleRefBind );
+        TestCase.assertEquals( 2, comp10.m_singleRefUnbind);
+    }
+
+
+    @Test
+    public void test_required_single_dynamic()
+    {
+        final Component component = findComponentByName( "test_required_single_dynamic_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // set target to not match any more -> deactivate this component
+        srv1.setFilterProperty( "don't match" );
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp12.m_singleRefBind );
+        TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp12.m_singleRefBind );
+        TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        TestCase.assertEquals( srv1, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 2, comp12.m_singleRefBind );
+        TestCase.assertEquals( 1, comp12.m_singleRefUnbind);
+    }
+
+
+    @Test
+    public void test_optional_multiple_dynamic()
+    {
+        final Component component = findComponentByName( "test_optional_multiple_dynamic_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // set target to not match any more
+        srv1.setFilterProperty( "don't match" );
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertSame( comp10, comp11 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertSame( comp10, comp12 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 2, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 3, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 3, comp10.m_multiRefBind );
+        TestCase.assertEquals( 2, comp10.m_multiRefUnbind);
+    }
+
+
+    @Test
+    public void test_required_multiple_dynamic()
+    {
+        final Component component = findComponentByName( "test_required_multiple_dynamic_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // set target to not match any more
+        srv1.setFilterProperty( "don't match" );
+
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertNull( comp11 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 1, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 2, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 2, comp12.m_multiRefBind );
+        TestCase.assertEquals( 1, comp12.m_multiRefUnbind);
+    }
+
+
+    @Test
+    public void test_optional_single_static()
+    {
+        final Component component = findComponentByName( "test_optional_single_static_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // set target to not match any more -> recreate !
+        srv1.setFilterProperty( "don't match" );
+        delay(); // async reactivation
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp11 );
+        TestCase.assertNull( comp11.m_singleRef );
+        TestCase.assertTrue( comp11.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 0, comp11.m_singleRefBind );
+        TestCase.assertEquals( 0, comp11.m_singleRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertSame( comp11, comp12 );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 0, comp12.m_singleRefBind );
+        TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp13 );
+        TestCase.assertSame( comp11, comp13 );
+        TestCase.assertSame( comp12, comp13 );
+        TestCase.assertNull( comp13.m_singleRef );
+        TestCase.assertTrue( comp13.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 0, comp13.m_singleRefBind );
+        TestCase.assertEquals( 0, comp13.m_singleRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        final SimpleComponent comp14 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp14 );
+        TestCase.assertSame( comp11, comp14 );
+        TestCase.assertSame( comp12, comp14 );
+        TestCase.assertSame( comp13, comp14 );
+        TestCase.assertNull( comp14.m_singleRef );
+        TestCase.assertTrue( comp14.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 0, comp14.m_singleRefBind );
+        TestCase.assertEquals( 0, comp14.m_singleRefUnbind);
+    }
+
+
+    @Test
+    public void test_required_single_static()
+    {
+        final Component component = findComponentByName( "test_required_single_static_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
+
+        // set target to not match any more -> deactivate this component
+        srv1.setFilterProperty( "don't match" );
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp10.m_singleRefBind );
+        TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp12.m_singleRefBind );
+        TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertSame( comp12, comp13 );
+        TestCase.assertEquals( srv2, comp12.m_singleRef );
+        TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp12.m_singleRefBind );
+        TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        delay(); // reactivation required
+        final SimpleComponent comp14 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp14 );
+        TestCase.assertNotSame( comp12, comp14 );
+        TestCase.assertNotSame( comp13, comp14 );
+        TestCase.assertEquals( srv1, comp14.m_singleRef );
+        TestCase.assertTrue( comp14.m_multiRef.isEmpty() );
+        TestCase.assertEquals( 1, comp14.m_singleRefBind );
+        TestCase.assertEquals( 0, comp14.m_singleRefUnbind);
+    }
+
+
+    @Test
+    public void test_optional_multiple_static()
+    {
+        final Component component = findComponentByName( "test_optional_multiple_static_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // set target to not match any more
+        srv1.setFilterProperty( "don't match" );
+        delay(); // async reactivation (for unbind)
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp11 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+        TestCase.assertNull( comp11.m_singleRef );
+        TestCase.assertFalse( comp11.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 0, comp11.m_multiRefBind );
+        TestCase.assertEquals( 0, comp11.m_multiRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding (not expected for an optional static ref)
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertSame( comp11, comp12 );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 0, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 0, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        delay(); // allow reactivation delay (for unbind/bind)
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp13 );
+        TestCase.assertSame( comp11, comp13 );
+        TestCase.assertSame( comp12, comp13 );
+        TestCase.assertNull( comp13.m_singleRef );
+        TestCase.assertFalse( comp13.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp13.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 0, comp13.m_multiRefBind );
+        TestCase.assertEquals( 0, comp13.m_multiRefUnbind);
+    }
+
+
+    @Test
+    public void test_required_multiple_static()
+    {
+        final Component component = findComponentByName( "test_required_multiple_static_target" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+
+        // async enabling
+        component.enable();
+        delay();
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // update a service property
+        srv1.update( "srv1-modified" );
+
+        // no changes in bindings expected
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertTrue( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 0, comp10.m_multiRefUnbind);
+
+        // set target to not match any more
+        srv1.setFilterProperty( "don't match" );
+
+        TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+        final SimpleComponent comp11 = SimpleComponent.INSTANCE;
+        TestCase.assertNull( comp11 );
+        TestCase.assertNull( comp10.m_singleRef );
+        TestCase.assertFalse( comp10.m_multiRef.contains( srv1 ) );
+        TestCase.assertEquals( 1, comp10.m_multiRefBind );
+        TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
+
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
+        delay(); // async binding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp12 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp12 );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 1, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv1 match again, expect not changes in bindings
+        srv1.setFilterProperty( "match" );
+        TestCase.assertNull( comp12.m_singleRef );
+        TestCase.assertFalse( comp12.m_multiRef.contains( srv1 ) );
+        TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 1, comp12.m_multiRefBind );
+        TestCase.assertEquals( 0, comp12.m_multiRefUnbind);
+
+        // make srv2 to not match, expect binding to srv1
+        srv2.setFilterProperty( "don't match" );
+        delay(); // allow reactivation/rebinding
+
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        final SimpleComponent comp13 = SimpleComponent.INSTANCE;
+        TestCase.assertNotSame( comp10, comp13 );
+        TestCase.assertNotSame( comp11, comp13 );
+        TestCase.assertNotSame( comp12, comp13 );
+        TestCase.assertNull( comp13.m_singleRef );
+        TestCase.assertTrue( comp13.m_multiRef.contains( srv1 ) );
+        TestCase.assertFalse( comp13.m_multiRef.contains( srv2 ) );
+        TestCase.assertEquals( 1, comp13.m_multiRefBind );
+        TestCase.assertEquals( 0, comp13.m_multiRefUnbind);
+   }
+}
\ No newline at end of file

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java?rev=884122&r1=884121&r2=884122&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java Wed Nov 25 14:51:21 2009
@@ -51,8 +51,16 @@
 
     public SimpleService m_singleRef;
 
+    public int m_singleRefBind = 0;
+
+    public int m_singleRefUnbind = 0;
+
     public final Set<SimpleService> m_multiRef = new HashSet<SimpleService>();
 
+    public int m_multiRefBind = 0;
+
+    public int m_multiRefUnbind = 0;
+
 
     @SuppressWarnings("unused")
     private void activate( ComponentContext activateContext, Map<?, ?> config )
@@ -132,6 +140,7 @@
     public void setSimpleService( SimpleService simpleService )
     {
         this.m_singleRef = simpleService;
+        this.m_singleRefBind++;
     }
 
 
@@ -142,6 +151,7 @@
         {
             this.m_singleRef = null;
         }
+        this.m_singleRefUnbind++;
     }
 
 
@@ -149,6 +159,7 @@
     public void bindSimpleService( SimpleService simpleService )
     {
         this.m_multiRef.add( simpleService );
+        this.m_multiRefBind++;
     }
 
 
@@ -156,5 +167,6 @@
     public void unbindSimpleService( SimpleService simpleService )
     {
         this.m_multiRef.remove( simpleService );
+        this.m_multiRefUnbind++;
     }
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java?rev=884122&r1=884121&r2=884122&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleServiceImpl.java Wed Nov 25 14:51:21 2009
@@ -29,7 +29,11 @@
 public class SimpleServiceImpl implements SimpleService
 {
 
-    private final String m_value;
+    private String m_value;
+
+    private int m_ranking;
+
+    private String m_filterProp;
 
     private ServiceRegistration m_registration;
 
@@ -42,22 +46,51 @@
 
     public static SimpleServiceImpl create( BundleContext bundleContext, String value, int ranking )
     {
-        SimpleServiceImpl instance = new SimpleServiceImpl( value );
-        Properties props = new Properties();
-        props.put( "value", value );
-        if ( ranking != 0 )
-        {
-            props.put( Constants.SERVICE_RANKING, Integer.valueOf( ranking ) );
-        }
+        SimpleServiceImpl instance = new SimpleServiceImpl( value, ranking );
+        Properties props = instance.getProperties();
         instance.setRegistration( bundleContext.registerService( SimpleService.class.getName(), instance, props ) );
         return instance;
     }
 
 
-    SimpleServiceImpl( String value )
+    SimpleServiceImpl( final String value, final int ranking )
     {
         this.m_value = value;
+        this.m_ranking = ranking;
+        this.m_filterProp = "match";
+    }
+
+
+    private Properties getProperties()
+    {
+        final Properties props = new Properties();
+        props.put( "value", m_value );
+        props.put( "filterprop", m_filterProp );
+        if ( m_ranking != 0 )
+        {
+            props.put( Constants.SERVICE_RANKING, Integer.valueOf( m_ranking ) );
+        }
+        return props;
+    }
 
+
+    public void update( String value )
+    {
+        if ( this.m_registration != null )
+        {
+            this.m_value = value;
+            this.m_registration.setProperties( getProperties() );
+        }
+    }
+
+
+    public void setFilterProperty( String filterProp )
+    {
+        if ( this.m_registration != null )
+        {
+            this.m_filterProp = filterProp;
+            this.m_registration.setProperties( getProperties() );
+        }
     }
 
 
@@ -93,6 +126,6 @@
     @Override
     public String toString()
     {
-        return getClass().getSimpleName() + ": value=" + getValue();
+        return getClass().getSimpleName() + ": value=" + getValue() + ", filterprop=" + m_filterProp;
     }
 }

Modified: felix/trunk/scr/src/test/resources/integration_test_simple_components_service_binding.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_simple_components_service_binding.xml?rev=884122&r1=884121&r2=884122&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_simple_components_service_binding.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_simple_components_service_binding.xml Wed Nov 25 14:51:21 2009
@@ -131,4 +131,127 @@
         />
     </scr:component>
 
+    
+    <!-- Same components as above but using a target spec -->
+
+    <scr:component name="test_optional_single_dynamic_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_required_single_dynamic_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="1..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_optional_multiple_dynamic_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..n"
+            policy="dynamic"
+            bind="bindSimpleService"
+            unbind="unbindSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_required_multiple_dynamic_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="1..n"
+            policy="dynamic"
+            bind="bindSimpleService"
+            unbind="unbindSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+    
+    <scr:component name="test_optional_single_static_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="static"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_required_single_static_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="1..1"
+            policy="static"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_optional_multiple_static_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..n"
+            policy="static"
+            bind="bindSimpleService"
+            unbind="unbindSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
+    <scr:component name="test_required_multiple_static_target"
+        enabled="false"
+        configuration-policy="ignore">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="1..n"
+            policy="static"
+            bind="bindSimpleService"
+            unbind="unbindSimpleService"
+            target="(filterprop=match)"
+        />
+    </scr:component>
+
 </components>



Mime
View raw message