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/03/09 16:56:46 UTC
tomee git commit: TOMEE-1728 don't call twice @PostConstruct in
ApplicationComposers.run
Repository: tomee
Updated Branches:
refs/heads/master 7f1ee68c3 -> 93b8c6dbc
TOMEE-1728 don't call twice @PostConstruct in ApplicationComposers.run
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/93b8c6db
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/93b8c6db
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/93b8c6db
Branch: refs/heads/master
Commit: 93b8c6dbcc3a6afe7e19d56aced13ce9c27b1a28
Parents: 7f1ee68
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Wed Mar 9 16:55:26 2016 +0100
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Wed Mar 9 16:55:26 2016 +0100
----------------------------------------------------------------------
.../openejb/testing/ApplicationComposers.java | 21 ++++++++++++--------
.../testing/ApplicationComposersTest.java | 3 +++
.../apache/openejb/testing/app/Application.java | 2 ++
3 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/93b8c6db/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 f9568b1..c645c0e 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
@@ -1515,17 +1515,11 @@ public class ApplicationComposers {
instance = type.newInstance();
}
composer.before(instance);
+ composer.testClassFinders.remove(composer); // fix this workaround used for tests but breaking standalone mode
final CountDownLatch latch = new CountDownLatch(1);
- composer.handleLifecycle(type, instance);
- composer.afterRunnables.add(new Runnable() {
- @Override
- public void run() {
- latch.countDown();
- }
- });
- Runtime.getRuntime().addShutdownHook(new Thread() {
+ final Thread hook = new Thread() {
@Override
public void run() {
try {
@@ -1534,8 +1528,19 @@ public class ApplicationComposers {
// no-op
}
}
+ };
+ Runtime.getRuntime().addShutdownHook(hook);
+ composer.afterRunnables.add(new Runnable() {
+ @Override
+ public void run() {
+ Runtime.getRuntime().removeShutdownHook(hook);
+ latch.countDown();
+ }
});
+ // do it after having added the latch countdown hook to avoid to block if start and stop very fast
+ composer.handleLifecycle(type, instance);
+
latch.await();
} catch (final InterruptedException ie) {
Thread.interrupted();
http://git-wip-us.apache.org/repos/asf/tomee/blob/93b8c6db/container/openejb-core/src/test/java/org/apache/openejb/testing/ApplicationComposersTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/testing/ApplicationComposersTest.java b/container/openejb-core/src/test/java/org/apache/openejb/testing/ApplicationComposersTest.java
index 9bec2e3..bd45ad9 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/testing/ApplicationComposersTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/testing/ApplicationComposersTest.java
@@ -20,6 +20,7 @@ import org.apache.openejb.testing.app.Application;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ApplicationComposersTest {
@@ -32,6 +33,7 @@ public class ApplicationComposersTest {
@Test
public void run() throws InterruptedException {
+ Application.startCount = 0;
final Thread t = new Thread() {
@Override
public void run() {
@@ -41,5 +43,6 @@ public class ApplicationComposersTest {
t.start();
t.join();
assertTrue(ok);
+ assertEquals(1, Application.startCount);
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/93b8c6db/container/openejb-core/src/test/java/org/apache/openejb/testing/app/Application.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/testing/app/Application.java b/container/openejb-core/src/test/java/org/apache/openejb/testing/app/Application.java
index 7f18708..26c416f 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/testing/app/Application.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/testing/app/Application.java
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertNotNull;
@Classes(cdi = true, value = Application.CdiBean.class)
public class Application {
+ public static volatile int startCount = 0;
private final String[] args;
public Application(String[] args) {
@@ -44,6 +45,7 @@ public class Application {
@PostConstruct
public void init() {
+ startCount++;
try {
assertNotNull(bean);
assertEquals("run", bean.run());