FELIX-1447 Remove ComponentMetadata parameter from AbstractComponentManager.log
method signature because the component metadata is directly available and
does not need to be provided by a parameter.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@800499 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
index 5f4db52..28d4b9d 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
@@ -86,7 +86,7 @@
return options( provision( scanDir( "target" ).filter( "*.jar" ), mavenBundle( "org.ops4j.pax.swissbox",
"pax-swissbox-tinybundles", "1.0.0" ), mavenBundle( "org.apache.felix", "org.apache.felix.configadmin",
"1.0.10" ) )
- // , PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
+// , PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
// PaxRunnerOptions.timeout( 0 )
);
@@ -229,23 +229,31 @@
component.enable();
delay();
+ final SimpleComponent firstInstance = SimpleComponent.INSTANCE;
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
- TestCase.assertNotNull( SimpleComponent.INSTANCE );
- TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertNotNull( firstInstance );
+ TestCase.assertNull( firstInstance.getProperty( PROP_NAME ) );
configure( pid );
delay();
+ final SimpleComponent secondInstance = SimpleComponent.INSTANCE;
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
- TestCase.assertNotNull( SimpleComponent.INSTANCE );
- TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertNotNull( secondInstance );
+ TestCase.assertEquals( PROP_NAME, secondInstance.getProperty( PROP_NAME ) );
+
deleteConfig( pid );
delay();
+ final SimpleComponent thirdInstance = SimpleComponent.INSTANCE;
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
- TestCase.assertNotNull( SimpleComponent.INSTANCE );
- TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertNotNull( thirdInstance );
+ TestCase.assertNull( thirdInstance.getProperty( PROP_NAME ) );
+
+ TestCase.assertNotSame( "Expect new instance object after reconfiguration", firstInstance, secondInstance );
+ TestCase.assertNotSame( "Expect new instance object after configuration deletion (1)", firstInstance, thirdInstance);
+ TestCase.assertNotSame( "Expect new instance object after configuration deletion (2)", secondInstance, thirdInstance);
component.disable();
delay();
@@ -316,6 +324,7 @@
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
final SimpleComponent instance = SimpleComponent.INSTANCE;
@@ -325,6 +334,7 @@
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
deleteConfig( pid );
delay();
@@ -332,6 +342,7 @@
TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+ TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
component.disable();
delay();
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java b/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java
index ad0ecbe..b900190 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/SimpleComponent.java
@@ -22,7 +22,10 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
+
import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
@@ -34,6 +37,8 @@
public static final Map<String, SimpleComponent> INSTANCES = new HashMap<String, SimpleComponent>();
+ public static final Set<SimpleComponent> PREVIOUS_INSTANCES = new HashSet<SimpleComponent>();
+
private Map<?, ?> m_config;
@@ -41,8 +46,21 @@
private void activate( Map<?, ?> config )
{
INSTANCE = this;
- INSTANCES.put( (String) config.get( Constants.SERVICE_PID), this );
+ INSTANCES.put( config.get( Constants.SERVICE_PID ).toString(), this );
setConfig( config );
+
+ if ( PREVIOUS_INSTANCES.contains( this ) )
+ {
+ System.err.println();
+ System.err.println( "An instance has been reused !!!" );
+ System.err.println( "Existing: " + PREVIOUS_INSTANCES );
+ System.err.println( "New : " + this );
+ System.err.println();
+ }
+ else
+ {
+ PREVIOUS_INSTANCES.add( this );
+ }
}
@@ -56,8 +74,9 @@
@SuppressWarnings("unused")
private void deactivate()
{
- INSTANCES.remove( getProperty( Constants.SERVICE_PID ));
+ INSTANCES.remove( getProperty( Constants.SERVICE_PID ).toString() );
INSTANCE = null;
+ setConfig( new HashMap<Object, Object>() );
}
@@ -70,7 +89,7 @@
protected void setConfig( Dictionary<?, ?> config )
{
Map<Object, Object> configMap = new HashMap<Object, Object>();
- for ( Enumeration<?> ce = config.elements(); ce.hasMoreElements(); )
+ for ( Enumeration<?> ce = config.keys(); ce.hasMoreElements(); )
{
Object key = ce.nextElement();
Object value = config.get( key );
diff --git a/scr/src/test/resources/integration_test_simple_components.xml b/scr/src/test/resources/integration_test_simple_components.xml
index 412c810..d6a5af9 100644
--- a/scr/src/test/resources/integration_test_simple_components.xml
+++ b/scr/src/test/resources/integration_test_simple_components.xml
@@ -24,6 +24,7 @@
enabled="false"
configuration-policy="ignore">
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="SimpleComponent.configuration.ignore" />
</scr:component>
<!-- component takes configuration as available -->
@@ -31,6 +32,7 @@
enabled="false"
configuration-policy="optional" >
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="SimpleComponent.configuration.optional" />
</scr:component>
<!-- component requires configuration -->
@@ -38,12 +40,14 @@
enabled="false"
configuration-policy="require" >
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="SimpleComponent.configuration.require" />
</scr:component>
<!-- component dynamically updates configuration -->
<scr:component name="DynamicConfigurationComponent"
enabled="false" modified="configure">
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="DynamicConfigurationComponent" />
</scr:component>
<!-- component instances created by factory configuration -->
@@ -51,6 +55,7 @@
enabled="false"
configuration-policy="require" >
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="FactoryConfigurationComponent" />
</scr:component>
<!-- component is a stupid service to verify non-use of private props -->
@@ -58,6 +63,7 @@
enabled="false" immediate="true"
configuration-policy="ignore" >
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+ <property name="service.pid" value="ServiceComponent" />
<property name="prop.public" value="required" />
<property name=".prop.private" value="private" />
<service>