merge the two JmsSessionClosedTest classes
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/b5fb0f3e Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/b5fb0f3e Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/b5fb0f3e Branch: refs/heads/master Commit: b5fb0f3e67c93ddb673d3245bd47a2de166d140c Parents: 72ab8a3 Author: Robert Gemmell <[email protected]> Authored: Fri Jan 16 17:33:31 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Fri Jan 16 17:58:07 2015 +0000 ---------------------------------------------------------------------- .../apache/qpid/jms/JmsSessionClosedTest.java | 234 ------------------- .../apache/qpid/jms/JmsSessionFailedTest.java | 62 ----- .../qpid/jms/session/JmsSessionClosedTest.java | 214 ++++++++++++++++- .../qpid/jms/session/JmsSessionFailedTest.java | 69 ++++++ 4 files changed, 277 insertions(+), 302 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b5fb0f3e/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionClosedTest.java deleted file mode 100644 index b1237a1..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionClosedTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.qpid.jms; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.Topic; - -import org.apache.qpid.jms.support.AmqpTestSupport; -import org.junit.Test; - -/** - * Validates all Session contracts following a close() call. - */ -public class JmsSessionClosedTest extends AmqpTestSupport { - - protected Session createSession() throws Exception { - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - session.close(); - return session; - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateMessageFails() throws Exception { - Session session = createSession(); - session.createMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateTextMessageFails() throws Exception { - Session session = createSession(); - session.createTextMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateTextMessageWithTextFails() throws Exception { - Session session = createSession(); - session.createTextMessage("TEST"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateMapMessageFails() throws Exception { - Session session = createSession(); - session.createMapMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateStreamMessageFails() throws Exception { - Session session = createSession(); - session.createStreamMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateBytesMessageFails() throws Exception { - Session session = createSession(); - session.createBytesMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateObjectMessageFails() throws Exception { - Session session = createSession(); - session.createObjectMessage(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateObjectMessageWithObjectFails() throws Exception { - Session session = createSession(); - session.createObjectMessage("TEST"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetTransactedFails() throws Exception { - Session session = createSession(); - session.getTransacted(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetAcknowledgeModeFails() throws Exception { - Session session = createSession(); - session.getAcknowledgeMode(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCommitFails() throws Exception { - Session session = createSession(); - session.commit(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testRollbackFails() throws Exception { - Session session = createSession(); - session.rollback(); - } - - @Test(timeout=30000) - public void testCloseDoesNotFail() throws Exception { - Session session = createSession(); - session.close(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testRecoverFails() throws Exception { - Session session = createSession(); - session.recover(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetMessageListenerFails() throws Exception { - Session session = createSession(); - session.getMessageListener(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetMessageListenerFails() throws Exception { - Session session = createSession(); - MessageListener listener = new MessageListener() { - @Override - public void onMessage(Message message) { - } - }; - session.setMessageListener(listener); - } - - @Test(timeout=30000, expected=RuntimeException.class) - public void testRunFails() throws Exception { - Session session = createSession(); - session.run(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateProducerFails() throws Exception { - Session session = createSession(); - Destination destination = session.createQueue("test"); - session.createProducer(destination); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateConsumerDestinatioFails() throws Exception { - Session session = createSession(); - Destination destination = session.createQueue("test"); - session.createConsumer(destination); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateConsumerDestinatioSelectorFails() throws Exception { - Session session = createSession(); - Destination destination = session.createQueue("test"); - session.createConsumer(destination, "a = b"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateConsumerDestinatioSelectorBooleanFails() throws Exception { - Session session = createSession(); - Destination destination = session.createQueue("test"); - session.createConsumer(destination, "a = b", true); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateQueueFails() throws Exception { - Session session = createSession(); - session.createQueue("TEST"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateTopicFails() throws Exception { - Session session = createSession(); - session.createTopic("TEST"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateTemporaryQueueFails() throws Exception { - Session session = createSession(); - session.createTemporaryQueue(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateTemporaryTopicFails() throws Exception { - Session session = createSession(); - session.createTemporaryQueue(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateDurableSubscriberFails() throws Exception { - Session session = createSession(); - Topic destination = session.createTopic("TEST"); - session.createDurableSubscriber(destination, "test"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateDurableSubscriberSelectorBooleanFails() throws Exception { - Session session = createSession(); - Topic destination = session.createTopic("TEST"); - session.createDurableSubscriber(destination, "test", "a = b", false); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateQueueBrowserFails() throws Exception { - Session session = createSession(); - Queue destination = session.createQueue("test"); - session.createBrowser(destination); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testCreateQueueBrowserWithSelectorFails() throws Exception { - Session session = createSession(); - Queue destination = session.createQueue("test"); - session.createBrowser(destination, "a = b"); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testUnsubscribeFails() throws Exception { - Session session = createSession(); - session.unsubscribe("test"); - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b5fb0f3e/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionFailedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionFailedTest.java deleted file mode 100644 index 5e6846c..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsSessionFailedTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.qpid.jms; - -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.Session; - -import org.apache.qpid.jms.JmsConnection; -import org.apache.qpid.jms.support.Wait; - - -/** - * Tests the Session method contracts when the underlying connection is lost. - */ -public class JmsSessionFailedTest extends JmsSessionClosedTest { - - @Override - protected Session createSession() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - connection.setExceptionListener(new ExceptionListener() { - - @Override - public void onException(JMSException exception) { - latch.countDown(); - } - }); - connection.start(); - stopPrimaryBroker(); - assertTrue(latch.await(20, TimeUnit.SECONDS)); - final JmsConnection jmsConnection = (JmsConnection) connection; - assertTrue(Wait.waitFor(new Wait.Condition() { - - @Override - public boolean isSatisified() throws Exception { - return !jmsConnection.isConnected(); - } - })); - return session; - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b5fb0f3e/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java index 7d3527f..a9ea137 100644 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java +++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java @@ -16,10 +16,15 @@ */ package org.apache.qpid.jms.session; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; import javax.jms.MessageConsumer; +import javax.jms.MessageListener; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; +import javax.jms.Topic; import org.apache.qpid.jms.JmsConnectionFactory; import org.apache.qpid.jms.support.AmqpTestSupport; @@ -30,15 +35,14 @@ import org.junit.Test; */ public class JmsSessionClosedTest extends AmqpTestSupport { - private Session session; - private MessageProducer sender; - private MessageConsumer receiver; + protected MessageProducer sender; + protected MessageConsumer receiver; - protected void createAndCloseSession() throws Exception { + protected Session createAndCloseSession() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); connection = factory.createConnection(); - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(name.getMethodName()); sender = session.createProducer(destination); @@ -46,15 +50,213 @@ public class JmsSessionClosedTest extends AmqpTestSupport { // Close the session explicitly, without closing the above. session.close(); + + return session; } @Test(timeout=30000) public void testSessionCloseAgain() throws Exception { - createAndCloseSession(); + Session session = createAndCloseSession(); // Close it again session.close(); } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTextMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createTextMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTextMessageWithTextFails() throws Exception { + Session session = createAndCloseSession(); + session.createTextMessage("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateMapMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createMapMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateStreamMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createStreamMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateBytesMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createBytesMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateObjectMessageFails() throws Exception { + Session session = createAndCloseSession(); + session.createObjectMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateObjectMessageWithObjectFails() throws Exception { + Session session = createAndCloseSession(); + session.createObjectMessage("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetTransactedFails() throws Exception { + Session session = createAndCloseSession(); + session.getTransacted(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetAcknowledgeModeFails() throws Exception { + Session session = createAndCloseSession(); + session.getAcknowledgeMode(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCommitFails() throws Exception { + Session session = createAndCloseSession(); + session.commit(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRollbackFails() throws Exception { + Session session = createAndCloseSession(); + session.rollback(); + } + + @Test(timeout=30000) + public void testCloseDoesNotFail() throws Exception { + Session session = createAndCloseSession(); + session.close(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRecoverFails() throws Exception { + Session session = createAndCloseSession(); + session.recover(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetMessageListenerFails() throws Exception { + Session session = createAndCloseSession(); + session.getMessageListener(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetMessageListenerFails() throws Exception { + Session session = createAndCloseSession(); + MessageListener listener = new MessageListener() { + @Override + public void onMessage(Message message) { + } + }; + session.setMessageListener(listener); + } + + @Test(timeout=30000, expected=RuntimeException.class) + public void testRunFails() throws Exception { + Session session = createAndCloseSession(); + session.run(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateProducerFails() throws Exception { + Session session = createAndCloseSession(); + Destination destination = session.createQueue("test"); + session.createProducer(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioFails() throws Exception { + Session session = createAndCloseSession(); + Destination destination = session.createQueue("test"); + session.createConsumer(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioSelectorFails() throws Exception { + Session session = createAndCloseSession(); + Destination destination = session.createQueue("test"); + session.createConsumer(destination, "a = b"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioSelectorBooleanFails() throws Exception { + Session session = createAndCloseSession(); + Destination destination = session.createQueue("test"); + session.createConsumer(destination, "a = b", true); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueFails() throws Exception { + Session session = createAndCloseSession(); + session.createQueue("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTopicFails() throws Exception { + Session session = createAndCloseSession(); + session.createTopic("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTemporaryQueueFails() throws Exception { + Session session = createAndCloseSession(); + session.createTemporaryQueue(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTemporaryTopicFails() throws Exception { + Session session = createAndCloseSession(); + session.createTemporaryQueue(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateDurableSubscriberFails() throws Exception { + Session session = createAndCloseSession(); + Topic destination = session.createTopic("TEST"); + session.createDurableSubscriber(destination, "test"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateDurableSubscriberSelectorBooleanFails() throws Exception { + Session session = createAndCloseSession(); + Topic destination = session.createTopic("TEST"); + session.createDurableSubscriber(destination, "test", "a = b", false); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueBrowserFails() throws Exception { + Session session = createAndCloseSession(); + Queue destination = session.createQueue("test"); + session.createBrowser(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueBrowserWithSelectorFails() throws Exception { + Session session = createAndCloseSession(); + Queue destination = session.createQueue("test"); + session.createBrowser(destination, "a = b"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testUnsubscribeFails() throws Exception { + Session session = createAndCloseSession(); + session.unsubscribe("test"); + } + + // --- Test effects on consumer/producer opened previously on the session --- + @Test(timeout=30000) public void testConsumerCloseAgain() throws Exception { createAndCloseSession(); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b5fb0f3e/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java new file mode 100644 index 0000000..3b56d5c --- /dev/null +++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.qpid.jms.session; + +import static org.junit.Assert.assertTrue; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Session; + +import org.apache.qpid.jms.JmsConnection; +import org.apache.qpid.jms.support.Wait; + + +/** + * Tests the Session method contracts when the underlying connection is lost. + */ +public class JmsSessionFailedTest extends JmsSessionClosedTest { + + @Override + protected Session createAndCloseSession() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + connection = createAmqpConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + connection.setExceptionListener(new ExceptionListener() { + + @Override + public void onException(JMSException exception) { + latch.countDown(); + } + }); + Queue destination = session.createQueue(name.getMethodName()); + + sender = session.createProducer(destination); + receiver = session.createConsumer(destination); + connection.start(); + + stopPrimaryBroker(); + + assertTrue(latch.await(20, TimeUnit.SECONDS)); + final JmsConnection jmsConnection = (JmsConnection) connection; + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return !jmsConnection.isConnected(); + } + })); + return session; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
