Author: not Date: Fri Mar 18 09:28:43 2011 New Revision: 1082858 URL: http://svn.apache.org/viewvc?rev=1082858&view=rev Log: ARIES-612 A test that makes sure you can call a reference in a destroy method. It will blow up if something goes wrong.
Added: aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java (with props) Modified: aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java aries/trunk/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml Modified: aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java?rev=1082858&r1=1082857&r2=1082858&view=diff ============================================================================== --- aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java (original) +++ aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestReferences.java Fri Mar 18 09:28:43 2011 @@ -32,6 +32,7 @@ import java.util.List; import org.apache.aries.blueprint.sample.BindingListener; import org.apache.aries.blueprint.sample.DefaultRunnable; +import org.apache.aries.blueprint.sample.DestroyTest; import org.apache.aries.blueprint.sample.InterfaceA; import org.apache.aries.unittest.mocks.MethodCall; import org.apache.aries.unittest.mocks.Skeleton; @@ -39,6 +40,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.ServiceRegistration; import org.osgi.service.blueprint.container.BlueprintContainer; @@ -155,6 +157,35 @@ public class TestReferences extends Abst assertEquals("The default runnable was not called", 2, defaultRunnable.getCount()); } + + @Test + public void testReferencesCallableInDestroy() throws Exception { + bundleContext.registerService(Runnable.class.getName(), new Thread(), null); + + BlueprintContainer blueprintContainer = getBlueprintContainerForBundle("org.apache.aries.blueprint.sample"); + assertNotNull(blueprintContainer); + + DestroyTest dt = (DestroyTest) blueprintContainer.getComponentInstance("destroyCallingReference"); + + Bundle b = findBundle("org.apache.aries.blueprint.sample"); + assertNotNull(b); + b.stop(); + + assertTrue("The destroy method was called", dt.waitForDestruction(1000)); + + Exception e = dt.getDestroyFailure(); + + if (e != null) throw e; + } + + private Bundle findBundle(String bsn) + { + for (Bundle b : bundleContext.getBundles()) { + if (bsn.equals(b.getSymbolicName())) return b; + } + + return null; + } @org.ops4j.pax.exam.junit.Configuration public static Option[] configuration() { Added: aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java?rev=1082858&view=auto ============================================================================== --- aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java (added) +++ aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java Fri Mar 18 09:28:43 2011 @@ -0,0 +1,64 @@ +/* + * 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 WARRANTIESOR 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.aries.blueprint.sample; + +public class DestroyTest +{ + private Runnable target; + private Exception destroyFailure; + private boolean destroyed; + + public void setTarget(Runnable r) + { + target = r; + } + + public Exception getDestroyFailure() + { + return destroyFailure; + } + + public void destroy() + { + try { + target.run(); + } catch (Exception e) { + destroyFailure = e; + } + + synchronized (this) { + destroyed = true; + notifyAll(); + } + } + + public synchronized boolean waitForDestruction(int timeout) + { + long startTime = System.currentTimeMillis(); + + while (!!!destroyed && System.currentTimeMillis() - startTime < timeout) { + try { + wait(100); + } catch (InterruptedException e) { + } + } + + return destroyed; + } +} \ No newline at end of file Propchange: aries/trunk/blueprint/blueprint-sample/src/main/java/org/apache/aries/blueprint/sample/DestroyTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: aries/trunk/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml?rev=1082858&r1=1082857&r2=1082858&view=diff ============================================================================== --- aries/trunk/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml (original) +++ aries/trunk/blueprint/blueprint-sample/src/main/resources/OSGI-INF/blueprint/config.xml Fri Mar 18 09:28:43 2011 @@ -93,6 +93,10 @@ </list> </property> </bean> + + <bean id="destroyCallingReference" class="org.apache.aries.blueprint.sample.DestroyTest" destroy-method="destroy"> + <property name="target" ref="refWithDefault"/> + </bean> <service ref="foo" auto-export="all-classes"> <service-properties>