Author: rhs
Date: Thu Feb  7 10:15:20 2008
New Revision: 619538

URL: http://svn.apache.org/viewvc?rev=619538&view=rev
Log:
added test for exception listener; fixed NPE

Added:
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
   (with props)
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
   (with props)
Modified:
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
    
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=619538&r1=619537&r2=619538&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
 Thu Feb  7 10:15:20 2008
@@ -148,11 +148,15 @@
         {
             _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);
     }
 }

Added: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java?rev=619538&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
 Thu Feb  7 10:15:20 2008
@@ -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");
+        }
+    }
+
+}

Propchange: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java?rev=619538&r1=619537&r2=619538&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
 Thu Feb  7 10:15:20 2008
@@ -122,7 +122,7 @@
             _brokerProcess.destroy();
             _brokerProcess = null;
         }
-        else   if ( ! _shel.equals(EXT_BROKER))
+        else   if ( _shel.equals(BROKER_VM))
         {
             TransportConnection.killAllVMBrokers();
         }

Added: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java?rev=619538&view=auto
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
 Thu Feb  7 10:15:20 2008
@@ -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;
+    }
+
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/Condition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java?rev=619538&r1=619537&r2=619538&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java
 Thu Feb  7 10:15:20 2008
@@ -22,6 +22,8 @@
 
 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;
 
@@ -61,27 +63,6 @@
         };
 
         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)


Reply via email to