Repository: qpid-jms Updated Branches: refs/heads/master f3e676e9c -> 1201c2561
QPIDJMS-207: ensure resource clean up for JMSContextTest Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/1201c256 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/1201c256 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/1201c256 Branch: refs/heads/master Commit: 1201c25619a692e51ceb1231c42854711973871d Parents: f3e676e Author: Robert Gemmell <[email protected]> Authored: Tue Dec 13 11:44:48 2016 +0000 Committer: Robert Gemmell <[email protected]> Committed: Tue Dec 13 11:44:48 2016 +0000 ---------------------------------------------------------------------- .../qpid/jms/JmsConnectionTestSupport.java | 4 ++- .../org/apache/qpid/jms/JmsContextTest.java | 28 ++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1201c256/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java index 5514c61..8dd5656 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java @@ -17,6 +17,7 @@ package org.apache.qpid.jms; import java.net.URI; +import java.util.concurrent.atomic.AtomicLong; import javax.jms.JMSContext; @@ -37,6 +38,7 @@ import org.junit.Before; */ public class JmsConnectionTestSupport extends QpidJmsTestCase { + private static final AtomicLong CONN_ID_SUFFIX = new AtomicLong(); private final IdGenerator clientIdGenerator = new IdGenerator(); protected final MockProviderFactory mockFactory = new MockProviderFactory(); @@ -80,7 +82,7 @@ public class JmsConnectionTestSupport extends QpidJmsTestCase { @Before public void setUp() throws Exception { super.setUp(); - connectionInfo = new JmsConnectionInfo(new JmsConnectionId("ID:TEST:1")); + connectionInfo = new JmsConnectionInfo(new JmsConnectionId("ID:JCTS(" + CONN_ID_SUFFIX.incrementAndGet() + "):" + getClass().getName())); connectionInfo.setClientId(clientIdGenerator.generateId(), false); } http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1201c256/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java index aa8b90e..4f88d7b 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java @@ -44,6 +44,7 @@ import javax.jms.Topic; import org.apache.qpid.jms.provider.ProviderConstants.ACK_TYPE; import org.apache.qpid.jms.provider.mock.MockRemotePeer; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Matchers; @@ -66,13 +67,26 @@ public class JmsContextTest extends JmsConnectionTestSupport { context = createJMSContextToMockProvider(); } + @Override + @After + public void tearDown() throws Exception { + super.tearDown(); + if (context != null) { + context.close(); + } + } + //----- Test basic interface behaviors -----------------------------------// @Test public void testCreateContextWithNewAcknowledgementMode() { JMSContext newContext = context.createContext(JMSContext.CLIENT_ACKNOWLEDGE); - assertNotNull(newContext); - assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, newContext.getSessionMode()); + try { + assertNotNull(newContext); + assertEquals(JMSContext.CLIENT_ACKNOWLEDGE, newContext.getSessionMode()); + } finally { + newContext.close(); + } } @Test @@ -84,9 +98,13 @@ public class JmsContextTest extends JmsConnectionTestSupport { public void testGetTransactedFromContext() { assertFalse(context.getTransacted()); JMSContext newContext = context.createContext(JMSContext.SESSION_TRANSACTED); - assertNotNull(newContext); - assertEquals(JMSContext.SESSION_TRANSACTED, newContext.getSessionMode()); - assertTrue(newContext.getTransacted()); + try { + assertNotNull(newContext); + assertEquals(JMSContext.SESSION_TRANSACTED, newContext.getSessionMode()); + assertTrue(newContext.getTransacted()); + } finally { + newContext.close(); + } } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
