Repository: qpid-jms Updated Branches: refs/heads/master 4bfe7f5ae -> 384599110
QPIDJMS-395 Throw a more descriptive exception type when forced Use a somewhat more descriptive exception type when the connection is remotely closed due to a forced error condition to aid in debug. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/38459911 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/38459911 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/38459911 Branch: refs/heads/master Commit: 3845991106aaad1421fbf3bdb4375f367c2ac9cd Parents: 4bfe7f5 Author: Timothy Bish <tabish...@gmail.com> Authored: Tue Jun 19 19:04:20 2018 -0400 Committer: Timothy Bish <tabish...@gmail.com> Committed: Tue Jun 19 19:04:20 2018 -0400 ---------------------------------------------------------------------- .../JmsConnectionRemotelyClosedException.java | 36 +++++++++++++++++ .../qpid/jms/provider/amqp/AmqpSupport.java | 3 ++ .../integration/ConnectionIntegrationTest.java | 42 +++++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/38459911/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionRemotelyClosedException.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionRemotelyClosedException.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionRemotelyClosedException.java new file mode 100644 index 0000000..0aa39f5 --- /dev/null +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionRemotelyClosedException.java @@ -0,0 +1,36 @@ +/* + * 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.JMSException; + +/** + * Thrown when the remote peer closes the connection with amqp:connection:forced + * signaling that the connection is closed. + */ +public class JmsConnectionRemotelyClosedException extends JMSException { + + private static final long serialVersionUID = -4811726481264524424L; + + public JmsConnectionRemotelyClosedException(String reason) { + super(reason); + } + + public JmsConnectionRemotelyClosedException(String reason, String errorCode) { + super(reason, errorCode); + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/38459911/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java index 62c5001..f93d49f 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java @@ -26,6 +26,7 @@ import javax.jms.JMSSecurityException; import javax.jms.ResourceAllocationException; import javax.jms.TransactionRolledBackException; +import org.apache.qpid.jms.JmsConnectionRemotelyClosedException; import org.apache.qpid.jms.JmsResourceNotFoundException; import org.apache.qpid.jms.provider.ProviderRedirectedException; import org.apache.qpid.proton.amqp.Symbol; @@ -143,6 +144,8 @@ public class AmqpSupport { remoteError = new JMSSecurityException(message); } else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) { remoteError = new ResourceAllocationException(message); + } else if (error.equals(ConnectionError.CONNECTION_FORCED)) { + remoteError = new JmsConnectionRemotelyClosedException(message); } else if (error.equals(AmqpError.NOT_FOUND)) { if (endpoint instanceof Connection) { remoteError = new JmsResourceNotFoundException(message); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/38459911/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java index c2f6f5f..8455640 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java @@ -58,10 +58,12 @@ import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Queue; +import javax.jms.ResourceAllocationException; import javax.jms.Session; import org.apache.qpid.jms.JmsConnection; import org.apache.qpid.jms.JmsConnectionFactory; +import org.apache.qpid.jms.JmsConnectionRemotelyClosedException; import org.apache.qpid.jms.JmsDefaultConnectionListener; import org.apache.qpid.jms.provider.ProviderRedirectedException; import org.apache.qpid.jms.provider.amqp.AmqpSupport; @@ -71,6 +73,7 @@ import org.apache.qpid.jms.test.testpeer.TestAmqpPeer; import org.apache.qpid.jms.test.testpeer.basictypes.AmqpError; import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError; import org.apache.qpid.jms.test.testpeer.matchers.CoordinatorMatcher; +import org.apache.qpid.jms.test.testpeer.matchers.sections.TransferPayloadCompositeMatcher; import org.apache.qpid.jms.util.MetaDataSupport; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.Symbol; @@ -645,7 +648,44 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase { try { producer.send(message); fail("Expected exception to be thrown"); - } catch (JMSException jmse) { + } catch (ResourceAllocationException jmse) { + // Expected + assertNotNull("Expected exception to have a message", jmse.getMessage()); + assertTrue("Expected breadcrumb to be present in message", jmse.getMessage().contains(BREAD_CRUMB)); + } + + connection.close(); + + testPeer.waitForAllHandlersToComplete(3000); + } + } + + @Test(timeout = 20000) + public void testRemotelyEndConnectionWithSessionWithProducerWithSendWaitingOnOutcome() throws Exception { + final String BREAD_CRUMB = "ErrorMessageBreadCrumb"; + + try (TestAmqpPeer testPeer = new TestAmqpPeer();) { + Connection connection = testFixture.establishConnecton(testPeer); + + testPeer.expectBegin(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Expect producer creation, don't give it credit. + testPeer.expectSenderAttach(); + testPeer.expectTransferButDoNotRespond(new TransferPayloadCompositeMatcher()); + + // Producer has no credit so the send should block waiting for it. + testPeer.remotelyCloseConnection(true, ConnectionError.CONNECTION_FORCED, BREAD_CRUMB, 50); + + Queue queue = session.createQueue("myQueue"); + final MessageProducer producer = session.createProducer(queue); + + Message message = session.createTextMessage("myMessage"); + + try { + producer.send(message); + fail("Expected exception to be thrown"); + } catch (JmsConnectionRemotelyClosedException jmse) { // Expected assertNotNull("Expected exception to have a message", jmse.getMessage()); assertTrue("Expected breadcrumb to be present in message", jmse.getMessage().contains(BREAD_CRUMB)); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org