Search in sources :

Example 1 with DeployApplication

use of org.apache.openejb.junit.DeployApplication 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);
}
Also used : Statement(org.junit.runners.model.Statement) DeployApplication(org.apache.openejb.junit.DeployApplication) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationComposers(org.apache.openejb.testing.ApplicationComposers) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DeployApplication (org.apache.openejb.junit.DeployApplication)1 ApplicationComposers (org.apache.openejb.testing.ApplicationComposers)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Statement (org.junit.runners.model.Statement)1