activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject activemq-artemis git commit: NO-JIRA: add an AMQP test that acks out of order, leveraging individual ack support from QPIDJMS-357
Date Mon, 29 Jan 2018 14:59:12 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master b66d0f7ac -> d02a1423b


NO-JIRA: add an AMQP test that acks out of order, leveraging individual ack support from QPIDJMS-357


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

Branch: refs/heads/master
Commit: d02a1423bafb7d4cfff24fe222af0c089f7e068d
Parents: b66d0f7
Author: Robbie Gemmell <robbie@apache.org>
Authored: Mon Jan 29 14:55:23 2018 +0000
Committer: Robbie Gemmell <robbie@apache.org>
Committed: Mon Jan 29 14:55:23 2018 +0000

----------------------------------------------------------------------
 .../integration/amqp/JMSAcknowledgeTest.java    | 101 +++++++++++++++++++
 1 file changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/d02a1423/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSAcknowledgeTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSAcknowledgeTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSAcknowledgeTest.java
new file mode 100644
index 0000000..938cfd4
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMSAcknowledgeTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.activemq.artemis.tests.integration.amqp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.artemis.core.server.Queue;
+import org.apache.activemq.artemis.tests.util.Wait;
+import org.junit.Test;
+
+public class JMSAcknowledgeTest extends JMSClientTestSupport {
+
+   private static final String MSG_NUM = "MSG_NUM";
+   private static final int INDIVIDUAL_ACK = 101;
+
+   @Test(timeout = 60000)
+   public void testConsumeIndividualMessagesOutOfOrder() throws Throwable {
+      Connection connection = createConnection();
+
+      // Send some messages
+      Session session = connection.createSession(false, INDIVIDUAL_ACK);
+      javax.jms.Queue queue = session.createQueue(getQueueName());
+
+      int msgCount = 10;
+      MessageProducer p = session.createProducer(queue);
+      for (int i = 0; i < msgCount; i++) {
+         TextMessage message = session.createTextMessage();
+         message.setText("Message:" + i);
+         message.setIntProperty(MSG_NUM, i);
+         p.send(message);
+      }
+
+      // Check they arrived
+      Queue queueView = getProxyToQueue(getQueueName());
+      Wait.assertEquals(10, queueView::getMessageCount);
+
+      // Consume them, ack some of them, out of order
+      MessageConsumer cons = session.createConsumer(queue);
+      connection.start();
+
+      List<Message> messages = new ArrayList<>();
+      for (int i = 0; i < msgCount; i++) {
+         TextMessage message = (TextMessage) cons.receive(5000);
+         assertNotNull("Message " + i + " was not received", message);
+         assertEquals("unexpected message number property", i, message.getIntProperty(MSG_NUM));
+
+         messages.add(message);
+      }
+
+      List<Integer> acknowledged = new ArrayList<>();
+
+      Random rand = new Random();
+      for (int i = 0; i < msgCount / 2; i++) {
+         Message msg = messages.remove(rand.nextInt(msgCount - i));
+
+         int messageNumber =  msg.getIntProperty(MSG_NUM);
+         acknowledged.add(messageNumber);
+
+         msg.acknowledge();
+      }
+
+      session.close();
+
+      Wait.assertEquals(msgCount / 2, queueView::getMessageCount);
+
+      // Consume them again, verify the rest are in expected sequence
+      session = connection.createSession(false, INDIVIDUAL_ACK);
+      cons = session.createConsumer(queue);
+
+      for (int i = 0; i < msgCount / 2; i++) {
+         TextMessage message = (TextMessage) cons.receive(5000);
+         assertNotNull("Message " + i + " was not received", message);
+         Message expectedMsg = messages.remove(0);
+         int expectedMsgNum = expectedMsg.getIntProperty(MSG_NUM);
+         assertEquals("unexpected message number property", expectedMsgNum, message.getIntProperty(MSG_NUM));
+      }
+   }
+}
\ No newline at end of file


Mime
View raw message