You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2009/04/28 04:56:19 UTC
svn commit: r769225 - in /geronimo/sandbox/blueprint/blueprint-core/src:
main/java/org/apache/geronimo/blueprint/context/
test/java/org/apache/geronimo/blueprint/
test/java/org/apache/geronimo/blueprint/pojos/ test/resources/
Author: gawor
Date: Tue Apr 28 02:56:18 2009
New Revision: 769225
URL: http://svn.apache.org/viewvc?rev=769225&view=rev
Log:
improved/added some dependency tests
Added:
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java (with props)
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java (with props)
Modified:
geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml
Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java?rev=769225&r1=769224&r2=769225&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/BlueprintObjectRepository.java Tue Apr 28 02:56:18 2009
@@ -17,10 +17,10 @@
*/
package org.apache.geronimo.blueprint.context;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import java.util.ListIterator;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -83,9 +83,12 @@
}
public void destroy() {
- for (Destroyable destroyable : destroyList) {
- destroyable.destroy();
+ // destroy objects in reverse creation order
+ ListIterator<DestroyCallback> reverse = destroyList.listIterator(destroyList.size());
+ while(reverse.hasPrevious()) {
+ reverse.previous().destroy();
}
+
destroyList.clear();
instances.clear();
}
Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java?rev=769225&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java Tue Apr 28 02:56:18 2009
@@ -0,0 +1,66 @@
+/*
+ * 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.geronimo.blueprint;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CallbackTracker {
+
+ private static List<Callback> callbacks = new ArrayList<Callback>();
+
+ public static void add(Callback callback) {
+ callbacks.add(callback);
+ }
+
+ public static List<Callback> getCallbacks() {
+ return callbacks;
+ }
+
+ public static void clear() {
+ callbacks.clear();
+ }
+
+ public static class Callback {
+
+ public static int INIT = 1;
+ public static int DESTROY = 2;
+
+ private Object object;
+ private int type;
+
+ public Callback(int type, Object object) {
+ this.type = type;
+ this.object = object;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public String toString() {
+ return type + " " + object;
+ }
+
+ }
+}
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/CallbackTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java?rev=769225&r1=769224&r2=769225&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/WiringTest.java Tue Apr 28 02:56:18 2009
@@ -20,8 +20,11 @@
import java.math.BigInteger;
import java.net.URI;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.geronimo.blueprint.CallbackTracker.Callback;
import org.apache.geronimo.blueprint.context.BlueprintObjectRepository;
import org.apache.geronimo.blueprint.context.Instanciator;
import org.apache.geronimo.blueprint.namespace.ComponentDefinitionRegistryImpl;
@@ -121,29 +124,39 @@
assertEquals(true, pojob.getDestroyCalled());
}
- public void testDependsOn() throws Exception {
- final AtomicBoolean initC = new AtomicBoolean();
- final AtomicBoolean initD = new AtomicBoolean();
- BeanC.run = new Runnable() {
- public void run() {
- assertTrue(initD.get());
- initC.set(true);
- }
- };
- BeanD.run = new Runnable() {
- public void run() {
- assertFalse(initC.get());
- initD.set(true);
- }
- };
+ public void testDependencies() throws Exception {
+ CallbackTracker.clear();
ComponentDefinitionRegistryImpl registry = parse("/test-depends-on.xml");
Instanciator i = new Instanciator(new TestBlueprintContext(registry));
- Repository repository = i.createRepository(registry);
+ BlueprintObjectRepository repository = i.createRepository(registry);
ObjectGraph graph = new ObjectGraph(repository);
- graph.createAll("c", "d");
+ Map instances = graph.createAll("c", "d", "e");
+
+ List<Callback> callback = CallbackTracker.getCallbacks();
+ assertEquals(3, callback.size());
+ checkInitCallback(instances.get("d"), callback.get(0));
+ checkInitCallback(instances.get("c"), callback.get(1));
+ checkInitCallback(instances.get("e"), callback.get(2));
+
+ repository.destroy();
+
+ assertEquals(6, callback.size());
+ checkDestroyCallback(instances.get("e"), callback.get(3));
+ checkDestroyCallback(instances.get("c"), callback.get(4));
+ checkDestroyCallback(instances.get("d"), callback.get(5));
}
+ private void checkInitCallback(Object obj, Callback callback) {
+ assertEquals(Callback.INIT, callback.getType());
+ assertEquals(obj, callback.getObject());
+ }
+
+ private void checkDestroyCallback(Object obj, Callback callback) {
+ assertEquals(Callback.DESTROY, callback.getType());
+ assertEquals(obj, callback.getObject());
+ }
+
public void testConstructor() throws Exception {
ComponentDefinitionRegistryImpl registry = parse("/test-constructor.xml");
Instanciator i = new Instanciator(new TestBlueprintContext(registry));
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java?rev=769225&r1=769224&r2=769225&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanC.java Tue Apr 28 02:56:18 2009
@@ -18,11 +18,17 @@
*/
package org.apache.geronimo.blueprint.pojos;
-public class BeanC {
+import org.apache.geronimo.blueprint.CallbackTracker;
+import org.apache.geronimo.blueprint.CallbackTracker.Callback;
- public static Runnable run;
+public class BeanC {
public void init() {
- run.run();
+ CallbackTracker.add(new Callback(Callback.INIT, this));
+ }
+
+ public void destroy() {
+ CallbackTracker.add(new Callback(Callback.DESTROY, this));
}
+
}
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java?rev=769225&r1=769224&r2=769225&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanD.java Tue Apr 28 02:56:18 2009
@@ -18,12 +18,17 @@
*/
package org.apache.geronimo.blueprint.pojos;
-public class BeanD {
+import org.apache.geronimo.blueprint.CallbackTracker;
+import org.apache.geronimo.blueprint.CallbackTracker.Callback;
- public static Runnable run;
+public class BeanD {
public void init() {
- run.run();
+ CallbackTracker.add(new Callback(Callback.INIT, this));
+ }
+
+ public void destroy() {
+ CallbackTracker.add(new Callback(Callback.DESTROY, this));
}
}
Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java?rev=769225&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java Tue Apr 28 02:56:18 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.geronimo.blueprint.pojos;
+
+import org.apache.geronimo.blueprint.CallbackTracker;
+import org.apache.geronimo.blueprint.CallbackTracker.Callback;
+
+public class BeanE {
+
+ public BeanE(BeanC c) {
+ }
+
+ public void init() {
+ CallbackTracker.add(new Callback(Callback.INIT, this));
+ }
+
+ public void destroy() {
+ CallbackTracker.add(new Callback(Callback.DESTROY, this));
+ }
+
+}
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/BeanE.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml?rev=769225&r1=769224&r2=769225&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-depends-on.xml Tue Apr 28 02:56:18 2009
@@ -6,5 +6,9 @@
<bean id="c" class="org.apache.geronimo.blueprint.pojos.BeanC" depends-on="d" init-method="init"/>
<bean id="d" class="org.apache.geronimo.blueprint.pojos.BeanD" init-method="init"/>
+
+ <bean id="e" class="org.apache.geronimo.blueprint.pojos.BeanE" init-method="init">
+ <argument ref="c"/>
+ </bean>
</blueprint>
\ No newline at end of file