activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6336 - queue browser delivers expired messages
Date Thu, 23 Jun 2016 15:47:24 GMT
Repository: activemq
Updated Branches:
  refs/heads/master 03785a4d5 -> 3dfda807f


https://issues.apache.org/jira/browse/AMQ-6336 - queue browser delivers expired messages


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3dfda807
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3dfda807
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3dfda807

Branch: refs/heads/master
Commit: 3dfda807f6c65f78badfccdbcec3676e45e66a2c
Parents: 03785a4
Author: Dejan Bosanac <dejan@nighttale.net>
Authored: Thu Jun 23 17:47:05 2016 +0200
Committer: Dejan Bosanac <dejan@nighttale.net>
Committed: Thu Jun 23 17:47:15 2016 +0200

----------------------------------------------------------------------
 .../activemq/ActiveMQMessageConsumer.java       | 11 +++--
 .../activemq/JmsQueueBrowserExpirationTest.java | 43 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/3dfda807/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
index 90ca7c2..9e532db 100755
--- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQMessageConsumer.java
@@ -1419,9 +1419,14 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer,
StatsC
                                 // delayed redelivery, ensure it can be re delivered
                                 session.connection.rollbackDuplicate(this, md.getMessage());
                             }
-                            unconsumedMessages.enqueue(md);
-                            if (availableListener != null) {
-                                availableListener.onMessageAvailable(this);
+                            if (!(md.getMessage() != null && md.getMessage().isExpired()))
{
+                                unconsumedMessages.enqueue(md);
+                                if (availableListener != null) {
+                                    availableListener.onMessageAvailable(this);
+                                }
+                            } else {
+                                beforeMessageIsConsumed(md);
+                                afterMessageIsConsumed(md, false);
                             }
                         }
                     } else {

http://git-wip-us.apache.org/repos/asf/activemq/blob/3dfda807/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserExpirationTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserExpirationTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserExpirationTest.java
index 1f4fff2..e6abbb8 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserExpirationTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/JmsQueueBrowserExpirationTest.java
@@ -26,6 +26,7 @@ import javax.jms.Connection;
 import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.MessageProducer;
+import javax.jms.Queue;
 import javax.jms.QueueBrowser;
 import javax.jms.Session;
 import javax.jms.TextMessage;
@@ -112,6 +113,48 @@ public class JmsQueueBrowserExpirationTest {
         browserConnection.close();
     }
 
+   @Test(timeout=10000)
+   public void testDoNotReceiveExpiredMessage() throws Exception {
+      int WAIT_TIME = 1000;
+
+      Connection connection = factory.createConnection();
+      connection.start();
+
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue producerQueue = session.createQueue("MyTestQueue");
+
+      MessageProducer producer = session.createProducer(producerQueue);
+      producer.setTimeToLive(WAIT_TIME);
+
+      TextMessage message = session.createTextMessage("Test message");
+      producer.send(producerQueue, message);
+
+      int count = getMessageCount(producerQueue, session);
+      assertEquals(1, count);
+
+      Thread.sleep(WAIT_TIME + 1000);
+
+      count = getMessageCount(producerQueue, session);
+      assertEquals(0, count);
+
+      producer.close();
+      session.close();
+      connection.close();
+   }
+
+    private int getMessageCount(Queue destination, Session session) throws Exception {
+        int result = 0;
+        QueueBrowser browser = session.createBrowser(destination);
+        Enumeration<?> enumeration = browser.getEnumeration();
+        while (enumeration.hasMoreElements()) {
+            ++result;
+            enumeration.nextElement();
+        }
+        browser.close();
+
+        return result;
+    }
+
     private int browse(ActiveMQQueue queue, Connection connection) throws JMSException {
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         QueueBrowser browser = session.createBrowser(queue);


Mime
View raw message