[
https://issues.apache.org/jira/browse/AMQ-8322?focusedWorklogId=786154&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-786154
]
ASF GitHub Bot logged work on AMQ-8322:
---------------------------------------
Author: ASF GitHub Bot
Created on: 29/Jun/22 17:45
Start Date: 29/Jun/22 17:45
Worklog Time Spent: 10m
Work Description: mattrpav commented on code in PR #729:
URL: https://github.com/apache/activemq/pull/729#discussion_r910242835
##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java:
##########
@@ -0,0 +1,353 @@
+/**
+ * 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.jms2;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Enumeration;
+
+import javax.jms.CompletionListener;
+import javax.jms.Destination;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.JMSRuntimeException;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.apache.activemq.ActiveMQContext;
+import org.junit.Test;
+
+public class ActiveMQJMS2ContextTest extends ActiveMQJMS2TestBase {
+
+ @Test
+ public void testConnectionFactoryCreateContext() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+ jmsContext.start();
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ recvMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testConnectionFactoryCreateContextSession() {
+ activemqConnectionFactory.createContext(Session.AUTO_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContextUserPass() {
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin")) {
+ assertNotNull(jmsContext);
+ jmsContext.start();
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ recvMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContextUserPassSession() {
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin",
Session.AUTO_ACKNOWLEDGE)) {
+ assertNotNull(jmsContext);
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ }
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContexMultiContext() {
+ JMSContext secondJMSContext = null;
+ JMSContext thirdJMSContext = null;
+
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin")) {
+ assertNotNull(jmsContext);
+ jmsContext.start();
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+
+ Destination testDestination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, testDestination, "Test-" +
methodNameDestinationName);
+ recvMessage(jmsContext, testDestination, "Test-" +
methodNameDestinationName);
+
+ secondJMSContext =
jmsContext.createContext(Session.AUTO_ACKNOWLEDGE);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+
+ // First context closed
+ String secondTestDestinationName = methodNameDestinationName +
".SECOND";
+ Destination secondTestDestination =
secondJMSContext.createQueue(secondTestDestinationName);
+
+ try {
+ sendMessage(secondJMSContext, secondTestDestination, "Test-" +
methodNameDestinationName);
+ recvMessage(secondJMSContext, secondTestDestination, "Test-" +
methodNameDestinationName);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ } finally {
+ if(secondJMSContext != null) {
+ try { secondJMSContext.close(); } catch (JMSRuntimeException
e) { fail(e.getMessage()); }
+ }
+ }
+
+ // Attempt to obtain a third context after all contexts have been
closed
+ boolean caught = false;
+ try {
+ thirdJMSContext =
secondJMSContext.createContext(Session.AUTO_ACKNOWLEDGE);
+ fail("JMSRuntimeException expected");
+ } catch (JMSRuntimeException e) {
+ caught = true;
+ assertEquals("Context already closed", e.getMessage());
+ }
+ assertTrue(caught);
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContextBrowse() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+ jmsContext.start();
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ browseMessage(jmsContext, destination, "Test-" +
methodNameDestinationName, true);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContextBrowseAutoStart() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ browseMessage(jmsContext, destination, "Test-" +
methodNameDestinationName, true);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testConnectionFactoryCreateContextBrowseAutoStartFalse() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+ jmsContext.setAutoStart(false);
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ browseMessage(jmsContext, destination, "Test-" +
methodNameDestinationName, false);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void
testConnectionFactoryCreateContextBrowseAutoStartFalseStartDelayed() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+ jmsContext.setAutoStart(false);
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ Destination destination =
jmsContext.createQueue(methodNameDestinationName);
+ sendMessage(jmsContext, destination, "Test-" +
methodNameDestinationName);
+ jmsContext.start();
+ browseMessage(jmsContext, destination, "Test-" +
methodNameDestinationName, true);
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testDisableMessageID() {
+ try(JMSContext jmsContext = activemqConnectionFactory.createContext())
{
+ assertNotNull(jmsContext);
+ jmsContext.setAutoStart(false);
+
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+ assertNotNull(jmsContext);
Review Comment:
Fixed
##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2MessageListenerTest.java:
##########
@@ -0,0 +1,159 @@
+/**
+ * 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.jms2;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.Message;
+
+import org.apache.activemq.ActiveMQSession;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(value = Parameterized.class)
+public class ActiveMQJMS2MessageListenerTest extends ActiveMQJMS2TestBase {
+
+ private final String destinationName;
+ private final String destinationType;
+ private final int ackMode;
+ private final String messagePayload;
+
+ public ActiveMQJMS2MessageListenerTest(String destinationType, int
ackMode) {
+ this.destinationName = "AMQ.JMS2.ACKMODE." + Integer.toString(ackMode)
+ destinationType.toUpperCase();
+ this.destinationType = destinationType;
+ this.ackMode = ackMode;
+ this.messagePayload = "Test message destType: " + destinationType + "
ackMode: " + Integer.toString(ackMode);
+ }
+
+ @Parameterized.Parameters(name="destinationType={0}, ackMode={1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ {"queue", ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE },
+ {"queue", ActiveMQSession.AUTO_ACKNOWLEDGE },
+ {"queue", ActiveMQSession.CLIENT_ACKNOWLEDGE },
+ {"queue", ActiveMQSession.DUPS_OK_ACKNOWLEDGE },
+ {"queue", ActiveMQSession.SESSION_TRANSACTED },
+ {"topic", ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE },
+ {"topic", ActiveMQSession.AUTO_ACKNOWLEDGE },
+ {"topic", ActiveMQSession.CLIENT_ACKNOWLEDGE },
+ {"topic", ActiveMQSession.DUPS_OK_ACKNOWLEDGE },
+ {"topic", ActiveMQSession.SESSION_TRANSACTED },
+ {"temp-queue", ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE },
+ {"temp-queue", ActiveMQSession.AUTO_ACKNOWLEDGE },
+ {"temp-queue", ActiveMQSession.CLIENT_ACKNOWLEDGE },
+ {"temp-queue", ActiveMQSession.DUPS_OK_ACKNOWLEDGE },
+ {"temp-queue", ActiveMQSession.SESSION_TRANSACTED },
+ {"temp-topic", ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE },
+ {"temp-topic", ActiveMQSession.AUTO_ACKNOWLEDGE },
+ {"temp-topic", ActiveMQSession.CLIENT_ACKNOWLEDGE },
+ {"temp-topic", ActiveMQSession.DUPS_OK_ACKNOWLEDGE },
+ {"temp-topic", ActiveMQSession.SESSION_TRANSACTED }
+ });
+ }
+
+ @Test
+ public void testMessageListener() {
+
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin", ackMode)) {
+ assertNotNull(jmsContext);
+ Destination destination =
ActiveMQJMS2TestSupport.generateDestination(jmsContext, destinationType,
destinationName);
+ assertNotNull(destination);
+ JMSConsumer jmsConsumer = jmsContext.createConsumer(destination);
+ ActiveMQJMS2TestMessageListener messageListener = new
ActiveMQJMS2TestMessageListener(ackMode);
+ jmsConsumer.setMessageListener(messageListener);
+ assertNotNull(jmsConsumer);
+ jmsContext.start();
+
+ Message message =
ActiveMQJMS2TestSupport.generateMessage(jmsContext, "text", messagePayload);
+
+ List<String> sentMessageIds = new LinkedList<>();
+ for(int deliveryMode : Arrays.asList(DeliveryMode.NON_PERSISTENT,
DeliveryMode.PERSISTENT)) {
+
sentMessageIds.add(ActiveMQJMS2TestSupport.sendMessage(jmsContext, destination,
message, null, deliveryMode, null, null, null, null, null, null, null));
+
+ switch(ackMode) {
+ case ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE:
message.acknowledge(); break;
+ default: break;
+ }
+ }
+
+ // For session and client ack we ack after all messages are sent
+ switch(ackMode) {
+ case ActiveMQSession.CLIENT_ACKNOWLEDGE: message.acknowledge();
break;
+ case ActiveMQSession.SESSION_TRANSACTED: jmsContext.commit();
break;
Review Comment:
Fixed
Issue Time Tracking
-------------------
Worklog Id: (was: 786154)
Time Spent: 15.5h (was: 15h 20m)
> Implement JMS 2.0 Connection createContext methods
> --------------------------------------------------
>
> Key: AMQ-8322
> URL: https://issues.apache.org/jira/browse/AMQ-8322
> Project: ActiveMQ
> Issue Type: New Feature
> Reporter: Matt Pavlovich
> Assignee: Matt Pavlovich
> Priority: Major
> Labels: #jms2
> Fix For: 5.18.0
>
> Time Spent: 15.5h
> Remaining Estimate: 0h
>
> Add support for JMSContext, JMSProducer and JMSConsumer for working with
> queues
--
This message was sent by Atlassian Jira
(v8.20.10#820010)