Repository: qpid-jms Updated Branches: refs/heads/master d76e0afd3 -> 96b21b85a
Move some tests to the client module that don't need a broker to validate the functionality. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/96b21b85 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/96b21b85 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/96b21b85 Branch: refs/heads/master Commit: 96b21b85ad22d54fc82a261f5ef22ce47a7e6f79 Parents: d76e0af Author: Timothy Bish <[email protected]> Authored: Thu Jan 29 18:22:49 2015 -0500 Committer: Timothy Bish <[email protected]> Committed: Thu Jan 29 18:22:49 2015 -0500 ---------------------------------------------------------------------- .../qpid/jms/JmsConnectionClosedTest.java | 74 +---- .../qpid/jms/JmsConnectionTestSupport.java | 119 ++++++++ .../consumer/JmsMessageConsumerClosedTest.java | 91 ++++++ .../consumer/JmsMessageConsumerFailedTest.java | 64 +++++ .../producer/JmsMessageProducerClosedTest.java | 135 +++++++++ .../producer/JmsMessageProducerFailedTest.java | 64 +++++ .../qpid/jms/session/JmsSessionClosedTest.java | 249 ++++++++++++++++ .../qpid/jms/session/JmsSessionFailedTest.java | 64 +++++ .../consumer/JmsMessageConsumerClosedTest.java | 90 ------ .../consumer/JmsMessageConsumerFailedTest.java | 65 ----- .../producer/JmsMessageProducerClosedTest.java | 143 ---------- .../producer/JmsMessageProducerFailedTest.java | 65 ----- .../qpid/jms/session/JmsSessionClosedTest.java | 285 ------------------- .../qpid/jms/session/JmsSessionFailedTest.java | 69 ----- 14 files changed, 787 insertions(+), 790 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java index 1be9605..73e7713 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java @@ -22,79 +22,16 @@ import javax.jms.JMSException; import javax.jms.Session; import javax.jms.Topic; -import org.apache.qpid.jms.meta.JmsResource; -import org.apache.qpid.jms.provider.Provider; -import org.apache.qpid.jms.provider.ProviderFuture; -import org.apache.qpid.jms.provider.ProviderListener; -import org.apache.qpid.jms.test.QpidJmsTestCase; -import org.apache.qpid.jms.util.IdGenerator; -import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test Connection methods contracts when state is closed. */ -public class JmsConnectionClosedTest extends QpidJmsTestCase { - - private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionClosedTest.class); +public class JmsConnectionClosedTest extends JmsConnectionTestSupport { protected Destination destination; - private final Provider provider = Mockito.mock(Provider.class); - private final IdGenerator clientIdGenerator = new IdGenerator(); - - protected JmsConnection connection; - protected ProviderListener providerListener; - - protected JmsConnection createConnectionToMockProvider() throws Exception { - - Mockito.doAnswer(new Answer<Object>() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - if (args[0] instanceof JmsResource) { - LOG.debug("Handling provider create resource: {}", args[0]); - ProviderFuture request = (ProviderFuture) args[1]; - request.onSuccess(); - } - return null; - } - }).when(provider).create(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class)); - - Mockito.doAnswer(new Answer<Object>() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - if (args[0] instanceof JmsResource) { - LOG.debug("Handling provider destroy resource: {}", args[0]); - ProviderFuture request = (ProviderFuture) args[1]; - request.onSuccess(); - } - return null; - } - }).when(provider).destroy(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class)); - - Mockito.doAnswer(new Answer<Object>() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - if (args[0] instanceof ProviderListener) { - providerListener = (ProviderListener) args[0]; - } - return null; - } - }).when(provider).setProviderListener(Mockito.any(ProviderListener.class)); - - JmsConnection connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator); - return connection; - } - protected JmsConnection createConnection() throws Exception { connection = createConnectionToMockProvider(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -110,15 +47,6 @@ public class JmsConnectionClosedTest extends QpidJmsTestCase { connection = createConnection(); } - @Override - @After - public void tearDown() throws Exception { - super.tearDown(); - if (connection != null) { - connection.close(); - } - } - @Test(timeout=30000, expected=JMSException.class) public void testGetClientIdFails() throws Exception { connection.getClientID(); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/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 new file mode 100644 index 0000000..0f93bc1 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java @@ -0,0 +1,119 @@ +/** + * 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 java.net.URI; + +import org.apache.qpid.jms.message.facade.defaults.JmsDefaultMessageFactory; +import org.apache.qpid.jms.meta.JmsConnectionInfo; +import org.apache.qpid.jms.meta.JmsResource; +import org.apache.qpid.jms.provider.Provider; +import org.apache.qpid.jms.provider.ProviderFuture; +import org.apache.qpid.jms.provider.ProviderListener; +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.apache.qpid.jms.util.IdGenerator; +import org.junit.After; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Base for tests that require a JmsConnection that is created using a + * Mocked Provider object to simulate a connection. + */ +public class JmsConnectionTestSupport extends QpidJmsTestCase { + + private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionTestSupport.class); + + private final Provider provider = Mockito.mock(Provider.class); + private final IdGenerator clientIdGenerator = new IdGenerator(); + + protected JmsConnection connection; + protected ProviderListener providerListener; + + protected JmsConnection createConnectionToMockProvider() throws Exception { + + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + if (args[0] instanceof JmsConnectionInfo) { + providerListener.onConnectionEstablished(new URI("vm://localhost")); + } + LOG.trace("Handling provider create resource: {}", args[0]); + ProviderFuture request = (ProviderFuture) args[1]; + request.onSuccess(); + return null; + } + }).when(provider).create(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class)); + + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + if (args[0] instanceof JmsResource) { + LOG.trace("Handling provider start resource: {}", args[0]); + ProviderFuture request = (ProviderFuture) args[1]; + request.onSuccess(); + } + return null; + } + }).when(provider).start(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class)); + + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + if (args[0] instanceof JmsResource) { + LOG.trace("Handling provider destroy resource: {}", args[0]); + ProviderFuture request = (ProviderFuture) args[1]; + request.onSuccess(); + } + return null; + } + }).when(provider).destroy(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class)); + + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + if (args[0] instanceof ProviderListener) { + providerListener = (ProviderListener) args[0]; + } + return null; + } + }).when(provider).setProviderListener(Mockito.any(ProviderListener.class)); + + Mockito.when(provider.getProviderListener()).thenReturn(providerListener); + Mockito.when(provider.getMessageFactory()).thenReturn(new JmsDefaultMessageFactory()); + + JmsConnection connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator); + + return connection; + } + + @Override + @After + public void tearDown() throws Exception { + super.tearDown(); + if (connection != null) { + connection.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java new file mode 100644 index 0000000..509a179 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java @@ -0,0 +1,91 @@ +/** + * 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.consumer; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Queue; +import javax.jms.Session; + +import org.apache.qpid.jms.JmsConnectionTestSupport; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests MessageConsumer method contracts after the MessageConsumer is closed. + */ +public class JmsMessageConsumerClosedTest extends JmsConnectionTestSupport { + + protected MessageConsumer consumer; + + protected MessageConsumer createConsumer() throws Exception { + connection = createConnectionToMockProvider(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue destination = session.createQueue(_testName.getMethodName()); + MessageConsumer consumer = session.createConsumer(destination); + consumer.close(); + return consumer; + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + consumer = createConsumer(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetMessageSelectorFails() throws Exception { + consumer.getMessageSelector(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetMessageListenerFails() throws Exception { + consumer.getMessageListener(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetMessageListenerFails() throws Exception { + consumer.setMessageListener(new MessageListener() { + @Override + public void onMessage(Message message) { + } + }); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRreceiveFails() throws Exception { + consumer.receive(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRreceiveTimedFails() throws Exception { + consumer.receive(11); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRreceiveNoWaitFails() throws Exception { + consumer.receiveNoWait(); + } + + @Test(timeout=30000) + public void testClose() throws Exception { + consumer.close(); + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java new file mode 100644 index 0000000..4166aa4 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java @@ -0,0 +1,64 @@ +/** + * 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.consumer; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.Queue; +import javax.jms.Session; + +import org.apache.qpid.jms.JmsConnection; +import org.apache.qpid.jms.test.Wait; + +/** + * Tests MessageConsumer method contracts after the MessageConsumer connection fails. + */ +public class JmsMessageConsumerFailedTest extends JmsMessageConsumerClosedTest { + + @Override + protected MessageConsumer createConsumer() throws Exception { + connection = createConnectionToMockProvider(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue destination = session.createQueue(_testName.getMethodName()); + MessageConsumer consumer = session.createConsumer(destination); + connection.setExceptionListener(new ExceptionListener() { + + @Override + public void onException(JMSException exception) { + } + }); + connection.start(); + providerListener.onConnectionFailure(new IOException()); + + final JmsConnection jmsConnection = connection; + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return !jmsConnection.isConnected(); + } + }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2))); + + return consumer; + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java new file mode 100644 index 0000000..9168026 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java @@ -0,0 +1,135 @@ +/** + * 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.producer; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.qpid.jms.JmsConnectionTestSupport; +import org.junit.Before; +import org.junit.Test; + +/** + * Test the contract of MessageProducer that has been closed. + */ +public class JmsMessageProducerClosedTest extends JmsConnectionTestSupport { + + protected MessageProducer producer; + protected Message message; + protected Destination destination; + + protected MessageProducer createProducer() throws Exception { + connection = createConnectionToMockProvider(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + message = session.createMessage(); + destination = session.createTopic("test"); + MessageProducer producer = session.createProducer(destination); + producer.close(); + return producer; + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + producer = createProducer(); + } + + @Test(timeout=30000) + public void testClose() throws Exception { + producer.close(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetDisableMessageIDFails() throws Exception { + producer.setDisableMessageID(true); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetDisableMessageIDFails() throws Exception { + producer.getDisableMessageID(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetDisableMessageTimestampFails() throws Exception { + producer.setDisableMessageTimestamp(false); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetDisableMessageTimestampFails() throws Exception { + producer.getDisableMessageTimestamp(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetDeliveryModeFails() throws Exception { + producer.setDeliveryMode(1); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetDeliveryModeFails() throws Exception { + producer.getDeliveryMode(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetPriorityFails() throws Exception { + producer.setPriority(1); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetPriorityFails() throws Exception { + producer.getPriority(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetTimeToLiveFails() throws Exception { + producer.setTimeToLive(1); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetTimeToLiveFails() throws Exception { + producer.getTimeToLive(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetDestinationFails() throws Exception { + producer.getDestination(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSendFails() throws Exception { + producer.send(message); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSendWithDestinationFails() throws Exception { + producer.send(destination, message); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSendWithModePriorityTTLFails() throws Exception { + producer.send(message, 1, 3, 111); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSendWithDestinationModePriorityTTLFails() throws Exception { + producer.send(destination, message, 1, 3, 111); + } +} + http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java new file mode 100644 index 0000000..e14bda6 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java @@ -0,0 +1,64 @@ +/** + * 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.producer; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.qpid.jms.JmsConnection; +import org.apache.qpid.jms.test.Wait; + +/** + * Tests the MessageProducer method contract when it's connection has failed. + */ +public class JmsMessageProducerFailedTest extends JmsMessageProducerClosedTest { + + @Override + protected MessageProducer createProducer() throws Exception { + connection = createConnectionToMockProvider(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + message = session.createMessage(); + destination = session.createQueue("test"); + MessageProducer producer = session.createProducer(destination); + connection.setExceptionListener(new ExceptionListener() { + + @Override + public void onException(JMSException exception) { + } + }); + connection.start(); + providerListener.onConnectionFailure(new IOException()); + + final JmsConnection jmsConnection = connection; + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return !jmsConnection.isConnected(); + } + }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2))); + + return producer; + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java new file mode 100644 index 0000000..ec1d962 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java @@ -0,0 +1,249 @@ +/** + * 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 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.JmsConnectionTestSupport; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests behaviour after a Session is closed. + */ +public class JmsSessionClosedTest extends JmsConnectionTestSupport { + + protected Session session; + protected MessageProducer sender; + protected MessageConsumer receiver; + + protected void createTestResources() throws Exception { + connection = createConnectionToMockProvider(); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue destination = session.createQueue(_testName.getMethodName()); + sender = session.createProducer(destination); + receiver = session.createConsumer(destination); + session.close(); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + createTestResources(); + } + + @Test(timeout=30000) + public void testSessionCloseAgain() throws Exception { + session.close(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateMessageFails() throws Exception { + session.createMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTextMessageFails() throws Exception { + session.createTextMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTextMessageWithTextFails() throws Exception { + session.createTextMessage("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateMapMessageFails() throws Exception { + session.createMapMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateStreamMessageFails() throws Exception { + session.createStreamMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateBytesMessageFails() throws Exception { + session.createBytesMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateObjectMessageFails() throws Exception { + session.createObjectMessage(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateObjectMessageWithObjectFails() throws Exception { + session.createObjectMessage("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetTransactedFails() throws Exception { + session.getTransacted(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetAcknowledgeModeFails() throws Exception { + session.getAcknowledgeMode(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCommitFails() throws Exception { + session.commit(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRollbackFails() throws Exception { + session.rollback(); + } + + @Test(timeout=30000) + public void testCloseDoesNotFail() throws Exception { + session.close(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testRecoverFails() throws Exception { + session.recover(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testGetMessageListenerFails() throws Exception { + session.getMessageListener(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testSetMessageListenerFails() throws Exception { + 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.run(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateProducerFails() throws Exception { + Destination destination = session.createQueue("test"); + session.createProducer(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioFails() throws Exception { + Destination destination = session.createQueue("test"); + session.createConsumer(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioSelectorFails() throws Exception { + Destination destination = session.createQueue("test"); + session.createConsumer(destination, "a = b"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateConsumerDestinatioSelectorBooleanFails() throws Exception { + Destination destination = session.createQueue("test"); + session.createConsumer(destination, "a = b", true); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueFails() throws Exception { + session.createQueue("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTopicFails() throws Exception { + session.createTopic("TEST"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTemporaryQueueFails() throws Exception { + session.createTemporaryQueue(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateTemporaryTopicFails() throws Exception { + session.createTemporaryQueue(); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateDurableSubscriberFails() throws Exception { + Topic destination = session.createTopic("TEST"); + session.createDurableSubscriber(destination, "test"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateDurableSubscriberSelectorBooleanFails() throws Exception { + Topic destination = session.createTopic("TEST"); + session.createDurableSubscriber(destination, "test", "a = b", false); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueBrowserFails() throws Exception { + Queue destination = session.createQueue("test"); + session.createBrowser(destination); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testCreateQueueBrowserWithSelectorFails() throws Exception { + Queue destination = session.createQueue("test"); + session.createBrowser(destination, "a = b"); + } + + @Test(timeout=30000, expected=JMSException.class) + public void testUnsubscribeFails() throws Exception { + session.unsubscribe("test"); + } + + // --- Test effects on consumer/producer opened previously on the session --- + + @Test(timeout=30000) + public void testConsumerCloseAgain() throws Exception { + // Close it again (closing the session should have closed it already). + receiver.close(); + } + + @Test(timeout=30000) + public void testProducerCloseAgain() throws Exception { + // Close it again (closing the session should have closed it already). + sender.close(); + } + + @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) + public void testConsumerGetMessageListenerFails() throws Exception { + receiver.getMessageListener(); + } + + @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) + public void testProducerGetDestinationFails() throws Exception { + sender.getDestination(); + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java new file mode 100644 index 0000000..a4b92f6 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java @@ -0,0 +1,64 @@ +/** + * 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.io.IOException; +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.test.Wait; + + +/** + * Tests the Session method contracts when the underlying connection is lost. + */ +public class JmsSessionFailedTest extends JmsSessionClosedTest { + + @Override + protected void createTestResources() throws Exception { + connection = createConnectionToMockProvider(); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + connection.setExceptionListener(new ExceptionListener() { + + @Override + public void onException(JMSException exception) { + } + }); + Queue destination = session.createQueue(_testName.getMethodName()); + + sender = session.createProducer(destination); + receiver = session.createConsumer(destination); + connection.start(); + providerListener.onConnectionFailure(new IOException()); + + final JmsConnection jmsConnection = connection; + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return !jmsConnection.isConnected(); + } + }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2))); + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java deleted file mode 100644 index a374b1a..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerClosedTest.java +++ /dev/null @@ -1,90 +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.consumer; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageListener; -import javax.jms.Queue; -import javax.jms.Session; - -import org.apache.qpid.jms.support.AmqpTestSupport; -import org.junit.Test; - -/** - * Tests MessageConsumer method contracts after the MessageConsumer is closed. - */ -public class JmsMessageConsumerClosedTest extends AmqpTestSupport { - - protected MessageConsumer consumer; - - protected MessageConsumer createConsumer() throws Exception { - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue destination = session.createQueue(name.getMethodName()); - MessageConsumer consumer = session.createConsumer(destination); - consumer.close(); - return consumer; - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetMessageSelectorFails() throws Exception { - consumer = createConsumer(); - consumer.getMessageSelector(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetMessageListenerFails() throws Exception { - consumer = createConsumer(); - consumer.getMessageListener(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetMessageListenerFails() throws Exception { - consumer = createConsumer(); - consumer.setMessageListener(new MessageListener() { - @Override - public void onMessage(Message message) { - } - }); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testRreceiveFails() throws Exception { - consumer = createConsumer(); - consumer.receive(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testRreceiveTimedFails() throws Exception { - consumer = createConsumer(); - consumer.receive(11); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testRreceiveNoWaitFails() throws Exception { - consumer = createConsumer(); - consumer.receiveNoWait(); - } - - @Test(timeout=30000) - public void testClose() throws Exception { - consumer = createConsumer(); - consumer.close(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java deleted file mode 100644 index 85b4b37..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerFailedTest.java +++ /dev/null @@ -1,65 +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.consumer; - -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.MessageConsumer; -import javax.jms.Queue; -import javax.jms.Session; - -import org.apache.qpid.jms.JmsConnection; -import org.apache.qpid.jms.support.Wait; - -/** - * Tests MessageConsumer method contracts after the MessageConsumer connection fails. - */ -public class JmsMessageConsumerFailedTest extends JmsMessageConsumerClosedTest { - - @Override - protected MessageConsumer createConsumer() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue destination = session.createQueue(name.getMethodName()); - MessageConsumer consumer = session.createConsumer(destination); - connection.setExceptionListener(new ExceptionListener() { - - @Override - public void onException(JMSException exception) { - latch.countDown(); - } - }); - connection.start(); - stopPrimaryBroker(); - assertTrue(latch.await(10, TimeUnit.SECONDS)); - final JmsConnection jmsConnection = (JmsConnection) connection; - assertTrue(Wait.waitFor(new Wait.Condition() { - - @Override - public boolean isSatisified() throws Exception { - return !jmsConnection.isConnected(); - } - })); - return consumer; - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java deleted file mode 100644 index d2aca10..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerClosedTest.java +++ /dev/null @@ -1,143 +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.producer; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageProducer; -import javax.jms.Session; - -import org.apache.qpid.jms.support.AmqpTestSupport; -import org.junit.Test; - -/** - * Test the contract of MessageProducer that has been closed. - */ -public class JmsMessageProducerClosedTest extends AmqpTestSupport { - - protected MessageProducer producer; - protected Message message; - protected Destination destination; - - protected MessageProducer createProducer() throws Exception { - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - message = session.createMessage(); - destination = session.createTopic("test"); - MessageProducer producer = session.createProducer(destination); - producer.close(); - return producer; - } - - @Test(timeout=30000) - public void testClose() throws Exception { - producer = createProducer(); - producer.close(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetDisableMessageIDFails() throws Exception { - producer = createProducer(); - producer.setDisableMessageID(true); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetDisableMessageIDFails() throws Exception { - producer = createProducer(); - producer.getDisableMessageID(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetDisableMessageTimestampFails() throws Exception { - producer = createProducer(); - producer.setDisableMessageTimestamp(false); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetDisableMessageTimestampFails() throws Exception { - producer = createProducer(); - producer.getDisableMessageTimestamp(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetDeliveryModeFails() throws Exception { - producer = createProducer(); - producer.setDeliveryMode(1); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetDeliveryModeFails() throws Exception { - producer = createProducer(); - producer.getDeliveryMode(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetPriorityFails() throws Exception { - producer = createProducer(); - producer.setPriority(1); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetPriorityFails() throws Exception { - producer = createProducer(); - producer.getPriority(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSetTimeToLiveFails() throws Exception { - producer = createProducer(); - producer.setTimeToLive(1); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetTimeToLiveFails() throws Exception { - producer = createProducer(); - producer.getTimeToLive(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testGetDestinationFails() throws Exception { - producer = createProducer(); - producer.getDestination(); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSendFails() throws Exception { - producer = createProducer(); - producer.send(message); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSendWithDestinationFails() throws Exception { - producer = createProducer(); - producer.send(destination, message); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSendWithModePriorityTTLFails() throws Exception { - producer = createProducer(); - producer.send(message, 1, 3, 111); - } - - @Test(timeout=30000, expected=JMSException.class) - public void testSendWithDestinationModePriorityTTLFails() throws Exception { - producer = createProducer(); - producer.send(destination, message, 1, 3, 111); - } -} - http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java deleted file mode 100644 index b6f5011..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerFailedTest.java +++ /dev/null @@ -1,65 +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.producer; - -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.MessageProducer; -import javax.jms.Session; - -import org.apache.qpid.jms.JmsConnection; -import org.apache.qpid.jms.support.Wait; - -/** - * Tests the MessageProducer method contract when it's connection has failed. - */ -public class JmsMessageProducerFailedTest extends JmsMessageProducerClosedTest { - - @Override - protected MessageProducer createProducer() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - connection = createAmqpConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - message = session.createMessage(); - destination = session.createQueue("test"); - MessageProducer producer = session.createProducer(destination); - connection.setExceptionListener(new ExceptionListener() { - - @Override - public void onException(JMSException exception) { - latch.countDown(); - } - }); - connection.start(); - stopPrimaryBroker(); - assertTrue(latch.await(10, TimeUnit.SECONDS)); - final JmsConnection jmsConnection = (JmsConnection) connection; - assertTrue(Wait.waitFor(new Wait.Condition() { - - @Override - public boolean isSatisified() throws Exception { - return !jmsConnection.isConnected(); - } - })); - return producer; - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/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 deleted file mode 100644 index a9ea137..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java +++ /dev/null @@ -1,285 +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.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; -import org.junit.Test; - -/** - * Tests behaviour after a Session is closed. - */ -public class JmsSessionClosedTest extends AmqpTestSupport { - - protected MessageProducer sender; - protected MessageConsumer receiver; - - protected Session createAndCloseSession() throws Exception { - JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI()); - connection = factory.createConnection(); - - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue destination = session.createQueue(name.getMethodName()); - - sender = session.createProducer(destination); - receiver = session.createConsumer(destination); - - // Close the session explicitly, without closing the above. - session.close(); - - return session; - } - - @Test(timeout=30000) - public void testSessionCloseAgain() throws Exception { - 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(); - // Close it again (closing the session should have closed it already). - receiver.close(); - } - - @Test(timeout=30000) - public void testProducerCloseAgain() throws Exception { - createAndCloseSession(); - // Close it again (closing the session should have closed it already). - sender.close(); - } - - @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) - public void testConsumerGetMessageListenerFails() throws Exception { - createAndCloseSession(); - receiver.getMessageListener(); - } - - @Test(timeout=30000, expected=javax.jms.IllegalStateException.class) - public void testProducerGetDestinationFails() throws Exception { - createAndCloseSession(); - sender.getDestination(); - } -} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/96b21b85/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 deleted file mode 100644 index 3b56d5c..0000000 --- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/session/JmsSessionFailedTest.java +++ /dev/null @@ -1,69 +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.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]
