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 2013/09/26 19:51:20 UTC

svn commit: r1526626 [1/3] - in /felix/trunk/ipojo: manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/ manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/ manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manip...

Author: clement
Date: Thu Sep 26 17:51:18 2013
New Revision: 1526626

URL: http://svn.apache.org/r1526626
Log:
Fix FELIX-4240 and FELIX-4242:
FELIX-4240 Support the 'exception' attribute in service dependencies
FELIX-4242 Support the 'timeout' attribute in service dependencies

Added:
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/ExceptionAwareCheckServiceProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/NoServiceException.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/timeout/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/TestDependenciesWithExceptions.java
      - copied, changed from r1526161, felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/   (with props)
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/pom.xml
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CheckServiceProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CollectionCheckServiceProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/FooProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/MultipleCheckServiceProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/NullableFooProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/CheckService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/FooService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/resources/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/resources/metadata.xml
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/main/resources/metadata.xml
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/Common.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/DefaultImplementationTest.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/DelayTest.java
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/DelayTest.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/DelayedProvider.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/EmptyTest.java
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/EmptyTest.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/NullTest.java
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/NullTest.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/NullableTest.java
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/NullableTest.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/test/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/TimeoutTest.java
      - copied, changed from r1526161, felix/trunk/ipojo/handler/temporal/temporal-dependency-handler-it/src/it/temporal-it/src/test/java/org/apache/felix/ipojo/handler/temporal/test/TemporalTest.java
Modified:
    felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
    felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/core.xsd
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/resources/xsd/core.xsd
    felix/trunk/ipojo/runtime/core-it/pom.xml
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
    felix/trunk/ipojo/runtime/core/src/main/resources/core.xsd
    felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/handlers/dependency/SmartProxyTest.java

Modified: felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java?rev=1526626&r1=1526625&r2=1526626&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java (original)
+++ felix/trunk/ipojo/manipulator/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java Thu Sep 26 17:51:18 2013
@@ -64,6 +64,13 @@ public @interface Requires {
     Class defaultimplementation() default Class.class;
 
     /**
+     * Set the exception to throw when the service is not available. This attribute can only be used for optional
+     * dependencies. It must be a subclass of {@link RuntimeException}.
+     * Default: no exception.
+     */
+    Class<? extends RuntimeException> exception() default RuntimeException.class;
+
+    /**
      * Set the binding policy.
      * Acceptable policy are dynamic, static and dynamic-priority.
      * Default: dynamic.
@@ -93,4 +100,13 @@ public @interface Requires {
      * Default: true
      */
     boolean proxy() default true;
+
+
+    /**
+     * Set the time to wait before applying the 'no service available' action.
+     * This attribute is only valid for optional dependencies.
+     * The time is set in milliseconds.
+     * Default: no timeout
+     */
+    int timeout() default -1;
 }

Modified: felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/core.xsd
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/core.xsd?rev=1526626&r1=1526625&r2=1526626&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/core.xsd (original)
+++ felix/trunk/ipojo/manipulator/ipojo-ant-task/src/main/resources/META-INF/xsd/core.xsd Thu Sep 26 17:51:18 2013
@@ -299,6 +299,26 @@
                     </xs:annotation>
                 </xs:attribute>
 
+                <xs:attribute name="exception" type="xs:string" use="optional">
+                    <xs:annotation>
+                        <xs:documentation>Specifies the exception to throw for an optional service
+                            dependency. If no providers are found, iPOJO creates an instance of the
+                            exception (with either no parameter or a String parameter as constructor argument), and
+                            throws it. The given class name must extends RuntimeException.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+
+                <xs:attribute name="timeout" type="xs:int" use="optional">
+                    <xs:annotation>
+                        <xs:documentation>Specifies the timeout after which the 'no service policy' is executed
+                            (nullable, null, empty collection, exception...). The value is the time in millisecond to
+                            wait. -1 is used to indicate an infinite wait, 0 executes the no service policy
+                            immediately.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+
                 <xs:attribute name="from" type="xs:string" use="optional">
                     <xs:annotation>
                         <xs:documentation>Specific service provider. The dependency can only be fulfilled by the

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java?rev=1526626&r1=1526625&r2=1526626&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/RequiresVisitor.java Thu Sep 26 17:51:18 2013
@@ -72,6 +72,11 @@ public class RequiresVisitor extends Emp
     private String m_defaultImplementation;
 
     /**
+     * Exception attribute.
+     */
+    private String m_exception;
+
+    /**
      * Enable or Disable Nullable pattern.
      */
     private String m_nullable;
@@ -92,6 +97,11 @@ public class RequiresVisitor extends Emp
     private String m_proxy;
 
     /**
+     * Timeout attribute.
+     */
+    private String m_timeout;
+
+    /**
      * Constructor.
      * @param name : field name.
      */
@@ -128,6 +138,11 @@ public class RequiresVisitor extends Emp
             m_defaultImplementation = type.getClassName();
             return;
         }
+        if (name.equals("exception")) {
+            Type type = Type.getType(value.toString());
+            m_exception = type.getClassName();
+            return;
+        }
         if (name.equals("specification")) {
             m_specification = value.toString();
             return;
@@ -148,6 +163,9 @@ public class RequiresVisitor extends Emp
         if (name.equals("proxy")) {
             m_proxy = value.toString();
         }
+        if (name.equals("timeout")) {
+            m_timeout = value.toString();
+        }
     }
 
     /**
@@ -183,6 +201,9 @@ public class RequiresVisitor extends Emp
         if (m_defaultImplementation != null) {
             requires.addAttribute(new Attribute("default-implementation", m_defaultImplementation));
         }
+        if (m_exception != null) {
+            requires.addAttribute(new Attribute("exception", m_exception));
+        }
         if (m_policy != null) {
             requires.addAttribute(new Attribute("policy", m_policy));
         }
@@ -198,6 +219,9 @@ public class RequiresVisitor extends Emp
         if (m_proxy != null) {
             requires.addAttribute(new Attribute("proxy", m_proxy));
         }
+        if (m_timeout != null) {
+            requires.addAttribute(new Attribute("timeout", m_timeout));
+        }
 
         if (m_id != null) {
             workbench.getIds().put(m_id, requires);

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/resources/xsd/core.xsd
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/resources/xsd/core.xsd?rev=1526626&r1=1526625&r2=1526626&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/resources/xsd/core.xsd (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/resources/xsd/core.xsd Thu Sep 26 17:51:18 2013
@@ -299,6 +299,26 @@
                     </xs:annotation>
                 </xs:attribute>
 
+                <xs:attribute name="exception" type="xs:string" use="optional">
+                    <xs:annotation>
+                        <xs:documentation>Specifies the exception to throw for an optional service
+                            dependency. If no providers are found, iPOJO creates an instance of the
+                            exception (with either no parameter or a String parameter as constructor argument), and
+                            throws it. The given class name must extends RuntimeException.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+
+                <xs:attribute name="timeout" type="xs:int" use="optional">
+                    <xs:annotation>
+                        <xs:documentation>Specifies the timeout after which the 'no service policy' is executed
+                            (nullable, null, empty collection, exception...). The value is the time in millisecond to
+                            wait. -1 is used to indicate an infinite wait, 0 executes the no service policy
+                            immediately.
+                        </xs:documentation>
+                    </xs:annotation>
+                </xs:attribute>
+
                 <xs:attribute name="from" type="xs:string" use="optional">
                     <xs:annotation>
                         <xs:documentation>Specific service provider. The dependency can only be fulfilled by the

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/ExceptionAwareCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/ExceptionAwareCheckServiceProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/ExceptionAwareCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/ExceptionAwareCheckServiceProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.ipojo.runtime.core.test.components.exceptions;
+
+import org.apache.felix.ipojo.annotations.Bind;
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.Properties;
+
+/**
+ * A component supporting exception when no services are available.
+ */
+@Component
+@Provides
+public class ExceptionAwareCheckServiceProvider implements CheckService {
+
+    @Requires(id="foo", optional = true, exception = NoServiceException.class)
+    private FooService fs;
+    private int bind;
+    private int unbind;
+
+    @Bind(id = "foo")
+    public void bindFoo(FooService fs) {
+        if (fs != null) {
+            bind++;
+        }
+    }
+
+    public void unbindFoo(FooService fs) {
+        if (fs != null) {
+            unbind++;
+        }
+    }
+
+    @Override
+    public boolean check() {
+        try {
+            fs.foo();
+            return true; // always return true, to detect the exception case.
+        } catch (NoServiceException e) {
+            return true;
+        }
+    }
+
+    @Override
+    public Properties getProps() {
+        Properties properties = new Properties();
+        properties.put("bind", bind);
+        properties.put("unbind", unbind);
+        return properties;
+    }
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/NoServiceException.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/NoServiceException.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/NoServiceException.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/exceptions/NoServiceException.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.ipojo.runtime.core.test.components.exceptions;
+
+/**
+ * Class used to test the 'exception' attribute.
+ */
+public class NoServiceException extends RuntimeException {
+
+    public NoServiceException(String message) {
+        super(message);
+    }
+
+}

Copied: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/TestDependenciesWithExceptions.java (from r1526161, felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/TestDependenciesWithExceptions.java?p2=felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/TestDependenciesWithExceptions.java&p1=felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java&r1=1526161&r2=1526626&rev=1526626&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/di/TestOptionalDependencies.java (original)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-optional-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/exceptions/TestDependenciesWithExceptions.java Thu Sep 26 17:51:18 2013
@@ -16,54 +16,46 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.ipojo.runtime.core.test.dependencies.di;
+
+package org.apache.felix.ipojo.runtime.core.test.dependencies.exceptions;
 
 import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.architecture.Architecture;
-import org.apache.felix.ipojo.architecture.InstanceDescription;
 import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
 import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.osgi.framework.ServiceReference;
 
 import java.util.Properties;
 
-import static org.junit.Assert.*;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-public class TestOptionalDependencies extends Common {
+/**
+ * Checks the behavior of the exception attribute.
+ */
+public class TestDependenciesWithExceptions extends Common {
 
-    ComponentInstance instance1, instance2, instance3, instance4, instance5;
-    ComponentInstance fooProvider;
+    ComponentInstance consumer;
+    ComponentInstance provider;
 
     @Before
     public void setUp() {
         try {
             Properties prov = new Properties();
             prov.put("instance.name", "FooProvider");
-            fooProvider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
-            fooProvider.stop();
+            provider = ipojoHelper.getFactory("FooProviderType-1").createComponentInstance(prov);
+            provider.stop();
 
             Properties i1 = new Properties();
-            i1.put("instance.name", "Simple");
-            instance1 = ipojoHelper.getFactory("DISimpleOptionalCheckServiceProvider").createComponentInstance(i1);
-
-            Properties i2 = new Properties();
-            i2.put("instance.name", "Void");
-            instance2 = ipojoHelper.getFactory("DIVoidOptionalCheckServiceProvider").createComponentInstance(i2);
-
-            Properties i3 = new Properties();
-            i3.put("instance.name", "Object");
-            instance3 = ipojoHelper.getFactory("DIObjectOptionalCheckServiceProvider").createComponentInstance(i3);
-
-            Properties i4 = new Properties();
-            i4.put("instance.name", "Ref");
-            instance4 = ipojoHelper.getFactory("DIRefOptionalCheckServiceProvider").createComponentInstance(i4);
-
-            Properties i5 = new Properties();
-            i5.put("instance.name", "Both");
-            instance5 = ipojoHelper.getFactory("DIBothOptionalCheckServiceProvider").createComponentInstance(i5);
+            i1.put("instance.name", "Consumer");
+            consumer = ipojoHelper
+                    .getFactory("org.apache.felix.ipojo.runtime.core.test.components.exceptions.ExceptionAwareCheckServiceProvider")
+                    .createComponentInstance(i1);
         } catch (Exception e) {
             fail(e.getMessage());
         }
@@ -71,328 +63,32 @@ public class TestOptionalDependencies ex
 
     @After
     public void tearDown() {
-        instance1.dispose();
-        instance2.dispose();
-        instance3.dispose();
-        instance4.dispose();
-        instance5.dispose();
-        fooProvider.dispose();
-        instance1 = null;
-        instance2 = null;
-        instance3 = null;
-        instance4 = null;
-        instance5 = null;
-        fooProvider = null;
-    }
-
-    @Test
-    public void testSimple() {
-        ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
-        assertNotNull("Check architecture availability", arch_ref);
-        InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
-
-        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
-        assertNotNull("Check CheckService availability", cs_ref);
-        CheckService cs = (CheckService) getContext().getService(cs_ref);
-        Properties props = cs.getProps();
-
-        //Check properties
-        assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
-        assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
-        assertNull("Check FS invocation (object) - 1", props.get("object"));
-        assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 5);
-        assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 5);
-        assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 5.0, 0);
-
-        fooProvider.start();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
-
-        assertNotNull("Check CheckService availability", cs_ref);
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-
-        //Check properties
-        assertTrue("check CheckService invocation - 2", ((Boolean) props.get("result")).booleanValue()); // True, a provider is there
-        assertEquals("check void bind invocation - 2", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation - 2", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation - 2", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation - 2", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation - 2", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation - 2", ((Integer) props.get("refU")).intValue(), 0);
-        assertNotNull("Check FS invocation (object) - 2", props.get("object"));
-        assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
-        assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
-        assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
-
-        fooProvider.stop();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
-
-        id = null;
-        cs = null;
-        getContext().ungetService(arch_ref);
-        getContext().ungetService(cs_ref);
-    }
-
-    @Test
-    public void testVoid() {
-        ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
-        assertNotNull("Check architecture availability", arch_ref);
-        InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
-
-        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
-        assertNotNull("Check CheckService availability", cs_ref);
-        CheckService cs = (CheckService) getContext().getService(cs_ref);
-        Properties props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation - 1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
-        assertEquals("check void bind invocation - 1", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation - 1", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation - 1", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation - 1", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation - 1", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation - 1", ((Integer) props.get("refU")).intValue(), 0);
-        assertNull("Check FS invocation (object) - 1", props.get("object"));
-        assertEquals("Check FS invocation (int) - 1", ((Integer) props.get("int")).intValue(), 5);
-        assertEquals("Check FS invocation (long) - 1", ((Long) props.get("long")).longValue(), 5);
-        assertEquals("Check FS invocation (double) - 1", ((Double) props.get("double")).doubleValue(), 5.0, 0);
-
-        fooProvider.start();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
-
-        assertNotNull("Check CheckService availability", cs_ref);
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 1);
-        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
-        assertNotNull("Check FS invocation (object) - 2", props.get("object"));
-        assertEquals("Check FS invocation (int) - 2", ((Integer) props.get("int")).intValue(), 1);
-        assertEquals("Check FS invocation (long) - 2", ((Long) props.get("long")).longValue(), 1);
-        assertEquals("Check FS invocation (double) - 2", ((Double) props.get("double")).doubleValue(), 1.0, 0);
-
-        fooProvider.stop();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
-
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 1);
-        assertEquals("check void unbind callback invocation -3 (" + ((Integer) props.get("voidU")) + ")", ((Integer) props.get("voidU")).intValue(), 1);
-        assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
-        assertNull("Check FS invocation (object) - 3", props.get("object"));
-        assertEquals("Check FS invocation (int) - 3", ((Integer) props.get("int")).intValue(), 5);
-        assertEquals("Check FS invocation (long) - 3", ((Long) props.get("long")).longValue(), 5);
-        assertEquals("Check FS invocation (double) - 3", ((Double) props.get("double")).doubleValue(), 5.0, 0);
-
-        id = null;
-        cs = null;
-        getContext().ungetService(arch_ref);
-        getContext().ungetService(cs_ref);
+        consumer.dispose();
+        provider.dispose();
+        consumer = null;
+        provider = null;
     }
 
+    /**
+     * A simple test checking that the exception is thrown.
+     */
     @Test
-    public void testObject() {
-        ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
-        assertNotNull("Check architecture availability", arch_ref);
-        InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
-
-        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
-        assertNotNull("Check CheckService availability", cs_ref);
-        CheckService cs = (CheckService) getContext().getService(cs_ref);
-        Properties props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
-        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
-
-        fooProvider.start();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
-
-        assertNotNull("Check CheckService availability", cs_ref);
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -2 (" + ((Integer) props.get("objectB")).intValue() + ")", ((Integer) props.get("objectB")).intValue(), 1);
-        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
-
-        fooProvider.stop();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
-
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 1);
-        assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 1);
-        assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
-
-        id = null;
-        cs = null;
-        getContext().ungetService(arch_ref);
-        getContext().ungetService(cs_ref);
-    }
+    public void testExceptionWhenServiceUnavailable() {
+        assertNull(osgiHelper.getServiceObject(FooService.class));
+        osgiHelper.waitForService(CheckService.class, "(instance.name=" + consumer.getInstanceName() + ")", 1000);
+        CheckService cs = osgiHelper.getServiceObject(CheckService.class,
+                "(instance.name=" + consumer.getInstanceName()+")");
+        assertNotNull(cs);
+
+        // the exception is caught by the implementation, and false is returned.
+        assertFalse(cs.check());
+
+        // we start the provider.
+        provider.start();
+        assertNotNull(osgiHelper.getServiceObject(FooService.class));
 
-    @Test
-    public void testRef() {
-        ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
-        assertNotNull("Check architecture availability", arch_ref);
-        InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
-
-        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
-        assertNotNull("Check CheckService availability", cs_ref);
-        CheckService cs = (CheckService) getContext().getService(cs_ref);
-        Properties props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
-        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -1", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -1", ((Integer) props.get("refU")).intValue(), 0);
-
-        fooProvider.start();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
-
-        assertNotNull("Check CheckService availability", cs_ref);
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 1);
-        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
-
-        fooProvider.stop();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
-
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 1);
-        assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 1);
-
-        id = null;
-        cs = null;
-        getContext().ungetService(arch_ref);
-        getContext().ungetService(cs_ref);
-    }
-
-    @Test
-    public void testBoth() {
-        ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance5.getInstanceName());
-        assertNotNull("Check architecture availability", arch_ref);
-        InstanceDescription id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
-
-        ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance5.getInstanceName());
-        assertNotNull("Check CheckService availability", cs_ref);
-        CheckService cs = (CheckService) getContext().getService(cs_ref);
-        Properties props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -1", ((Boolean) props.get("result")).booleanValue()); // False is returned (nullable)
-        assertEquals("check void bind invocation -1", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -1", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -1", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -1", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check both bind callback invocation -1", ((Integer) props.get("bothB")).intValue(), 0);
-        assertEquals("check both unbind callback invocation -1", ((Integer) props.get("bothU")).intValue(), 0);
-
-        fooProvider.start();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 2", id.getState() == ComponentInstance.VALID);
-
-        assertNotNull("Check CheckService availability", cs_ref);
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertTrue("check CheckService invocation -2", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -2", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -2", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -2", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -2", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -2", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -2", ((Integer) props.get("refU")).intValue(), 0);
-        assertEquals("check both bind callback invocation -2", ((Integer) props.get("bothB")).intValue(), 1);
-        assertEquals("check both unbind callback invocation -2", ((Integer) props.get("bothU")).intValue(), 0);
-
-        fooProvider.stop();
-
-        id = ((Architecture) getContext().getService(arch_ref)).getInstanceDescription();
-        assertTrue("Check instance validity - 3", id.getState() == ComponentInstance.VALID);
-
-        cs = (CheckService) getContext().getService(cs_ref);
-        props = cs.getProps();
-        //Check properties
-        assertFalse("check CheckService invocation -3", ((Boolean) props.get("result")).booleanValue());
-        assertEquals("check void bind invocation -3", ((Integer) props.get("voidB")).intValue(), 0);
-        assertEquals("check void unbind callback invocation -3", ((Integer) props.get("voidU")).intValue(), 0);
-        assertEquals("check object bind callback invocation -3", ((Integer) props.get("objectB")).intValue(), 0);
-        assertEquals("check object unbind callback invocation -3", ((Integer) props.get("objectU")).intValue(), 0);
-        assertEquals("check ref bind callback invocation -3", ((Integer) props.get("refB")).intValue(), 0);
-        assertEquals("check ref unbind callback invocation -3", ((Integer) props.get("refU")).intValue(), 0);
-        assertEquals("check both bind callback invocation -3", ((Integer) props.get("bothB")).intValue(), 1);
-        assertEquals("check both unbind callback invocation -3", ((Integer) props.get("bothU")).intValue(), 1);
-
-        id = null;
-        cs = null;
-        getContext().ungetService(arch_ref);
-        getContext().ungetService(cs_ref);
+        // This time everything is fine.
+        assertTrue(cs.check());
     }
 
 

Propchange: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 26 17:51:18 2013
@@ -0,0 +1,2 @@
+target
+ipojo-core-service-dependency-timeout-test.iml

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/pom.xml?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/pom.xml (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/pom.xml Thu Sep 26 17:51:18 2013
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>org.apache.felix.ipojo.runtime.core-it</artifactId>
+        <version>1.10.2-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>ipojo-core-service-dependency-timeout-test</artifactId>
+    <version>1.10.2-SNAPSHOT</version>
+    <name>${project.artifactId}</name>
+    
+</project>
\ No newline at end of file

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CheckServiceProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CheckServiceProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CheckServiceProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.components;
+
+import org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.*;
+
+import java.util.Properties;
+
+public class CheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private FooService fs;
+
+    public boolean check() {
+        return fs != null && fs.foo();
+    }
+
+    public Properties getProps() {
+        if (fs != null) {
+            return fs.fooProps();
+        }
+        return null;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CollectionCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CollectionCheckServiceProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CollectionCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/CollectionCheckServiceProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.components;
+
+import org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.*;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+public class CollectionCheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private Collection<FooService> fs;
+
+    public boolean check() {
+        boolean result = true;
+        //Use a local variable to avoid to wait at each access.
+        Collection<FooService> col = fs;
+        if (col  != null) {
+            for (FooService svc : col) {
+                result = result && svc.foo();
+            }
+        }        
+        return result;
+    }
+
+    public Properties getProps() {
+        Iterator<FooService> it = fs.iterator();
+        if (it.hasNext()) {
+            FooService svc = it.next();
+            return svc.fooProps();
+        }
+        return null;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/FooProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/FooProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/FooProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/FooProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.components;
+
+import org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.FooService;
+
+import java.util.Properties;
+
+public class FooProvider implements FooService {
+
+    public boolean foo() {
+       return true;
+    }
+
+    public Properties fooProps() {
+        return null;
+    }
+
+    public boolean getBoolean() {
+        return false;
+    }
+
+    public double getDouble() {
+        return 0;
+    }
+
+    public int getInt() {
+        return 0;
+    }
+
+    public long getLong() {
+        return 0;
+    }
+
+    public Boolean getObject() {
+        return null;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/MultipleCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/MultipleCheckServiceProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/MultipleCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/MultipleCheckServiceProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.components;
+
+
+import java.util.Properties;
+import org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.*;
+
+public class MultipleCheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private FooService[] fs;
+
+    public boolean check() {
+        boolean result = true;
+        //Use a local variable to avoid to wait at each access.
+        FooService[] array = fs;
+        for (int i = 0; array != null && i < array.length; i++) {
+            result = result && array[i].foo();
+            System.out.println("Result : " + result);
+        }
+        return result;
+    }
+
+    public Properties getProps() {
+        return fs[0].fooProps();
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/NullableFooProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/NullableFooProvider.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/NullableFooProvider.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/components/NullableFooProvider.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.components;
+
+import org.apache.felix.ipojo.runtime.test.dependencies.timeout.services.*;
+
+import java.util.Properties;
+
+public class NullableFooProvider implements FooService {
+
+    public boolean foo() {
+       return false;
+    }
+
+    public Properties fooProps() {
+        return null;
+    }
+
+    public boolean getBoolean() {
+        return false;
+    }
+
+    public double getDouble() {
+        return -1;
+    }
+
+    public int getInt() {
+        return -1;
+    }
+
+    public long getLong() {
+        return -1;
+    }
+
+    public Boolean getObject() {
+        return null;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/CheckService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/CheckService.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/CheckService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/CheckService.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.services;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+	public boolean check();
+	
+	public Properties getProps();
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/FooService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/FooService.java?rev=1526626&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/FooService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-timeout-test/src/main/java/org/apache/felix/ipojo/runtime/test/dependencies/timeout/services/FooService.java Thu Sep 26 17:51:18 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.ipojo.runtime.test.dependencies.timeout.services;
+
+import java.util.Properties;
+
+public interface FooService {
+
+	boolean foo();
+	
+	Properties fooProps();
+	
+	Boolean getObject();
+	
+	boolean getBoolean();
+	
+	int getInt();
+	
+	long getLong();
+	
+	double getDouble();
+	
+}