Add an assertion to test that interrupted state is preserved.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1195046 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-10-29 21:44:27 +00:00
parent 83fde0b2a0
commit 15f641634b
1 changed files with 57 additions and 57 deletions

View File

@ -16,9 +16,7 @@
*/ */
package org.apache.activemq.bugs; package org.apache.activemq.bugs;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
@ -33,66 +31,68 @@ import org.junit.Test;
public class AMQ3529Test { public class AMQ3529Test {
private ConnectionFactory connectionFactory; private ConnectionFactory connectionFactory;
private Connection connection; private Connection connection;
private Session session; private Session session;
private BrokerService broker; private BrokerService broker;
private String connectionUri; private String connectionUri;
@Before @Before
public void startBroker() throws Exception { public void startBroker() throws Exception {
broker = new BrokerService(); broker = new BrokerService();
broker.setDeleteAllMessagesOnStartup(true); broker.setDeleteAllMessagesOnStartup(true);
broker.setPersistent(false); broker.setPersistent(false);
broker.setUseJmx(false); broker.setUseJmx(false);
broker.addConnector("tcp://0.0.0.0:0"); broker.addConnector("tcp://0.0.0.0:0");
broker.start(); broker.start();
broker.waitUntilStarted(); broker.waitUntilStarted();
connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString(); connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
connectionFactory = new ActiveMQConnectionFactory(connectionUri); connectionFactory = new ActiveMQConnectionFactory(connectionUri);
} }
@After @After
public void stopBroker() throws Exception { public void stopBroker() throws Exception {
broker.stop(); broker.stop();
broker.waitUntilStopped(); broker.waitUntilStopped();
} }
@Test(timeout = 60000) @Test(timeout = 60000)
public void testInterruptionAffects() throws Exception { public void testInterruptionAffects() throws Exception {
ThreadGroup tg = new ThreadGroup("tg"); ThreadGroup tg = new ThreadGroup("tg");
assertEquals(0, tg.activeCount()); assertEquals(0, tg.activeCount());
Thread client = new Thread(tg, "client") { Thread client = new Thread(tg, "client") {
@Override @Override
public void run() { public void run() {
try { try {
connection = connectionFactory.createConnection(); connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session); assertNotNull(session);
} catch (JMSException e) { } catch (JMSException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
// next line is the nature of the test, if I remove this line, everything works OK // next line is the nature of the test, if I remove this line, everything works OK
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
try { try {
connection.close(); connection.close();
} catch (JMSException e) { } catch (JMSException e) {
} }
}
}; assertTrue(Thread.currentThread().isInterrupted());
client.start(); }
client.join(); };
Thread.sleep(2000); client.start();
Thread[] remainThreads = new Thread[tg.activeCount()]; client.join();
tg.enumerate(remainThreads); Thread.sleep(2000);
for (Thread t : remainThreads) { Thread[] remainThreads = new Thread[tg.activeCount()];
if (t.isAlive() && !t.isDaemon()) tg.enumerate(remainThreads);
fail("Remaining thread: " + t.toString()); for (Thread t : remainThreads) {
} if (t.isAlive() && !t.isDaemon())
} fail("Remaining thread: " + t.toString());
}
}
} }