qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1733874 - in /qpid/java/trunk/systests/src: main/java/org/apache/qpid/test/utils/ test/java/org/apache/qpid/systest/rest/ test/java/org/apache/qpid/test/client/
Date Mon, 07 Mar 2016 07:52:04 GMT
Author: kwall
Date: Mon Mar  7 07:52:04 2016
New Revision: 1733874

URL: http://svn.apache.org/viewvc?rev=1733874&view=rev
Log:
QPID-7122: Tidy up exception handling CloseOnNoRouteForMandatoryMessageTest / remove some
superfluous tests

* Also removed some excessive system tests that tested that amonted to no more than AMQShortString
not exceeding 255 characters

Modified:
    qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
    qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
    qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/CloseOnNoRouteForMandatoryMessageTest.java
    qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/ImmediateAndMandatoryPublishingTest.java
    qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/UnroutableMessageTestExceptionListener.java

Modified: qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1733874&r1=1733873&r2=1733874&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
(original)
+++ qpid/java/trunk/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
Mon Mar  7 07:52:04 2016
@@ -721,19 +721,6 @@ public class QpidBrokerTestCase extends
     }
 
     /**
-     * Useful, for example, to avoid the connection being automatically closed in {@link
#tearDown()}
-     * if it has deliberately been put into an error state already.
-     */
-    protected void forgetConnection(Connection connection)
-    {
-        _logger.debug("Forgetting about connection " + connection);
-        boolean removed = _connections.remove(connection);
-        assertTrue(
-                "The supplied connection " + connection + " should have been one that I already
know about",
-                removed);
-    }
-
-    /**
      * Return a uniqueName for this test.
      * In this case it returns a queue Named by the TestCase and TestName
      *

Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java?rev=1733874&r1=1733873&r2=1733874&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
(original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
Mon Mar  7 07:52:04 2016
@@ -27,11 +27,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
-import javax.jms.Connection;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
 import org.apache.qpid.configuration.CommonProperties;
 import org.apache.qpid.server.management.plugin.servlet.rest.RestServlet;
 import org.apache.qpid.server.model.Broker;
@@ -41,7 +36,6 @@ import org.apache.qpid.server.model.Life
 import org.apache.qpid.server.model.Port;
 import org.apache.qpid.server.model.State;
 import org.apache.qpid.server.model.VirtualHostNode;
-import org.apache.qpid.test.client.UnroutableMessageTestExceptionListener;
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.util.SystemUtils;
 
@@ -150,33 +144,6 @@ public class BrokerRestTest extends Qpid
 
     }
 
-    public void testSetCloseOnNoRoute() throws Exception
-    {
-        Map<String, Object> brokerDetails = getRestTestHelper().getJsonAsSingletonList("broker");
-        assertTrue("closeOnNoRoute should be true", (Boolean)brokerDetails.get(Broker.CONNECTION_CLOSE_WHEN_NO_ROUTE));
-
-        Map<String, Object> brokerAttributes = new HashMap<String, Object>();
-        brokerAttributes.put(Broker.CONNECTION_CLOSE_WHEN_NO_ROUTE, false);
-
-        int response = getRestTestHelper().submitRequest("broker", "PUT", brokerAttributes);
-        assertEquals("Unexpected update response", 200, response);
-
-        brokerDetails = getRestTestHelper().getJsonAsSingletonList("broker");
-        assertFalse("closeOnNoRoute should be false", (Boolean)brokerDetails.get(Broker.CONNECTION_CLOSE_WHEN_NO_ROUTE));
-
-        Connection connection = getConnection();
-        UnroutableMessageTestExceptionListener exceptionListener = new UnroutableMessageTestExceptionListener();
-        connection.setExceptionListener(exceptionListener);
-        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
-        MessageProducer producer = session.createProducer(getTestQueue());
-        TextMessage message = session.createTextMessage("Test");
-        producer.send(message);
-
-        session.commit();
-
-        exceptionListener.assertReceivedNoRouteWithReturnedMessage(message, getTestQueueName());
-    }
-
     private Map<String, Object> getValidBrokerAttributes()
     {
         Map<String, Object> brokerAttributes = new HashMap<String, Object>();

Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/CloseOnNoRouteForMandatoryMessageTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/CloseOnNoRouteForMandatoryMessageTest.java?rev=1733874&r1=1733873&r2=1733874&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/CloseOnNoRouteForMandatoryMessageTest.java
(original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/CloseOnNoRouteForMandatoryMessageTest.java
Mon Mar  7 07:52:04 2016
@@ -22,24 +22,17 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.jms.Connection;
-import javax.jms.Destination;
 import javax.jms.IllegalStateException;
-import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
-import javax.naming.NamingException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.qpid.AMQException;
-import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
 import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.url.URLSyntaxException;
 
 /**
  * Tests the broker's connection-closing behaviour when it receives an unroutable message
@@ -54,12 +47,6 @@ public class CloseOnNoRouteForMandatoryM
     private Connection _connection;
     private UnroutableMessageTestExceptionListener _testExceptionListener = new UnroutableMessageTestExceptionListener();
 
-    @Override
-    public void setUp() throws Exception
-    {
-        super.setUp();
-    }
-
     public void testNoRoute_brokerClosesConnection() throws Exception
     {
         createConnectionWithCloseWhenNoRoute(true);
@@ -87,88 +74,6 @@ public class CloseOnNoRouteForMandatoryM
             //The session was marked closed even before we had a chance to call commit on
it
             assertTrue("ISE did not indicate closure", ise.getMessage().contains("closed"));
         }
-
-        forgetConnection(_connection);
-    }
-
-    public void testCloseOnNoRouteWhenExceptionMessageLengthIsGreater255() throws Exception
-    {
-        createConnectionWithCloseWhenNoRoute(true);
-
-        AMQSession<?, ?> transactedSession = (AMQSession<?, ?>) _connection.createSession(true,
Session.SESSION_TRANSACTED);
-
-        StringBuilder longExchangeName = getLongExchangeName();
-
-        String exchangeName = longExchangeName.toString();
-        transactedSession.declareExchange(exchangeName, "direct", false);
-
-        Destination testQueue = new AMQQueue(exchangeName, getTestQueueName());
-        MessageProducer mandatoryProducer = transactedSession.createProducer(
-                testQueue,
-                true, // mandatory
-                false); // immediate
-
-        Message message = transactedSession.createMessage();
-        mandatoryProducer.send(message);
-        try
-        {
-            transactedSession.commit();
-            fail("Expected exception not thrown");
-        }
-        catch (IllegalStateException ise)
-        {
-            _logger.debug("Caught exception", ise);
-            //The session was marked closed even before we had a chance to call commit on
it
-            assertTrue("ISE did not indicate closure", ise.getMessage().contains("closed"));
-        }
-        catch (JMSException e)
-        {
-            _logger.debug("Caught exception", e);
-            AMQException noRouteException = (AMQException) e.getLinkedException();
-            assertNotNull("AMQException should be linked to JMSException", noRouteException);
-
-            assertEquals(AMQConstant.NO_ROUTE, noRouteException.getErrorCode());
-            String expectedMessage = "Error: No route for message [Exchange: " + longExchangeName.substring(0,
220) + "...";
-            assertEquals("Unexpected exception message: " + noRouteException.getMessage(),
expectedMessage,
-                    noRouteException.getMessage());
-        }
-        finally
-        {
-            forgetConnection(_connection);
-        }
-    }
-
-    public void testNoRouteMessageReurnedWhenExceptionMessageLengthIsGreater255() throws
Exception
-    {
-        createConnectionWithCloseWhenNoRoute(false);
-
-        AMQSession<?, ?> transactedSession = (AMQSession<?, ?>) _connection.createSession(true,
Session.SESSION_TRANSACTED);
-
-        StringBuilder longExchangeName = getLongExchangeName();
-
-        String exchangeName = longExchangeName.toString();
-        transactedSession.declareExchange(exchangeName, "direct", false);
-
-        AMQQueue testQueue = new AMQQueue(exchangeName, getTestQueueName());
-        MessageProducer mandatoryProducer = transactedSession.createProducer(
-                testQueue,
-                true, // mandatory
-                false); // immediate
-
-        Message message = transactedSession.createMessage();
-        mandatoryProducer.send(message);
-        transactedSession.commit();
-        _testExceptionListener.assertReceivedReturnedMessageWithLongExceptionMessage(message,
testQueue);
-    }
-
-    private StringBuilder getLongExchangeName()
-    {
-        StringBuilder longExchangeName = new StringBuilder();
-        for (int i = 0; i < 50; i++)
-        {
-            longExchangeName.append("abcde");
-        }
-        return longExchangeName;
     }
 
     public void testNoRouteForNonMandatoryMessage_brokerKeepsConnectionOpenAndCallsExceptionListener()
throws Exception
@@ -206,9 +111,6 @@ public class CloseOnNoRouteForMandatoryM
         Message message = nonTransactedSession.createMessage();
         mandatoryProducer.send(message);
 
-        // should succeed - the message is asynchronously bounced back to the exception listener
-        message.acknowledge();
-
         _testExceptionListener.assertReceivedNoRouteWithReturnedMessage(message, getTestQueueName());
     }
 
@@ -229,9 +131,9 @@ public class CloseOnNoRouteForMandatoryM
         _testExceptionListener.assertReceivedNoRouteWithReturnedMessage(message, getTestQueueName());
     }
 
-    private void createConnectionWithCloseWhenNoRoute(boolean closeWhenNoRoute) throws URLSyntaxException,
NamingException, JMSException
+    private void createConnectionWithCloseWhenNoRoute(boolean closeWhenNoRoute) throws Exception
     {
-        Map<String, String> options = new HashMap<String, String>();
+        Map<String, String> options = new HashMap<>();
         options.put(ConnectionURL.OPTIONS_CLOSE_WHEN_NO_ROUTE, Boolean.toString(closeWhenNoRoute));
         _connection = getConnectionWithOptions(options);
         _connection.setExceptionListener(_testExceptionListener);

Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/ImmediateAndMandatoryPublishingTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/ImmediateAndMandatoryPublishingTest.java?rev=1733874&r1=1733873&r2=1733874&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/ImmediateAndMandatoryPublishingTest.java
(original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/ImmediateAndMandatoryPublishingTest.java
Mon Mar  7 07:52:04 2016
@@ -107,7 +107,7 @@ public class ImmediateAndMandatoryPublis
     }
 
     private void publishIntoExistingDestinationWithNoConsumerAndImmediateOn(int acknowledgeMode,
boolean pubSub)
-            throws JMSException, InterruptedException
+            throws Exception
     {
         consumerCreateAndClose(pubSub, true);
 
@@ -116,15 +116,13 @@ public class ImmediateAndMandatoryPublis
         _testExceptionListener.assertReceivedNoConsumersWithReturnedMessage(message);
     }
 
-    private void publishWithMandatoryOnImmediateOff(int acknowledgeMode, boolean pubSub)
throws JMSException,
-            InterruptedException
+    private void publishWithMandatoryOnImmediateOff(int acknowledgeMode, boolean pubSub)
throws Exception
     {
         Message message = produceMessage(acknowledgeMode, pubSub, true, false);
         _testExceptionListener.assertReceivedNoRouteWithReturnedMessage(message, getTestQueueName());
     }
 
-    private void publishWithMandatoryOffImmediateOff(int acknowledgeMode, boolean pubSub)
throws JMSException,
-            InterruptedException
+    private void publishWithMandatoryOffImmediateOff(int acknowledgeMode, boolean pubSub)
throws Exception
     {
         produceMessage(acknowledgeMode, pubSub, false, false);
 
@@ -180,7 +178,7 @@ public class ImmediateAndMandatoryPublis
         return message;
     }
 
-    public void testMandatoryAndImmediateDefaults() throws JMSException, InterruptedException
+    public void testMandatoryAndImmediateDefaults() throws Exception
     {
         Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
@@ -213,7 +211,7 @@ public class ImmediateAndMandatoryPublis
         session.close();
     }
 
-    public void testMandatoryAndImmediateSystemProperties() throws JMSException, InterruptedException
+    public void testMandatoryAndImmediateSystemProperties() throws Exception
     {
         setTestClientSystemProperty("qpid.default_mandatory","true");
         Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Modified: qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/UnroutableMessageTestExceptionListener.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/UnroutableMessageTestExceptionListener.java?rev=1733874&r1=1733873&r2=1733874&view=diff
==============================================================================
--- qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/UnroutableMessageTestExceptionListener.java
(original)
+++ qpid/java/trunk/systests/src/test/java/org/apache/qpid/test/client/UnroutableMessageTestExceptionListener.java
Mon Mar  7 07:52:04 2016
@@ -38,7 +38,6 @@ import org.slf4j.LoggerFactory;
 import org.apache.qpid.AMQException;
 import org.apache.qpid.client.AMQNoConsumersException;
 import org.apache.qpid.client.AMQNoRouteException;
-import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.protocol.AMQConstant;
 
 /**
@@ -71,19 +70,19 @@ public class UnroutableMessageTestExcept
         _exceptions.add(e);
     }
 
-    public void assertReceivedNoRouteWithReturnedMessage(Message message, String intendedQueueName)
+    public void assertReceivedNoRouteWithReturnedMessage(Message message, String intendedQueueName)
throws Exception
     {
         JMSException exception = getReceivedException();
         assertNoRouteExceptionWithReturnedMessage(exception, message, intendedQueueName);
     }
 
-    public void assertReceivedNoRoute(String intendedQueueName)
+    public void assertReceivedNoRoute(String intendedQueueName) throws Exception
     {
         JMSException exception = getReceivedException();
         assertNoRoute(exception, intendedQueueName);
     }
 
-    public void assertReceivedNoConsumersWithReturnedMessage(Message message)
+    public void assertReceivedNoConsumersWithReturnedMessage(Message message) throws Exception
     {
         JMSException exception = getReceivedException();
         AMQNoConsumersException noConsumersException = (AMQNoConsumersException) exception.getLinkedException();
@@ -91,48 +90,25 @@ public class UnroutableMessageTestExcept
         Message bounceMessage = (Message) noConsumersException.getUndeliveredMessage();
         assertNotNull("Bounced Message is expected", bounceMessage);
 
-        try
-        {
-            assertEquals("Unexpected message is bounced", message.getJMSMessageID(), bounceMessage.getJMSMessageID());
-        }
-        catch (JMSException e)
-        {
-            throw new RuntimeException("Couldn't check exception", e);
-        }
-    }
-
-    public void assertReceivedReturnedMessageWithLongExceptionMessage(Message message, AMQQueue
queue)
-    {
-        JMSException exception = getReceivedException();
-        assertNoRouteException(exception, message);
-        String exchangeName = queue.getExchangeName();
-        String expectedMessage = "Error: No Route for message [Exchange: " + exchangeName.substring(0,
220) + "...";
-        assertTrue("Unexpected exception message: " + exception.getMessage(), exception.getMessage().contains(expectedMessage));
+        assertEquals("Unexpected message is bounced", message.getJMSMessageID(), bounceMessage.getJMSMessageID());
     }
 
     public void assertNoRouteExceptionWithReturnedMessage(
-            JMSException exception, Message message, String intendedQueueName)
+            JMSException exception, Message message, String intendedQueueName) throws Exception
     {
         assertNoRoute(exception, intendedQueueName);
 
         assertNoRouteException(exception, message);
     }
 
-    private void assertNoRouteException(JMSException exception, Message message)
+    private void assertNoRouteException(JMSException exception, Message message) throws Exception
     {
         AMQNoRouteException noRouteException = (AMQNoRouteException) exception.getLinkedException();
         assertNotNull("AMQNoRouteException should be linked to JMSException", noRouteException);
         Message bounceMessage = (Message) noRouteException.getUndeliveredMessage();
         assertNotNull("Bounced Message is expected", bounceMessage);
 
-        try
-        {
-            assertEquals("Unexpected message is bounced", message.getJMSMessageID(), bounceMessage.getJMSMessageID());
-        }
-        catch (JMSException e)
-        {
-            throw new RuntimeException("Couldn't check exception", e);
-        }
+        assertEquals("Unexpected message is bounced", message.getJMSMessageID(), bounceMessage.getJMSMessageID());
     }
 
     public void assertNoRoute(JMSException exception, String intendedQueueName)
@@ -151,29 +127,15 @@ public class UnroutableMessageTestExcept
     }
 
 
-    public void assertNoException()
+    public void assertNoException() throws Exception
+    {
+        assertNull("Unexpected JMSException", _exceptions.poll(NEGATIVE_TIMEOUT, TimeUnit.SECONDS));
+    }
+
+    private JMSException getReceivedException() throws Exception
     {
-        try
-        {
-            assertNull("Unexpected JMSException", _exceptions.poll(NEGATIVE_TIMEOUT, TimeUnit.SECONDS));
-        }
-        catch (InterruptedException e)
-        {
-            throw new RuntimeException("Couldn't check exception", e);
-        }
-    }
-
-    private JMSException getReceivedException()
-    {
-        try
-        {
-            JMSException exception = _exceptions.poll(POSITIVE_TIMEOUT, TimeUnit.SECONDS);
-            assertNotNull("JMSException is expected", exception);
-            return exception;
-        }
-        catch(InterruptedException e)
-        {
-            throw new RuntimeException("Couldn't check exception", e);
-        }
+        JMSException exception = _exceptions.poll(POSITIVE_TIMEOUT, TimeUnit.SECONDS);
+        assertNotNull("JMSException is expected", exception);
+        return exception;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message