[
https://issues.apache.org/jira/browse/AMQ-8322?focusedWorklogId=766876&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-766876
]
ASF GitHub Bot logged work on AMQ-8322:
---------------------------------------
Author: ASF GitHub Bot
Created on: 05/May/22 19:26
Start Date: 05/May/22 19:26
Worklog Time Spent: 10m
Work Description: cshannon commented on code in PR #729:
URL: https://github.com/apache/activemq/pull/729#discussion_r866243454
##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2MessageTypesTest.java:
##########
@@ -0,0 +1,582 @@
+/**
+ * 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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(value = Parameterized.class)
+public class ActiveMQJMS2MessageTypesTest extends ActiveMQJMS2TestBase {
+
+ private final String clientID;
+ private final String destinationType;
+ private final String messagePayload;
+ private final String messageType;
+
+ public ActiveMQJMS2MessageTypesTest(String destinationType, String
messageType) {
+ this.clientID = destinationType + "-" + messageType;
+ this.destinationType = destinationType;
+ this.messagePayload = "Test message payload";
+ this.messageType = messageType;
+ }
+
+ @Parameterized.Parameters(name="destinationType={0}, messageType={1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ {"queue", "bytes"},
+ {"queue", "map"},
+ {"queue", "object"},
+ {"queue", "stream"},
+ {"queue", "text"},
+ {"topic", "bytes"},
+ {"topic", "map"},
+ {"topic", "object"},
+ {"topic", "stream"},
+ {"topic", "text"},
+ {"temp-queue", "bytes"},
+ {"temp-queue", "map"},
+ {"temp-queue", "object"},
+ {"temp-queue", "stream"},
+ {"temp-queue", "text"},
+ {"temp-topic", "bytes"},
+ {"temp-topic", "map"},
+ {"temp-topic", "object"},
+ {"temp-topic", "stream"},
+ {"temp-topic", "text"},
+ });
+ }
+
+ @Test
+ public void testMessageDeliveryMode() {
+
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin",
Session.AUTO_ACKNOWLEDGE)) {
+ assertNotNull(jmsContext);
+ Destination destination =
ActiveMQJMS2TestSupport.generateDestination(jmsContext, destinationType,
methodNameDestinationName);
+ assertNotNull(destination);
+ JMSConsumer jmsConsumer = jmsContext.createConsumer(destination);
+ assertNotNull(jmsConsumer);
+ jmsContext.start();
+
+ Message message =
ActiveMQJMS2TestSupport.generateMessage(jmsContext, messageType,
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));
+ }
+
+ Message recvMessage = null;
+ List<Message> recvMessages = new LinkedList<>();
+ int loopCount = 0;
+ int maxLoops = 50;
+ boolean done = false;
+ do {
+ recvMessage = jmsConsumer.receive(500l);
+ if(recvMessage != null) {
+ recvMessages.add(recvMessage);
+ }
+
+ if(recvMessages.size() == 2) {
+ done = true;
+ }
+ loopCount++;
+ } while (loopCount <= maxLoops && !done);
+
+ int foundCount = 0;
+ for(int validDeliveryMode :
Arrays.asList(DeliveryMode.NON_PERSISTENT, DeliveryMode.PERSISTENT)) {
+ for(javax.jms.Message tmpMessage : recvMessages) {
+ if(tmpMessage.getJMSDeliveryMode() == validDeliveryMode) {
+
ActiveMQJMS2TestSupport.validateMessageDeliveryMode(tmpMessage, messageType,
messagePayload, validDeliveryMode);
+ foundCount++;
+ }
+ }
+ }
+ assertEquals(Integer.valueOf(2), Integer.valueOf(foundCount));
+ jmsConsumer.close();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMessageDeliveryModeInvalid() {
+
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin",
Session.AUTO_ACKNOWLEDGE)) {
+ assertNotNull(jmsContext);
+ Destination destination =
ActiveMQJMS2TestSupport.generateDestination(jmsContext, destinationType,
methodNameDestinationName);
+ assertNotNull(destination);
+ jmsContext.start();
+
+ Message message =
ActiveMQJMS2TestSupport.generateMessage(jmsContext, messageType,
messagePayload);
+ boolean caught = false;
+ try {
+ ActiveMQJMS2TestSupport.sendMessage(jmsContext, destination,
message, null, 99, null, null, null, null, null, null, null);
+ fail("IlegalStateRuntimeException expected");
+ } catch (IllegalStateRuntimeException e) {
+ assertEquals("unknown delivery mode: 99", e.getMessage());
+ caught = true;
+ }
+ assertTrue(caught);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMessagePriority() {
+
+ try(JMSContext jmsContext =
activemqConnectionFactory.createContext("admin", "admin",
Session.AUTO_ACKNOWLEDGE)) {
+ assertNotNull(jmsContext);
+ Destination destination =
ActiveMQJMS2TestSupport.generateDestination(jmsContext, destinationType,
methodNameDestinationName);
+ assertNotNull(destination);
+ JMSConsumer jmsConsumer = jmsContext.createConsumer(destination);
+ assertNotNull(jmsConsumer);
+ jmsContext.start();
+
+ Message message =
ActiveMQJMS2TestSupport.generateMessage(jmsContext, messageType,
messagePayload);
+
+ List<String> sentMessageIds = new LinkedList<>();
+ for(int priority=0; priority<10; priority++) {
+
sentMessageIds.add(ActiveMQJMS2TestSupport.sendMessage(jmsContext, destination,
message, null, null, null, null, null, null, null, priority, null));
+ }
+
+ Message recvMessage = null;
+ List<Message> recvMessages = new LinkedList<>();
+ int loopCount = 0;
+ int maxLoops = 50;
+ boolean done = false;
+ do {
+ recvMessage = jmsConsumer.receive(500l);
+ if(recvMessage != null) {
+ recvMessages.add(recvMessage);
+ }
+
+ if(recvMessages.size() == 10) {
+ done = true;
+ }
+ loopCount++;
+ } while (loopCount <= maxLoops && !done);
Review Comment:
I will add at the very least you can at least turn it into a helper method
and re-use the code that way it can be easily refined or tuned later vs where
it's copy and pasted all over the place now (that was my main complaint from
5.17.x where the same do/while was copy pasted over and over so if you wanted
to change the design it would be awful to fix)
Issue Time Tracking
-------------------
Worklog Id: (was: 766876)
Time Spent: 13h 50m (was: 13h 40m)
> 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: 13h 50m
> Remaining Estimate: 0h
>
> Add support for JMSContext, JMSProducer and JMSConsumer for working with
> queues
--
This message was sent by Atlassian Jira
(v8.20.7#820007)