From commits-return-50324-archive-asf-public=cust-asf.ponee.io@activemq.apache.org Mon Jan 29 15:59:13 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id E5113180654 for ; Mon, 29 Jan 2018 15:59:13 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D4519160C31; Mon, 29 Jan 2018 14:59:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 27B05160C2C for ; Mon, 29 Jan 2018 15:59:13 +0100 (CET) Received: (qmail 68905 invoked by uid 500); 29 Jan 2018 14:59:12 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 68896 invoked by uid 99); 29 Jan 2018 14:59:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Jan 2018 14:59:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3FCB3E9454; Mon, 29 Jan 2018 14:59:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: robbie@apache.org To: commits@activemq.apache.org Message-Id: <4c00e2e6827a46eba901e67dcd7a2b91@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) 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 Authored: Mon Jan 29 14:55:23 2018 +0000 Committer: Robbie Gemmell 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 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 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