gemmellr commented on code in PR #1303:
URL: https://github.com/apache/activemq/pull/1303#discussion_r1760972384


##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java:
##########
@@ -296,24 +296,57 @@ public void testProducerDeliveryDelaySet() throws 
JMSException {
         messageProducer.setDeliveryDelay(1000l);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendMessageCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, (CompletionListener)null);
+        messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendMessageQoSParamsCompletionListener() throws 
JMSException {
-         messageProducer.send(null, 1, 4, 0l, null);
+         messageProducer.send(session.createTextMessage("test message"), 1, 4, 
0l, null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendDestinationMessageCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, null);
+         messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void 
testProducerSendDestinationMessageQosParamsCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, 1, 4, 0l, null);
+         messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), 1, 4, 0l, null);
+    }
+
+    @Test
+    public void testProducerSendMessageWithNonNullCompletionListener() throws 
JMSException {
+        final String testTextMessageBody = "this is a test message";
+        final CompletionListener completionListener = new CompletionListener() 
{
+            @Override
+            public void onCompletion(Message message) {
+                TextMessage textMessage = (TextMessage) message;
+                try {
+                    assertEquals(textMessage.getText(), testTextMessageBody);

Review Comment:
   This also simply doesnt work as a verification. The test thread is usually 
the only one an assert check failing will directly cause a test failure, and 
this isnt done in the test thread (or at least shouldnt be, since 
CompletionListeners are not allowed to be fired by the thread calling send 
\[1\]). The client is likely just going to swallow this assertion failure if it 
happens, and the test pass regardless of any problem here. You would need to 
retain the result of the callback and coordinate the checking across the 
threads.
   
   [\1\] "A Jakarta Messaging provider must not invoke the CompletionListener 
from the thread that is calling the asynchronous send method." 



##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java:
##########
@@ -296,24 +296,57 @@ public void testProducerDeliveryDelaySet() throws 
JMSException {
         messageProducer.setDeliveryDelay(1000l);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendMessageCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, (CompletionListener)null);
+        messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendMessageQoSParamsCompletionListener() throws 
JMSException {
-         messageProducer.send(null, 1, 4, 0l, null);
+         messageProducer.send(session.createTextMessage("test message"), 1, 4, 
0l, null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendDestinationMessageCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, null);
+         messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), null);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void 
testProducerSendDestinationMessageQosParamsCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, 1, 4, 0l, null);
+         messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), 1, 4, 0l, null);
+    }
+
+    @Test
+    public void testProducerSendMessageWithNonNullCompletionListener() throws 
JMSException {
+        final String testTextMessageBody = "this is a test message";
+        final CompletionListener completionListener = new CompletionListener() 
{
+            @Override
+            public void onCompletion(Message message) {
+                TextMessage textMessage = (TextMessage) message;
+                try {
+                    assertEquals(textMessage.getText(), testTextMessageBody);
+                } catch (JMSException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+
+            @Override
+            public void onException(Message message, Exception e) {
+                throw new RuntimeException(e);
+            }
+        };
+        messageProducer.send(
+                session.createQueue(methodNameDestinationName),
+                session.createTextMessage(testTextMessageBody),
+                completionListener);

Review Comment:
   Its also more than a little odd to use ActiveMQJMS2ContextTest to test this, 
since you cant created a MessageProducer with a JMSContext, but rather only 
JMSProducer instances.
   
   This is largely an existing issue though since all the other existing tests 
you updated, those checking for throwing UnsupportedOperationException, do the 
same. Seems like maybe those are c&p errors from long ago.



##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java:
##########
@@ -296,24 +296,57 @@ public void testProducerDeliveryDelaySet() throws 
JMSException {
         messageProducer.setDeliveryDelay(1000l);
     }
 
-    @Test(expected = UnsupportedOperationException.class)
+    @Test
     public void testProducerSendMessageCompletionListener() throws 
JMSException {
-         messageProducer.send(session.createQueue(methodNameDestinationName), 
null, (CompletionListener)null);
+        messageProducer.send(session.createQueue(methodNameDestinationName), 
session.createTextMessage("test message"), null);

Review Comment:
   ..and related to a followup comment I just made on the later test, it doesnt 
really seem to make sense for ActiveMQJMS2ContextTest to test this method at 
all given you dont created a MessageProducer using a JMSContext (but rather a 
Session), but rather a JMSProducer



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org
For additional commands, e-mail: gitbox-h...@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact


Reply via email to