use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ProperConnectionShutdownTest method run.
@Test
@Ignore("https://issues.apache.org/jira/browse/AMQ-6051")
public void run() throws Throwable {
final Thread[] threadsBefore = listThreads();
final AtomicReference<Thread[]> threadWhile = new AtomicReference<>();
// run test
final Statement testInContainer = new Statement() {
@Override
public void evaluate() throws Throwable {
messages.sendMessage("Hello World!");
messages.sendMessage("How are you?");
threadWhile.set(listThreads());
messages.sendMessage("Still spinning?");
assertEquals(messages.receiveMessage(), "Hello World!");
assertEquals(messages.receiveMessage(), "How are you?");
assertEquals(messages.receiveMessage(), "Still spinning?");
/* TODO: activate it when AMQ-6051 is fixed
// all worked, now hold a connection
new Thread(new Runnable() { // not daemon!
@Override
public void run() {
messages.blockConnection(); // oops, I forgot to close it
}
}).start();
*/
}
};
new DeployApplication(this, testInContainer, new ApplicationComposers(this)).evaluate();
// AMQ state (started) polling for transport thread is 1s
Thread.sleep(2250);
while (Join.join("", listThreads()).contains("ActiveMQ Session Task")) {
// let few sec to AMQ to leave the holding task
Thread.sleep(1000);
}
// ensure no connection are leaking
final Thread[] threadsAfter = listThreads();
int countAMQ = 0;
int countOthers = 0;
for (final Thread t : threadsAfter) {
if (!t.isAlive()) {
continue;
}
if (t.getName().contains("AMQ") || t.getName().toLowerCase(Locale.ENGLISH).contains("activemq")) {
countAMQ++;
} else {
countOthers++;
}
}
final String debugMessage = Join.join(", ", threadsAfter);
assertEquals(debugMessage, 0, countAMQ);
// geronimo libs spawn 2 threads we know: PoolIdleReleaseTimer and CurrentTime so we can get initial + 2 threads there
assertTrue(debugMessage, countOthers <= threadsBefore.length + 2);
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ResourceEventsTest method run.
@Test
public void run() throws Exception {
Listener.EVENTS.clear();
new ApplicationComposers(this).evaluate(this, new Callable<Object>() {
@Override
public Object call() throws Exception {
assertEquals(2, Listener.EVENTS.size());
for (final ResourceEvent re : Listener.EVENTS) {
assertTrue(ResourceCreated.class.isInstance(re));
assertNotNull(re.getResource());
assertTrue("base".equals(re.getName()) || "base2".equals(re.getName()));
}
Listener.EVENTS.clear();
assertTrue(Child.class.isInstance(base));
assertFalse(Child.class.isInstance(base2));
assertNotNull(Child.class.cast(base).parent);
return null;
}
});
assertEquals(2, Listener.EVENTS.size());
for (final ResourceEvent re : Listener.EVENTS) {
assertTrue(ResourceBeforeDestroyed.class.isInstance(re));
Object resource = re.getResource();
if (Assembler.ResourceInstance.class.isInstance(resource)) {
resource = Assembler.ResourceInstance.class.cast(resource).getObject();
}
assertNotNull(resource);
assertTrue("base".equals(re.getName()) || "base2".equals(re.getName()));
if ("base".equals(re.getName())) {
assertTrue(Child.class.isInstance(resource));
} else {
assertFalse(Child.class.isInstance(resource));
assertTrue(Base.class.isInstance(resource));
}
}
Listener.EVENTS.clear();
assertTrue(base2.stopped);
assertTrue(base.stopped);
assertTrue(Base.class.cast(Child.class.cast(base).parent).stopped);
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class ContainerRule method apply.
@Override
public Statement apply(final Statement statement, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final ApplicationComposers composers = new ContainerApplicationComposers(instance);
composers.startContainer(instance);
try {
statement.evaluate();
} finally {
composers.after();
}
}
};
}
use of org.apache.openejb.testing.ApplicationComposers in project tomee by apache.
the class EnsureRequestScopeThreadLocalIsCleanUpTest method runAndCheckThreadLocal.
@Test
public void runAndCheckThreadLocal() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
assertNotNull(contextsService.getCurrentContext(RequestScoped.class));
assertNotNull(contextsService.getCurrentContext(SessionScoped.class));
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
Aggregations