From 0b829558b32ac1fe34fab3f18cf2730a7a919e7c Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 23 Feb 2017 09:46:59 -0600 Subject: [PATCH] ARTEMIS-989 JMS2 context support custom session modes --- .../jms/client/ActiveMQConnectionFactory.java | 5 +- .../jms/consumer/JmsConsumerTest.java | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java index 4d314ce6c6..dee81573d1 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java @@ -48,6 +48,7 @@ import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.client.ActiveMQClient; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSConstants; import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory; @@ -297,7 +298,9 @@ public class ActiveMQConnectionFactory implements ConnectionFactoryOptions, Exte case JMSContext.AUTO_ACKNOWLEDGE: case JMSContext.CLIENT_ACKNOWLEDGE: case JMSContext.DUPS_OK_ACKNOWLEDGE: - case JMSContext.SESSION_TRANSACTED: { + case JMSContext.SESSION_TRANSACTED: + case ActiveMQJMSConstants.PRE_ACKNOWLEDGE: + case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE: { return; } default: diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/consumer/JmsConsumerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/consumer/JmsConsumerTest.java index 4856b5d552..d242da88b7 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/consumer/JmsConsumerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/consumer/JmsConsumerTest.java @@ -184,6 +184,52 @@ public class JmsConsumerTest extends JMSTestBase { conn.close(); } + @Test + public void testIndividualACKJms2() throws Exception { + JMSContext context = cf.createContext(ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE); + jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME); + JMSProducer producer = context.createProducer(); + JMSConsumer consumer = context.createConsumer(jBossQueue); + int noOfMessages = 100; + for (int i = 0; i < noOfMessages; i++) { + producer.send(jBossQueue, context.createTextMessage("m" + i)); + } + + context.start(); + + // Consume even numbers first + for (int i = 0; i < noOfMessages; i++) { + Message m = consumer.receive(500); + Assert.assertNotNull(m); + if (i % 2 == 0) { + m.acknowledge(); + } + } + + context.close(); + + context = cf.createContext(ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE); + + consumer = context.createConsumer(jBossQueue); + + // Consume odd numbers first + for (int i = 0; i < noOfMessages; i++) { + if (i % 2 == 0) { + continue; + } + + TextMessage m = (TextMessage) consumer.receive(1000); + Assert.assertNotNull(m); + m.acknowledge(); + Assert.assertEquals("m" + i, m.getText()); + } + + SimpleString queueName = new SimpleString(JmsConsumerTest.Q_NAME); + Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(queueName).getBindable()).getDeliveringCount()); + Assert.assertEquals(0, getMessageCount((Queue) server.getPostOffice().getBinding(queueName).getBindable())); + context.close(); + } + @Test public void testIndividualACKMessageConsumer() throws Exception { Connection conn = cf.createConnection();