You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2010/11/10 20:12:46 UTC

svn commit: r1033647 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/ tests/core/factories/ tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ tests/core/factories/src/main/java/org/apache/felix/ipojo...

Author: clement
Date: Wed Nov 10 19:12:46 2010
New Revision: 1033647

URL: http://svn.apache.org/viewvc?rev=1033647&view=rev
Log:
Fix FELIX-2694 Instance state not recomputed after reconfiguration when the instance is stopped

When the instance is stopped, after the reconfiguration the instance is restarted.

Added:
    felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
    felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java
Modified:
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    felix/trunk/ipojo/tests/core/factories/pom.xml
    felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/FactoryTestSuite.java
    felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=1033647&r1=1033646&r2=1033647&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java Wed Nov 10 19:12:46 2010
@@ -1158,12 +1158,17 @@ public class InstanceManager implements 
      * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
      */
     public void reconfigure(Dictionary configuration) {
+    	 m_factory.getLogger().log(Logger.INFO, "Reconfiguring " + getInstanceName());
         for (int i = 0; i < m_handlers.length; i++) {
             m_handlers[i].getHandler().reconfigure(configuration);
         }
         // We synchronized the state computation.
         synchronized (this) {
-            if (m_state == INVALID) {
+        	if (m_state == STOPPED) {
+        		m_factory.getLogger().log(Logger.INFO, "Instance stopped during reconfiguration - Try to restart");
+        		start();
+        	} else if (m_state == INVALID) {
+        		m_factory.getLogger().log(Logger.INFO, "Instance invalid during reconfiguration - Recompute state");
                 // Try to revalidate the instance after reconfiguration
                 for (int i = 0; i < m_handlers.length; i++) {
                     if (m_handlers[i].getState() != VALID) {

Modified: felix/trunk/ipojo/tests/core/factories/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/pom.xml?rev=1033647&r1=1033646&r2=1033647&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/pom.xml (original)
+++ felix/trunk/ipojo/tests/core/factories/pom.xml Wed Nov 10 19:12:46 2010
@@ -1,23 +1,15 @@
-<!--
-	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.
--->
+<!-- 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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 	<parent>
 		<groupId>ipojo.tests</groupId>
 		<artifactId>ipojo.tests</artifactId>
@@ -105,6 +97,23 @@
 					<target>1.4</target>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-junit4osgi-plugin</artifactId>
+				<version>1.1.0-SNAPSHOT</version>
+				<executions>
+					<execution>
+						<goals>
+							<goal>test</goal>
+						</goals>
+						<configuration>
+							<configuration>
+								<org.osgi.http.port>8083</org.osgi.http.port>
+							</configuration>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
 		</plugins>
 	</build>
 </project>

Added: felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java?rev=1033647&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java (added)
+++ felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java Wed Nov 10 19:12:46 2010
@@ -0,0 +1,17 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+public class ReconfigurableSimpleType {
+
+
+	private String prop; // Property.
+
+	public void start () {
+		if (prop == null || prop.equals("KO")) {
+			throw new IllegalStateException("Bad Configuration : " + prop);
+		}
+		System.out.println("OK !!!!");
+	}
+
+
+
+}

Modified: felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/FactoryTestSuite.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/FactoryTestSuite.java?rev=1033647&r1=1033646&r2=1033647&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/FactoryTestSuite.java (original)
+++ felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/FactoryTestSuite.java Wed Nov 10 19:12:46 2010
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -32,7 +32,7 @@ public class FactoryTestSuite {
         ots.addTestSuite(ConfigAdminTest.class);
         ots.addTestSuite(ObedienceTest.class);
         ots.addTestSuite(FactoryProps.class);
-   //     ots.addTestSuite(EmptyArrayTest.class);
+        ots.addTestSuite(ReconfigurationTest.class);
         return ots;
     }
 

Added: felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java?rev=1033647&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java (added)
+++ felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/ReconfigurationTest.java Wed Nov 10 19:12:46 2010
@@ -0,0 +1,49 @@
+package org.apache.felix.ipojo.test.scenarios.factories;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.MissingHandlerException;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+
+public class ReconfigurationTest extends OSGiTestCase {
+
+
+	public void testRevalidationOnREconfiguration() {
+		ComponentFactory factory = (ComponentFactory) Utils.getFactoryByName(getContext(),
+				"org.apache.felix.ipojo.test.scenarios.component.ReconfigurableSimpleType");
+
+		// First inject a configuration triggering an exception of the validate method.
+		Properties props = new Properties();
+		props.put("prop", "KO");
+		ComponentInstance ci = null;
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch (UnacceptableConfiguration e) {
+			e.printStackTrace();
+		} catch (MissingHandlerException e) {
+			e.printStackTrace();
+		} catch (ConfigurationException e) {
+			e.printStackTrace();
+		}
+
+		assertNotNull(ci);
+		assertEquals("instance invalid", ComponentInstance.STOPPED, ci.getState());
+
+		// Reconfigure
+		props = new Properties();
+		props.put("prop", "OK");
+
+		ci.reconfigure(props);
+
+		assertNotNull(ci);
+		assertEquals("instance valid", ComponentInstance.VALID, ci.getState());
+	}
+
+
+
+}

Modified: felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml?rev=1033647&r1=1033646&r2=1033647&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml Wed Nov 10 19:12:46 2010
@@ -1,5 +1,5 @@
 <ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="org.apache.felix.ipojo hhttp://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd" 
+	xsi:schemaLocation="org.apache.felix.ipojo hhttp://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd"
 	xmlns="org.apache.felix.ipojo">
 	<!-- Simple provider  -->
 	<component
@@ -7,14 +7,14 @@
 		name="Factories-FooProviderType-1" architecture="true">
 		<provides />
 	</component>
-	
+
 	<!-- Provider providing 2 services -->
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1"
 		name="Factories-FooBarProviderType-1" architecture="true">
 		<provides />
 	</component>
-	
+
 	<!-- Provider with dynamic property -->
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
@@ -28,7 +28,7 @@
 			<property name="intAProp" field="intAProp" value="{ 1,2,3}" mandatory="true"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"
 		name="Factories-FooProviderType-Dynopt" architecture="true">
@@ -41,7 +41,7 @@
 			<property name="intAProp" field="intAProp" value="{ 1,2,3}"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
 		name="Factories-FooProviderType-2" architecture="true">
@@ -54,7 +54,7 @@
 			<property name="intAProp" type="int[]" value="{1,2,3}" mandatory="true"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
 		name="Factories-FooProviderType-2opt" architecture="true">
@@ -67,7 +67,7 @@
 			<property name="intAProp" type="int[]" value="{1,2,3}"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"
 		name="Factories-FooProviderType-Dyn2" architecture="true">
@@ -80,7 +80,7 @@
 				value="{1, 2,3 }" mandatory="true"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"
 		name="Factories-FooProviderType-Dyn2opt" architecture="true">
@@ -93,7 +93,7 @@
 				value="{1, 2,3 }"/>
 		</provides>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
 		name="Factories-FooProviderType-3" architecture="true">
@@ -107,7 +107,7 @@
 			<property name="bar" field="m_bar" mandatory="true"/>
 		</properties>
 	</component>
-	
+
 	<component
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
 		name="Factories-FooProviderType-3opt" architecture="true">
@@ -121,11 +121,18 @@
 			<property name="bar" field="m_bar"/>
 		</properties>
 	</component>
-	
+
 	<!-- type & instance used to check instance lifecycle against factory validation & invalidation -->
 	<component classname="org.apache.felix.ipojo.test.scenarios.component.SimpleType" architecture="true">
 		<controller field="m_controller"/>
 	</component>
 	<instance component="org.apache.felix.ipojo.test.scenarios.component.SimpleType" name="SimpleInstance"/>
-	
+
+	<!-- check that instance state is recomputed after reconfiguration -->
+	<component classname="org.apache.felix.ipojo.test.scenarios.component.ReconfigurableSimpleType" architecture="true">
+		<properties>
+			<property name="prop" field="prop"/>
+		</properties>
+		<callback transition="validate" method="start"/>
+	</component>
 </ipojo>