summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2008-02-07 18:15:20 +0000
committerRafael H. Schloming <rhs@apache.org>2008-02-07 18:15:20 +0000
commit021713fbe45e92e5eef13184be711c7156d7db00 (patch)
tree525bbaa32a1099f1ae35b0e92b03684bd6c1cdee /java
parent06ca351132b86961e14ee59f7353c1f7e1a0f50a (diff)
downloadqpid-python-021713fbe45e92e5eef13184be711c7156d7db00.tar.gz
added test for exception listener; fixed NPE
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@619538 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java12
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java62
-rw-r--r--java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java2
-rw-r--r--java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java50
-rw-r--r--java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java23
5 files changed, 123 insertions, 26 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
index e7a2a62e19..bf1ed49492 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
+++ b/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/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
new file mode 100644
index 0000000000..20461415d1
--- /dev/null
+++ b/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/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
index 8ab381db32..0ccb50dda3 100644
--- a/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
+++ b/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();
}
diff --git a/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java b/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
new file mode 100644
index 0000000000..bbd1722677
--- /dev/null
+++ b/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
@@ -0,0 +1,50 @@
+/*
+ *
+ * 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.util.concurrent;
+
+
+/**
+ * Condition
+ *
+ */
+
+public class Condition
+{
+
+ private boolean value = false;
+
+ public synchronized void set()
+ {
+ value = true;
+ notifyAll();
+ }
+
+ public synchronized boolean get(long timeout) throws InterruptedException
+ {
+ if (!value)
+ {
+ wait(timeout);
+ }
+
+ return value;
+ }
+
+}
diff --git a/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java b/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
index 167b02a556..55d53ebaae 100644
--- a/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
+++ b/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
@@ -22,6 +22,8 @@ package org.apache.qpidity.transport;
import org.apache.mina.util.AvailablePortFinder;
+import org.apache.qpid.util.concurrent.Condition;
+
import org.apache.qpidity.transport.network.mina.MinaHandler;
import org.apache.qpidity.transport.util.Logger;
@@ -63,27 +65,6 @@ public class ConnectionTest extends TestCase
MinaHandler.accept("0.0.0.0", port, server);
}
- private class Condition
- {
- private boolean value = false;
-
- public synchronized void set()
- {
- value = true;
- notifyAll();
- }
-
- public synchronized boolean get(long timeout) throws InterruptedException
- {
- if (!value)
- {
- wait(timeout);
- }
-
- return value;
- }
- }
-
private Connection connect(final Condition closed)
{
Connection conn = MinaHandler.connect("0.0.0.0", port, new ConnectionDelegate()