You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/02/17 12:29:15 UTC
tomee git commit: extracting AppComposer app class lifecycle handling
and adding it in SingleApplicationComposerRunner as well
Repository: tomee
Updated Branches:
refs/heads/master 800edc908 -> 3186829e3
extracting AppComposer app class lifecycle handling and adding it in SingleApplicationComposerRunner as well
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3186829e
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3186829e
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3186829e
Branch: refs/heads/master
Commit: 3186829e39e3f35fa4d3e5057aab547204dc950a
Parents: 800edc9
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Wed Feb 17 12:28:49 2016 +0100
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Wed Feb 17 12:28:49 2016 +0100
----------------------------------------------------------------------
.../openejb/testing/ApplicationComposers.java | 99 +++++++++++---------
.../SingleApplicationComposerRunner.java | 6 +-
2 files changed, 58 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/3186829e/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index 353d891..f9568b1 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -1517,43 +1517,8 @@ public class ApplicationComposers {
composer.before(instance);
final CountDownLatch latch = new CountDownLatch(1);
- final Object appInstance = instance;
- composer.beforeDestroyAfterRunnables.add(new Runnable() {
- @Override
- public void run() {
- for (final Map.Entry<Object, ClassFinder> m : composer.testClassFinders.entrySet()) {
- for (final Method mtd : m.getValue().findAnnotatedMethods(PreDestroy.class)) {
- if (mtd.getParameterTypes().length == 0) {
- try {
- mtd.invoke(mtd.getDeclaringClass() == type ? appInstance : m.getKey());
- } catch (final IllegalAccessException | InvocationTargetException e) {
- // no-op
- }
- }
- }
- }
- }
- });
- if (!composer.appContext.getWebContexts().isEmpty()) {
- composer.beforeDestroyAfterRunnables.add(new Runnable() {
- @Override
- public void run() {
- try {
- final Object sessionManager = SystemInstance.get().getComponent(
- ParentClassLoaderFinder.Helper.get().loadClass("org.apache.openejb.server.httpd.session.SessionManager")
- );
- if (sessionManager != null) {
- final Class<?>[] paramTypes = {WebContext.class};
- for (final WebContext web : composer.appContext.getWebContexts()) {
- Reflections.invokeByReflection(sessionManager, "destroy", paramTypes, new Object[]{web});
- }
- }
- } catch (final Throwable e) {
- // no-op
- }
- }
- });
- }
+ composer.handleLifecycle(type, instance);
+
composer.afterRunnables.add(new Runnable() {
@Override
public void run() {
@@ -1571,14 +1536,6 @@ public class ApplicationComposers {
}
});
- for (final Map.Entry<Object, ClassFinder> m : composer.testClassFinders.entrySet()) {
- for (final Method mtd : m.getValue().findAnnotatedMethods(PostConstruct.class)) {
- if (mtd.getParameterTypes().length == 0) {
- mtd.invoke(mtd.getDeclaringClass() == type ? instance : m.getKey());
- }
- }
- }
-
latch.await();
} catch (final InterruptedException ie) {
Thread.interrupted();
@@ -1587,6 +1544,58 @@ public class ApplicationComposers {
}
}
+ public void handleLifecycle(final Class<?> type, final Object appInstance) throws IllegalAccessException, InvocationTargetException {
+ beforeDestroyAfterRunnables.add(new Runnable() {
+ @Override
+ public void run() {
+ for (final Map.Entry<Object, ClassFinder> m : testClassFinders.entrySet()) {
+ for (final Method mtd : m.getValue().findAnnotatedMethods(PreDestroy.class)) {
+ if (mtd.getParameterTypes().length == 0) {
+ if (!mtd.isAccessible()) {
+ mtd.setAccessible(true);
+ }
+ try {
+ mtd.invoke(mtd.getDeclaringClass() == type ? appInstance : m.getKey());
+ } catch (final IllegalAccessException | InvocationTargetException e) {
+ // no-op
+ }
+ }
+ }
+ }
+ }
+ });
+ if (!appContext.getWebContexts().isEmpty()) {
+ beforeDestroyAfterRunnables.add(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ final Object sessionManager = SystemInstance.get().getComponent(
+ ParentClassLoaderFinder.Helper.get().loadClass("org.apache.openejb.server.httpd.session.SessionManager")
+ );
+ if (sessionManager != null) {
+ final Class<?>[] paramTypes = {WebContext.class};
+ for (final WebContext web : appContext.getWebContexts()) {
+ Reflections.invokeByReflection(sessionManager, "destroy", paramTypes, new Object[]{web});
+ }
+ }
+ } catch (final Throwable e) {
+ // no-op
+ }
+ }
+ });
+ }
+ for (final Map.Entry<Object, ClassFinder> m : testClassFinders.entrySet()) {
+ for (final Method mtd : m.getValue().findAnnotatedMethods(PostConstruct.class)) {
+ if (mtd.getParameterTypes().length == 0) {
+ if (!mtd.isAccessible()) {
+ mtd.setAccessible(true);
+ }
+ mtd.invoke(mtd.getDeclaringClass() == type ? appInstance : m.getKey());
+ }
+ }
+ }
+ }
+
public static void main(final String[] args) throws Exception {
if (args.length < 1) {
throw new IllegalArgumentException("provide at least application class as parameter");
http://git-wip-us.apache.org/repos/asf/tomee/blob/3186829e/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
index dcbfe9a..6c40003 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/SingleApplicationComposerRunner.java
@@ -141,7 +141,7 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
}
if (!started) {
final Object app = APP.get();
- new ApplicationComposers(app.getClass()) {
+ final ApplicationComposers composers = new ApplicationComposers(app.getClass()) {
@Override
public void deployApp(final Object inputTestInstance) throws Exception {
super.deployApp(inputTestInstance);
@@ -164,7 +164,9 @@ public class SingleApplicationComposerRunner extends BlockJUnit4ClassRunner {
started = true;
}
}
- }.before(app);
+ };
+ composers.before(app);
+ composers.handleLifecycle(app.getClass(), app);
}
}