diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2008-02-07 18:15:20 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2008-02-07 18:15:20 +0000 |
| commit | 52e81e74a91433167ebc4c6ca22c088d16d9fbbd (patch) | |
| tree | 4d13a5a0b93e9cc2753726c5b0204fda28dfad21 /qpid/java/client/src | |
| parent | 4bc30db6cb860f83d0ca685c573277c09fd63567 (diff) | |
| download | qpid-python-52e81e74a91433167ebc4c6ca22c088d16d9fbbd.tar.gz | |
added test for exception listener; fixed NPE
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@619538 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src')
3 files changed, 71 insertions, 5 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java index e7a2a62e19..bf1ed49492 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java @@ -148,11 +148,15 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Closed { _logger.debug("Received a connection close from the broker: Error code : " + errorCode.getCode()); } - JMSException ex = new JMSException(reason,String.valueOf(errorCode.getCode())); - if (t != null) + if (_conn._exceptionListener != null) { - ex.initCause(t); + JMSException ex = new JMSException(reason,String.valueOf(errorCode.getCode())); + if (t != null) + { + ex.initCause(t); + } + + _conn._exceptionListener.onException(ex); } - _conn._exceptionListener.onException(ex); } } diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java new file mode 100644 index 0000000000..20461415d1 --- /dev/null +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java @@ -0,0 +1,62 @@ +/* + * + * 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.test.unit.client.connection; + +import org.apache.qpid.testutil.QpidTestCase; + +import org.apache.qpid.util.concurrent.Condition; + +import javax.jms.Connection; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; + +/** + * ExceptionListenerTest + * + */ + +public class ExceptionListenerTest extends QpidTestCase +{ + + public void testBrokerDeath() throws Exception + { + Connection conn = getConnection("guest", "guest"); + + conn.start(); + + final Condition fired = new Condition(); + conn.setExceptionListener(new ExceptionListener() + { + public void onException(JMSException e) + { + fired.set(); + } + }); + + killBroker(); + + if (!fired.get(3000)) + { + fail("exception listener was not fired"); + } + } + +} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java index 8ab381db32..0ccb50dda3 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java @@ -122,7 +122,7 @@ public class QpidTestCase extends TestCase _brokerProcess.destroy(); _brokerProcess = null; } - else if ( ! _shel.equals(EXT_BROKER)) + else if ( _shel.equals(BROKER_VM)) { TransportConnection.killAllVMBrokers(); } |
