From bc34dcae91fc3554b0c9733a7cacc8e44b07116c Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:12:11 +0000 Subject: [PATCH 01/11] Add description for persistent delayed message tests --- .../src/deliverydelay/web/DeliveryDelayServlet.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index 0796d12b554..bdae0893e8e 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1260,6 +1260,12 @@ public void testGetDeliveryDelayTopic_Tcp( } } + + // Tests for delayed message persistence over server restart. + // These tests are each in two parts; a sender part that sends 2 messages, and a receiver part that attempts to receive the messages. + // The methods are driven from the Test class, which calls the sender method, restarts the server, and then calls the receiver method. + + // new tests for simplified API public void testPersistentMessage( @@ -1464,6 +1470,11 @@ public void testPersistentMessageReceiveTopic_Tcp( } } + + + + + public void testTimeToLiveWithDeliveryDelay( HttpServletRequest request, HttpServletResponse response) throws Exception { From 47abcbc9e43dfda3ce2fa9958f226402cebcd1a3 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:14:44 +0000 Subject: [PATCH 02/11] Remove unused variables from Simplified API tests --- .../src/deliverydelay/web/DeliveryDelayServlet.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index bdae0893e8e..6086631cf74 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1271,8 +1271,6 @@ public void testGetDeliveryDelayTopic_Tcp( public void testPersistentMessage( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - JMSContext jmsContext = jmsQCFBindings.createContext(); JMSConsumer jmsConsumer = jmsContext.createConsumer(jmsQueue); JMSProducer jmsProducer = jmsContext.createProducer(); @@ -1323,8 +1321,6 @@ public void testPersistentMessageReceive( public void testPersistentMessage_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - JMSContext jmsContext = jmsQCFTCP.createContext(); JMSConsumer jmsConsumer = jmsContext.createConsumer(jmsQueue); JMSProducer jmsProducer = jmsContext.createProducer(); @@ -1373,8 +1369,6 @@ public void testPersistentMessageReceive_Tcp( public void testPersistentMessageTopic( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - JMSContext jmsContext = jmsTCFBindings.createContext(); JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsg1"); JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsg2"); @@ -1423,8 +1417,6 @@ public void testPersistentMessageReceiveTopic( public void testPersistentMessageTopic_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - JMSContext jmsContext = jmsTCFTCP.createContext(); JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsgTcp1"); JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsgTcp2"); From 0740574f529d17a386728f6e024fc77d06383cca Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:33:56 +0000 Subject: [PATCH 03/11] Bring classic and simplified API tests together --- .../web/DeliveryDelayServlet.java | 514 +++++++++--------- 1 file changed, 257 insertions(+), 257 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index 6086631cf74..cbd0f6fe6fd 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1462,9 +1462,264 @@ public void testPersistentMessageReceiveTopic_Tcp( } } + + // Old tests for classic API - - + public void testPersistentMessageClassicApi( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + QueueConnection con = jmsQCFBindings.createQueueConnection(); + con.start(); + + QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + + QueueSender producer1 = sessionSender.createSender(jmsQueue); + emptyQueue(jmsQCFBindings, jmsQueue); + + QueueSender producer2 = sessionSender.createSender(jmsQueue1); + emptyQueue(jmsQCFBindings, jmsQueue1); + + producer1.setDeliveryMode(DeliveryMode.PERSISTENT); + producer1.setDeliveryDelay(1000); + TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); + producer1.send(msg1); + + producer2.setDeliveryDelay(1000); + producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); + producer2.send(msg2); + + sessionSender.close(); + con.close(); + } + + public void testPersistentMessageReceiveClassicApi( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean testFailed = false; + + QueueConnection con = jmsQCFBindings.createQueueConnection(); + con.start(); + + QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + + QueueReceiver jmsConsumer1 = sessionSender.createReceiver(jmsQueue); + QueueReceiver jmsConsumer2 = sessionSender.createReceiver(jmsQueue); + + QueueSender producer = sessionSender.createSender(jmsQueue1); + + TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); + TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); + + if ( ((msg1 == null) || + (msg1.getText() == null) || + !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || + (msg2 != null) ) { + testFailed = true; + } + + sessionSender.close(); + con.close(); + + if ( testFailed ) { + throw new Exception("testPersistentMessageReceiveClassicApi failed"); + } + } + + public void testPersistentMessageClassicApi_Tcp( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + QueueConnection con = jmsQCFTCP.createQueueConnection(); + con.start(); + + QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + + QueueSender producer1 = sessionSender.createSender(jmsQueue); + emptyQueue(jmsQCFBindings, jmsQueue); + + QueueSender producer2 = sessionSender.createSender(jmsQueue1); + emptyQueue(jmsQCFBindings, jmsQueue1); + + producer1.setDeliveryMode(DeliveryMode.PERSISTENT); + producer1.setDeliveryDelay(1000); + TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); + producer1.send(msg1); + + producer2.setDeliveryDelay(1000); + producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); + producer2.send(msg2); + + sessionSender.close(); + con.close(); + } + + public void testPersistentMessageReceiveClassicApi_Tcp( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean testFailed = false; + + QueueConnection con = jmsQCFTCP.createQueueConnection(); + con.start(); + + QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + + MessageConsumer jmsConsumer1 = sessionSender.createConsumer(jmsQueue); + MessageConsumer jmsConsumer2 = sessionSender.createConsumer(jmsQueue); + + QueueSender producer = sessionSender.createSender(jmsQueue1); + + TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); + TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); + + if ( ((msg1 == null) || + (msg1.getText() == null) || + !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || + (msg2 != null) ) { + testFailed = true; + } + + sessionSender.close(); + con.close(); + + if ( testFailed ) { + throw new Exception("testPersistentMessageReceiveClassicApi failed"); + } + } + + public void testPersistentMessageTopicClassicApi( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + TopicConnection con = jmsTCFBindings.createTopicConnection(); + con.start(); + + TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + + TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); + TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); + + TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); + TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); + + jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); + jmsProducer1.setDeliveryDelay(1000); + TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApi"); + jmsProducer1.send(msg1); + + jmsProducer2.setDeliveryDelay(1000); + jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApi"); + jmsProducer2.send(msg2); + + con.close(); + } + + public void testPersistentMessageReceiveTopicClassicApi( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean testFailed = false; + + TopicConnection con = jmsTCFBindings.createTopicConnection(); + con.start(); + + TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + + TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); + TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); + + TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); + + TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); + TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); + + if ( ((msg1 == null) || + (msg1.getText() == null) || + !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApi")) || + (msg2 != null) ) { + testFailed = true; + } + + jmsConsumer1.close(); + jmsConsumer2.close(); + + sessionSender.unsubscribe("durPersMsgCA1"); + sessionSender.unsubscribe("durPersMsgCA2"); + sessionSender.close(); + + con.close(); + + if ( testFailed ) { + throw new Exception("testPersistentMessageReceiveTopicClassicApi failed"); + } + } + + public void testPersistentMessageTopicClassicApi_Tcp( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean testFailed = false; + + TopicConnection con = jmsTCFTCP.createTopicConnection(); + con.start(); + + TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + + TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); + TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); + + TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); + TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); + + jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); + jmsProducer1.setDeliveryDelay(1000); + TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApiTcp"); + jmsProducer1.send(msg1); + + jmsProducer2.setDeliveryDelay(1000); + jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApiTcp"); + jmsProducer2.send(msg2); + + con.close(); + } + + public void testPersistentMessageReceiveTopicClassicApi_Tcp( + HttpServletRequest request, HttpServletResponse response) throws Exception { + + boolean testFailed = false; + + TopicConnection con = jmsTCFTCP.createTopicConnection(); + con.start(); + + TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + + TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); + TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); + + TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); + + TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); + TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); + + if ( ((msg1 == null) || + (msg1.getText() == null) || + !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApiTcp")) || + (msg2 != null) ) { + testFailed = true; + } + + jmsConsumer1.close(); + jmsConsumer2.close(); + + sessionSender.unsubscribe("durPersMsgCATcp1"); + sessionSender.unsubscribe("durPersMsgCATcp2"); + sessionSender.close(); + + con.close(); + + if ( testFailed ) { + throw new Exception("testPersistentMessageStoreReceiveTopicClassicApi_Tcp failed"); + } + } public void testTimeToLiveWithDeliveryDelay( @@ -3700,261 +3955,6 @@ public void testGetDeliveryDelayClassicApiTopic_Tcp( } } - public void testPersistentMessageClassicApi( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - QueueConnection con = jmsQCFBindings.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueSender producer1 = sessionSender.createSender(jmsQueue); - emptyQueue(jmsQCFBindings, jmsQueue); - - QueueSender producer2 = sessionSender.createSender(jmsQueue1); - emptyQueue(jmsQCFBindings, jmsQueue1); - - producer1.setDeliveryMode(DeliveryMode.PERSISTENT); - producer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); - producer1.send(msg1); - - producer2.setDeliveryDelay(1000); - producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); - producer2.send(msg2); - - sessionSender.close(); - con.close(); - } - - public void testPersistentMessageReceiveClassicApi( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - boolean testFailed = false; - - QueueConnection con = jmsQCFBindings.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueReceiver jmsConsumer1 = sessionSender.createReceiver(jmsQueue); - QueueReceiver jmsConsumer2 = sessionSender.createReceiver(jmsQueue); - - QueueSender producer = sessionSender.createSender(jmsQueue1); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - sessionSender.close(); - con.close(); - - if ( testFailed ) { - throw new Exception("testPersistentMessageReceiveClassicApi failed"); - } - } - - public void testPersistentMessageClassicApi_Tcp( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - QueueConnection con = jmsQCFTCP.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueSender producer1 = sessionSender.createSender(jmsQueue); - emptyQueue(jmsQCFBindings, jmsQueue); - - QueueSender producer2 = sessionSender.createSender(jmsQueue1); - emptyQueue(jmsQCFBindings, jmsQueue1); - - producer1.setDeliveryMode(DeliveryMode.PERSISTENT); - producer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); - producer1.send(msg1); - - producer2.setDeliveryDelay(1000); - producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); - producer2.send(msg2); - - sessionSender.close(); - con.close(); - } - - public void testPersistentMessageReceiveClassicApi_Tcp( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - boolean testFailed = false; - - QueueConnection con = jmsQCFTCP.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer jmsConsumer1 = sessionSender.createConsumer(jmsQueue); - MessageConsumer jmsConsumer2 = sessionSender.createConsumer(jmsQueue); - - QueueSender producer = sessionSender.createSender(jmsQueue1); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - sessionSender.close(); - con.close(); - - if ( testFailed ) { - throw new Exception("testPersistentMessageReceiveClassicApi failed"); - } - } - - public void testPersistentMessageTopicClassicApi( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - TopicConnection con = jmsTCFBindings.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); - - TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); - TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); - - jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); - jmsProducer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApi"); - jmsProducer1.send(msg1); - - jmsProducer2.setDeliveryDelay(1000); - jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApi"); - jmsProducer2.send(msg2); - - con.close(); - } - - public void testPersistentMessageReceiveTopicClassicApi( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - boolean testFailed = false; - - TopicConnection con = jmsTCFBindings.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); - - TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - - sessionSender.unsubscribe("durPersMsgCA1"); - sessionSender.unsubscribe("durPersMsgCA2"); - sessionSender.close(); - - con.close(); - - if ( testFailed ) { - throw new Exception("testPersistentMessageReceiveTopicClassicApi failed"); - } - } - - public void testPersistentMessageTopicClassicApi_Tcp( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - boolean testFailed = false; - - TopicConnection con = jmsTCFTCP.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); - - TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); - TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); - - jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); - jmsProducer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApiTcp"); - jmsProducer1.send(msg1); - - jmsProducer2.setDeliveryDelay(1000); - jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApiTcp"); - jmsProducer2.send(msg2); - - con.close(); - } - - public void testPersistentMessageReceiveTopicClassicApi_Tcp( - HttpServletRequest request, HttpServletResponse response) throws Exception { - - boolean testFailed = false; - - TopicConnection con = jmsTCFTCP.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); - - TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApiTcp")) || - (msg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - - sessionSender.unsubscribe("durPersMsgCATcp1"); - sessionSender.unsubscribe("durPersMsgCATcp2"); - sessionSender.close(); - - con.close(); - - if ( testFailed ) { - throw new Exception("testPersistentMessageStoreReceiveTopicClassicApi_Tcp failed"); - } - } public void testJSAD_Send_Message_P2PTest( HttpServletRequest request, HttpServletResponse response) throws Exception { From 31602124d37375224830685e511af8a6beaf87a9 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:54:25 +0000 Subject: [PATCH 04/11] Add new simplied API persistent message send method --- .../web/DeliveryDelayServlet.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index cbd0f6fe6fd..abb8775aa9b 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1267,6 +1267,51 @@ public void testGetDeliveryDelayTopic_Tcp( // new tests for simplified API + + // New consolidated simplified API persistent test sender method + private void testPersistentMessageSimplifiedAPI_send(ConnectionFactory cf, + Destination persistentMessageDestination, + Destination nonpersistentMessageDestination, + String identifier) + throws Exception { + + boolean pubSub = persistentMessageDestination instanceof Topic; + JMSConsumer jmsConsumer1 = null, jmsConsumer2 = null; + + try (JMSContext jmsContext = cf.createContext()) { + + JMSProducer jmsProducer = jmsContext.createProducer(); + + // If we are sending messages to Topic destinations then there needs to be subscriptions to receive the messages + if (pubSub) { + jmsConsumer1 = jmsContext.createDurableConsumer((Topic) persistentMessageDestination, "durPersMsg1_" + identifier); + jmsConsumer2 = jmsContext.createDurableConsumer((Topic) nonpersistentMessageDestination, "durPersMsg2_" + identifier); + } + else { + // empty the message queue before sending the new messages. + // This is replicating previous behaviour, but will probably need to be removed if we re-work the tests to run concurrently. + emptyQueue(cf, (Queue)persistentMessageDestination); + emptyQueue(cf, (Queue)nonpersistentMessageDestination); + } + + // Send the messages + jmsProducer.setDeliveryDelay(defaultTestDeliveryDelay).setDeliveryMode(DeliveryMode.PERSISTENT) + .send(persistentMessageDestination, "PersistentMessage_" + identifier); + + jmsProducer.setDeliveryDelay(defaultTestDeliveryDelay).setDeliveryMode(DeliveryMode.NON_PERSISTENT) + .send(nonpersistentMessageDestination, "NonPersistentMessage_" + identifier); + + // If we're running in the pub/sub domain then close the subscribers (the subscriptions will remain open + if (pubSub) { + jmsConsumer1.close(); + jmsConsumer2.close(); + } + + } + + return; + } + public void testPersistentMessage( HttpServletRequest request, HttpServletResponse response) throws Exception { From 847d78de4a19ec9921d8aa30d4cce311da8cf091 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:18:06 +0000 Subject: [PATCH 05/11] Simplified API persistent tests use consolidated sender --- .../web/DeliveryDelayServlet.java | 118 ++++++++---------- 1 file changed, 49 insertions(+), 69 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index abb8775aa9b..5a358d72322 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1312,26 +1312,17 @@ private void testPersistentMessageSimplifiedAPI_send(ConnectionFactory cf, return; } + private String testPersistentQueueMessageIdentifier = "testPersistentQueueMessage"; public void testPersistentMessage( HttpServletRequest request, HttpServletResponse response) throws Exception { - - JMSContext jmsContext = jmsQCFBindings.createContext(); - JMSConsumer jmsConsumer = jmsContext.createConsumer(jmsQueue); - JMSProducer jmsProducer = jmsContext.createProducer(); - - emptyQueue(jmsQCFBindings, jmsQueue); - emptyQueue(jmsQCFBindings, jmsQueue1); - - jmsProducer.setDeliveryMode(DeliveryMode.PERSISTENT).setDeliveryDelay(1000); - - jmsProducer.send(jmsQueue, "testPersistentMessage_PersistentMsg"); - - jmsProducer.setDeliveryDelay(1000).setDeliveryMode(DeliveryMode.NON_PERSISTENT); - jmsProducer.send(jmsQueue1, "testPersistentMessage_NonPersistentMsg"); - - jmsConsumer.close(); - jmsContext.close(); + // Originally used message text "testPersistentMessage_PersistentMsg" "testPersistentMessage_NonPersistentMsg" + // jmsQCFBindings, jmsQueue, jmsQueue1 + + testPersistentMessageSimplifiedAPI_send(jmsQCFBindings, jmsQueue, jmsQueue1, testPersistentQueueMessageIdentifier); + + return; + } public void testPersistentMessageReceive( @@ -1349,7 +1340,7 @@ public void testPersistentMessageReceive( if ( ((recMsg1 == null) || (recMsg1.getText() == null) || - !recMsg1.getText().equals("testPersistentMessage_PersistentMsg")) || + !recMsg1.getText().equals("PersistentMessage_" + testPersistentQueueMessageIdentifier)) || (recMsg2 != null) ) { testFailed = true; } @@ -1363,23 +1354,16 @@ public void testPersistentMessageReceive( } } + private String testPersistentQueueMessageTcpIdentifier = "testPersistentQueueMessageTcp"; + public void testPersistentMessage_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { + // Originally used message text "testPersistentMessage_PersistentMsgTcp" "testPersistentMessage_NonPersistentMsgTcp" + // jmsQCFTCP, jmsQueue, jmsQueue1 + + testPersistentMessageSimplifiedAPI_send(jmsQCFTCP, jmsQueue, jmsQueue1, testPersistentQueueMessageTcpIdentifier); - JMSContext jmsContext = jmsQCFTCP.createContext(); - JMSConsumer jmsConsumer = jmsContext.createConsumer(jmsQueue); - JMSProducer jmsProducer = jmsContext.createProducer(); - emptyQueue(jmsQCFTCP, jmsQueue); - emptyQueue(jmsQCFTCP, jmsQueue1); - - jmsProducer.setDeliveryMode(DeliveryMode.PERSISTENT).setDeliveryDelay(1000); - jmsProducer.send(jmsQueue, "testPersistentMessage_PersistentMsgTcp"); - - jmsProducer.setDeliveryDelay(1000).setDeliveryMode(DeliveryMode.NON_PERSISTENT); - jmsProducer.send(jmsQueue1, "testPersistentMessage_NonPersistentMsgTcp"); - - jmsConsumer.close(); - jmsContext.close(); + return; } public void testPersistentMessageReceive_Tcp( @@ -1397,7 +1381,7 @@ public void testPersistentMessageReceive_Tcp( if ( ((recMsg1 == null) || (recMsg1.getText() == null) || - !recMsg1.getText().equals("testPersistentMessage_PersistentMsgTcp")) || + !recMsg1.getText().equals("PersistentMessage_" + testPersistentQueueMessageTcpIdentifier)) || (recMsg2 != null) ) { testFailed = true; } @@ -1411,31 +1395,29 @@ public void testPersistentMessageReceive_Tcp( } } + private String testPersistentTopicMessageIdentifier = "testPersistentTopicMessage"; + public void testPersistentMessageTopic( HttpServletRequest request, HttpServletResponse response) throws Exception { + // Originally used message text "testPersistentMessage_PersistentMsgTopic" "testPersistentMessage_NonPersistentMsgTopic" + // jmsTCFBindings, jmsTopic, jmsTopic1 - JMSContext jmsContext = jmsTCFBindings.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsg1"); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsg2"); - JMSProducer jmsProducer = jmsContext.createProducer(); - - jmsProducer.setDeliveryMode(DeliveryMode.PERSISTENT) .setDeliveryDelay(1000); - jmsProducer.send(jmsTopic, "testPersistentMessage_PersistentMsgTopic"); - - jmsProducer.setDeliveryDelay(1000).setDeliveryMode(DeliveryMode.NON_PERSISTENT); - jmsProducer.send(jmsTopic1, "testPersistentMessage_NonPersistentMsgTopic"); - - // First half of test .. verification in the second half. + testPersistentMessageSimplifiedAPI_send(jmsTCFBindings, jmsTopic, jmsTopic1, testPersistentTopicMessageIdentifier); + + return; } public void testPersistentMessageReceiveTopic( HttpServletRequest request, HttpServletResponse response) throws Exception { boolean testFailed = false; + + String subscriber1Name = "durPersMsg1_" + testPersistentTopicMessageIdentifier; + String subscriber2Name = "durPersMsg2_" + testPersistentTopicMessageIdentifier; JMSContext jmsContext = jmsTCFBindings.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsg1"); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsg2"); + JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, subscriber1Name); + JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, subscriber2Name); JMSProducer jmsProducer = jmsContext.createProducer(); TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); @@ -1443,15 +1425,15 @@ public void testPersistentMessageReceiveTopic( if ( ((recMsg1 == null) || (recMsg1.getText() == null) || - !recMsg1.getText().equals("testPersistentMessage_PersistentMsgTopic")) || - (recMsg2 != null)) { + !recMsg1.getText().equals("PersistentMessage_" + testPersistentTopicMessageIdentifier)) || + (recMsg2 != null) ) { testFailed = true; } jmsConsumer1.close(); jmsConsumer2.close(); - jmsContext.unsubscribe("durPersMsg1"); - jmsContext.unsubscribe("durPersMsg2"); + jmsContext.unsubscribe(subscriber1Name); + jmsContext.unsubscribe(subscriber2Name); jmsContext.close(); if ( testFailed ) { @@ -1459,31 +1441,29 @@ public void testPersistentMessageReceiveTopic( } } + private String testPersistentTopicMessageTcpIdentifier = "testPersistentTopicMessageTcp"; + public void testPersistentMessageTopic_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - - JMSContext jmsContext = jmsTCFTCP.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsgTcp1"); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsgTcp2"); - JMSProducer jmsProducer = jmsContext.createProducer(); - - jmsProducer.setDeliveryMode(DeliveryMode.PERSISTENT).setDeliveryDelay(1000); - jmsProducer.send(jmsTopic, "testPersistentMessage_PersistentMsgTopicTcp"); - - jmsProducer.setDeliveryDelay(1000).setDeliveryMode(DeliveryMode.NON_PERSISTENT); - jmsProducer.send(jmsTopic1, "testPersistentMessage_NonPersistentMsgTopicTcp"); - - // First half of test .. verification in the second half. + // Originally used message text "testPersistentMessage_PersistentMsgTopicTcp" "testPersistentMessage_NonPersistentMsgTopicTcp" + // jmsTCFTCP, jmsTopic, jmsTopic1 + + testPersistentMessageSimplifiedAPI_send(jmsTCFTCP, jmsTopic, jmsTopic1, testPersistentTopicMessageTcpIdentifier); + + return; } public void testPersistentMessageReceiveTopic_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { boolean testFailed = false; + + String subscriber1Name = "durPersMsg1_" + testPersistentTopicMessageTcpIdentifier; + String subscriber2Name = "durPersMsg2_" + testPersistentTopicMessageTcpIdentifier; JMSContext jmsContext = jmsTCFTCP.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, "durPersMsgTcp1"); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, "durPersMsgTcp2"); + JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, subscriber1Name); + JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, subscriber2Name); JMSProducer jmsProducer = jmsContext.createProducer(); TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); @@ -1491,15 +1471,15 @@ public void testPersistentMessageReceiveTopic_Tcp( if ( ((recMsg1 == null) || (recMsg1.getText() == null) || - !recMsg1.getText().equals("testPersistentMessage_PersistentMsgTopicTcp")) || + !recMsg1.getText().equals("PersistentMessage_" + testPersistentTopicMessageTcpIdentifier)) || (recMsg2 != null) ) { testFailed = true; } jmsConsumer1.close(); jmsConsumer2.close(); - jmsContext.unsubscribe("durPersMsgTcp1"); - jmsContext.unsubscribe("durPersMsgTcp2"); + jmsContext.unsubscribe(subscriber1Name); + jmsContext.unsubscribe(subscriber2Name); jmsContext.close(); if ( testFailed ) { From 10fe74e3b8971c74c78a492510f66d091606b774 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:26:42 +0000 Subject: [PATCH 06/11] Add new simplified API persistent message receive method --- .../web/DeliveryDelayServlet.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index 5a358d72322..7b322c9b135 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1312,6 +1312,62 @@ private void testPersistentMessageSimplifiedAPI_send(ConnectionFactory cf, return; } + // New consolidated simplified API persistent test receiver method + private boolean testPersistentMessageSimplifiedAPI_receive(ConnectionFactory cf, + Destination persistentMessageDestination, + Destination nonpersistentMessageDestination, + String identifier) + throws Exception { + + boolean pubSub = persistentMessageDestination instanceof Topic; + boolean testPassed = true; + + String subscriber1Name = "durPersMsg1_" + identifier; + String subscriber2Name = "durPersMsg2_" + identifier; + + JMSConsumer jmsConsumer1 = null, jmsConsumer2 = null; + + try (JMSContext jmsContext = cf.createContext()) { + + if (pubSub) { + jmsConsumer1 = jmsContext.createDurableConsumer((Topic) persistentMessageDestination, subscriber1Name); + jmsConsumer2 = jmsContext.createDurableConsumer((Topic) nonpersistentMessageDestination, subscriber2Name); + } + else { + jmsConsumer1 = jmsContext.createConsumer(persistentMessageDestination); + jmsConsumer2 = jmsContext.createConsumer(nonpersistentMessageDestination); + } + + // Try to receive a message from each destination. Wait for twice the default deliveryDelay time if required + // Only the persistentMessageDestination should receive something + + TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(defaultTestDeliveryDelay * 2); + TextMessage recMsg2 = (TextMessage) jmsConsumer2.receive(defaultTestDeliveryDelay * 2); + + // and check whether we got the expected results + if ( ((recMsg1 == null) || // If we failed to get a persistent message + (recMsg1.getText() == null) || // or the message had no payload... + !recMsg1.getText().equals("PersistentMessage_" + identifier)) || // ...or the payload wasn't what we expected (implying it's a message from some other test or something) + (recMsg2 != null) ) { // or we received a message from the nonpersistentMessageDestination (as the message there should not have persisted over the server restart) + testPassed = false; // ...then we need to mark the test as failed. + } + + // tidy up + jmsConsumer1.close(); + jmsConsumer2.close(); + + if (pubSub) { + jmsContext.unsubscribe(subscriber1Name); + jmsContext.unsubscribe(subscriber2Name); + } + + } + + return testPassed; + } + + + private String testPersistentQueueMessageIdentifier = "testPersistentQueueMessage"; public void testPersistentMessage( From 3348e6dd85f376436a9674bd78f3a609452bc15c Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Tue, 19 Nov 2024 13:39:37 +0000 Subject: [PATCH 07/11] Simplified API persistent tests use consolidated receiver --- .../web/DeliveryDelayServlet.java | 110 +++--------------- 1 file changed, 16 insertions(+), 94 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index 7b322c9b135..f5620889801 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1384,30 +1384,13 @@ public void testPersistentMessage( public void testPersistentMessageReceive( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - JMSContext jmsContext = jmsQCFBindings.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createConsumer(jmsQueue); - JMSConsumer jmsConsumer2 = jmsContext.createConsumer(jmsQueue1); - JMSProducer jmsProducer = jmsContext.createProducer(); - - TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage recMsg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((recMsg1 == null) || - (recMsg1.getText() == null) || - !recMsg1.getText().equals("PersistentMessage_" + testPersistentQueueMessageIdentifier)) || - (recMsg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - jmsContext.close(); + boolean testPassed = testPersistentMessageSimplifiedAPI_receive(jmsQCFBindings, jmsQueue, jmsQueue1, testPersistentQueueMessageIdentifier); - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceive failed"); } + + return; } private String testPersistentQueueMessageTcpIdentifier = "testPersistentQueueMessageTcp"; @@ -1425,30 +1408,13 @@ public void testPersistentMessage_Tcp( public void testPersistentMessageReceive_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; + boolean testPassed = testPersistentMessageSimplifiedAPI_receive(jmsQCFTCP, jmsQueue, jmsQueue1, testPersistentQueueMessageTcpIdentifier); - JMSContext jmsContext = jmsQCFTCP.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createConsumer(jmsQueue); - JMSConsumer jmsConsumer2 = jmsContext.createConsumer(jmsQueue1); - JMSProducer jmsProducer = jmsContext.createProducer(); - - TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage recMsg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((recMsg1 == null) || - (recMsg1.getText() == null) || - !recMsg1.getText().equals("PersistentMessage_" + testPersistentQueueMessageTcpIdentifier)) || - (recMsg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - jmsContext.close(); - - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceive_Tcp failed"); } + + return; } private String testPersistentTopicMessageIdentifier = "testPersistentTopicMessage"; @@ -1466,35 +1432,13 @@ public void testPersistentMessageTopic( public void testPersistentMessageReceiveTopic( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - String subscriber1Name = "durPersMsg1_" + testPersistentTopicMessageIdentifier; - String subscriber2Name = "durPersMsg2_" + testPersistentTopicMessageIdentifier; + boolean testPassed = testPersistentMessageSimplifiedAPI_receive(jmsTCFBindings, jmsTopic, jmsTopic1, testPersistentTopicMessageIdentifier); - JMSContext jmsContext = jmsTCFBindings.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, subscriber1Name); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, subscriber2Name); - JMSProducer jmsProducer = jmsContext.createProducer(); - - TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage recMsg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((recMsg1 == null) || - (recMsg1.getText() == null) || - !recMsg1.getText().equals("PersistentMessage_" + testPersistentTopicMessageIdentifier)) || - (recMsg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - jmsContext.unsubscribe(subscriber1Name); - jmsContext.unsubscribe(subscriber2Name); - jmsContext.close(); - - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceiveTopic failed"); } + + return; } private String testPersistentTopicMessageTcpIdentifier = "testPersistentTopicMessageTcp"; @@ -1512,35 +1456,13 @@ public void testPersistentMessageTopic_Tcp( public void testPersistentMessageReceiveTopic_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - String subscriber1Name = "durPersMsg1_" + testPersistentTopicMessageTcpIdentifier; - String subscriber2Name = "durPersMsg2_" + testPersistentTopicMessageTcpIdentifier; - - JMSContext jmsContext = jmsTCFTCP.createContext(); - JMSConsumer jmsConsumer1 = jmsContext.createDurableConsumer(jmsTopic, subscriber1Name); - JMSConsumer jmsConsumer2 = jmsContext.createDurableConsumer(jmsTopic1, subscriber2Name); - JMSProducer jmsProducer = jmsContext.createProducer(); - - TextMessage recMsg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage recMsg2 = (TextMessage) jmsConsumer2.receive(30000); + boolean testPassed = testPersistentMessageSimplifiedAPI_receive(jmsTCFTCP, jmsTopic, jmsTopic1, testPersistentTopicMessageTcpIdentifier); - if ( ((recMsg1 == null) || - (recMsg1.getText() == null) || - !recMsg1.getText().equals("PersistentMessage_" + testPersistentTopicMessageTcpIdentifier)) || - (recMsg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - jmsContext.unsubscribe(subscriber1Name); - jmsContext.unsubscribe(subscriber2Name); - jmsContext.close(); - - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageStoreReceiveTopic_Tcp failed"); } + + return; } From 95d7db9fbb93bc8d525cca4c4433b334231a91e8 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:00:08 +0000 Subject: [PATCH 08/11] Bring testPersistentMessageStore methods together before merge --- .../deliverydelay/fat/DelayFullTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java index 22ae6cd6cee..2ee3206aa58 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java @@ -311,6 +311,11 @@ public void testDeliveryDelayForDifferentDelays_Topic() throws Exception { restartServers(); } + // Tests that test the persistence of delivery delay messages over a server restart + // Each test calls a sender method in the servlet that sends 2 message, 1 persistent and 1 nonpersistent. + // Then the servers are restarted and the servlet is called to attempt to receive the messages. + // Where possible, these are amalgamated to call multiple sender and the associated receiver methods around a single server restart to reduce the number of restarts that are needed. + @Test public void testPersistentMessageStore_B() throws Exception { runInServlet("testPersistentMessage"); @@ -322,23 +327,23 @@ public void testPersistentMessageStore_B() throws Exception { } @Test - public void testPersistentMessageStore_Tcp() throws Exception { - runInServlet("testPersistentMessage_Tcp"); + public void testPersistentMessageStoreTopic_B() throws Exception { + runInServlet("testPersistentMessageTopic"); restartServers(); - boolean testResult = runInServlet("testPersistentMessageReceive_Tcp"); - assertTrue("testPersistentMessageStore_Tcp failed", testResult); + boolean testResult = runInServlet("testPersistentMessageReceiveTopic"); + assertTrue("testPersistentMessageStoreTopic_B failed", testResult); } @Test - public void testPersistentMessageStoreTopic_B() throws Exception { - runInServlet("testPersistentMessageTopic"); + public void testPersistentMessageStore_Tcp() throws Exception { + runInServlet("testPersistentMessage_Tcp"); restartServers(); - boolean testResult = runInServlet("testPersistentMessageReceiveTopic"); - assertTrue("testPersistentMessageStoreTopic_B failed", testResult); + boolean testResult = runInServlet("testPersistentMessageReceive_Tcp"); + assertTrue("testPersistentMessageStore_Tcp failed", testResult); } @Test From c96a911faa6b31adf0d208496a49ceb27356361b Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:10:13 +0000 Subject: [PATCH 09/11] Merge ptp and pubsub deliverydelay persistence tests --- .../deliverydelay/fat/DelayFullTest.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java index 2ee3206aa58..6dfa3a038d7 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/fat/src/com/ibm/ws/messaging/jms20/deliverydelay/fat/DelayFullTest.java @@ -315,45 +315,48 @@ public void testDeliveryDelayForDifferentDelays_Topic() throws Exception { // Each test calls a sender method in the servlet that sends 2 message, 1 persistent and 1 nonpersistent. // Then the servers are restarted and the servlet is called to attempt to receive the messages. // Where possible, these are amalgamated to call multiple sender and the associated receiver methods around a single server restart to reduce the number of restarts that are needed. - + // Note: for now the ptp messages are checked first, and if a failure is detected, the test fails at this point before the pub/sub results are checked. This could be improved later to check all the results and potentially give a richer response. + + // Simplified API tests @Test public void testPersistentMessageStore_B() throws Exception { + + // Send PtP messages runInServlet("testPersistentMessage"); - - restartServers(); - - boolean testResult = runInServlet("testPersistentMessageReceive"); - assertTrue("testPersistentMessageStore_B failed", testResult); - } - - @Test - public void testPersistentMessageStoreTopic_B() throws Exception { + + // Send pub/sub messages runInServlet("testPersistentMessageTopic"); restartServers(); - boolean testResult = runInServlet("testPersistentMessageReceiveTopic"); - assertTrue("testPersistentMessageStoreTopic_B failed", testResult); + // Receive ptp messages + boolean ptpTestResult = runInServlet("testPersistentMessageReceive"); + assertTrue("testPersistentMessageStore_B failed", ptpTestResult); + + // Receive pubsub messages + boolean pubsubTestResult = runInServlet("testPersistentMessageReceiveTopic"); + assertTrue("testPersistentMessageStoreTopic_B failed", pubsubTestResult); } + @Test public void testPersistentMessageStore_Tcp() throws Exception { + + // Send PtP messages runInServlet("testPersistentMessage_Tcp"); - restartServers(); - - boolean testResult = runInServlet("testPersistentMessageReceive_Tcp"); - assertTrue("testPersistentMessageStore_Tcp failed", testResult); - } - - @Test - public void testPersistentMessageStoreTopic_Tcp() throws Exception { + // Send pub/sub messages runInServlet("testPersistentMessageTopic_Tcp"); restartServers(); - boolean testResult = runInServlet("testPersistentMessageReceiveTopic_Tcp"); - assertTrue("testPersistentMessageStoreTopic_B failed", testResult); + // Receive ptp messages + boolean ptpTestResult = runInServlet("testPersistentMessageReceive_Tcp"); + assertTrue("testPersistentMessageStore_Tcp failed", ptpTestResult); + + // Receive pubsub messages + boolean pubsubTestResult = runInServlet("testPersistentMessageReceiveTopic_Tcp"); + assertTrue("testPersistentMessageStoreTopic_B failed", pubsubTestResult); } From 60a1e45d11380a3a4d4aa4a203d4887d8f325c8e Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:18:27 +0000 Subject: [PATCH 10/11] Add new classicAPI generic sender and receiver methods --- .../web/DeliveryDelayServlet.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index f5620889801..6c978c73e6f 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1467,6 +1467,121 @@ public void testPersistentMessageReceiveTopic_Tcp( // Old tests for classic API + // The new consolidated versions use the JMS1.1 unified domain objects instead of the older JMS1.02 domain-specific objects. + + + // New consolidated classic API persistent test sender method + private boolean testPersistentMessageClassicAPI_send(ConnectionFactory cf, + Destination persistentMessageDestination, + Destination nonpersistentMessageDestination, + String identifier) + throws Exception { + + // If we are sending pub/sub messages then we need to ensure there are durable subscribers that can receive the messages. + MessageConsumer consumer1 = null, consumer2 = null; + + boolean pubSub = persistentMessageDestination instanceof Topic; + boolean testPassed = true; + + String subscriber1Name = "durPersMsg1_" + identifier; + String subscriber2Name = "durPersMsg2_" + identifier; + + Connection connection = cf.createConnection(); + connection.start(); + + Session session = connection.createSession(Session.AUTO_ACKNOWLEDGE); + + MessageProducer producer1 = session.createProducer(persistentMessageDestination); + MessageProducer producer2 = session.createProducer(nonpersistentMessageDestination); + + if (pubSub) { + consumer1 = session.createDurableConsumer((Topic)persistentMessageDestination, subscriber1Name); + consumer2 = session.createDurableConsumer((Topic)nonpersistentMessageDestination, subscriber2Name); + } + else { + emptyQueue(cf, (Queue)persistentMessageDestination); + emptyQueue(cf, (Queue)nonpersistentMessageDestination); + } + + producer1.setDeliveryMode(DeliveryMode.PERSISTENT); + producer1.setDeliveryDelay(defaultTestDeliveryDelay); + TextMessage msg1 = session.createTextMessage("PersistentMessage_" + identifier); + producer1.send(msg1); + + producer2.setDeliveryDelay(defaultTestDeliveryDelay); + producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + TextMessage msg2 = session.createTextMessage("NonPersistentMessage_" + identifier); + producer2.send(msg2); + + + // If we're running in the pub/sub domain then close the subscribers (the subscriptions will remain open + if (pubSub) { + consumer1.close(); + consumer2.close(); + } + + session.close(); + connection.close(); + + return testPassed; + } + + // New consolidated classic API persistent test receiver method + private boolean testPersistentMessageClassicAPI_receive(ConnectionFactory cf, + Destination persistentMessageDestination, + Destination nonpersistentMessageDestination, + String identifier) + throws Exception { + + boolean pubSub = persistentMessageDestination instanceof Topic; + boolean testPassed = true; + + String subscriber1Name = "durPersMsg1_" + identifier; + String subscriber2Name = "durPersMsg2_" + identifier; + + MessageConsumer consumer1 = null, consumer2 = null; + + + Connection connection = cf.createConnection(); + connection.start(); + + Session session = connection.createSession(Session.AUTO_ACKNOWLEDGE); + + if (pubSub) { + consumer1 = session.createDurableConsumer((Topic) persistentMessageDestination, subscriber1Name); + consumer2 = session.createDurableConsumer((Topic) nonpersistentMessageDestination, subscriber2Name); + } + else { + consumer1 = session.createConsumer(persistentMessageDestination); + consumer2 = session.createConsumer(nonpersistentMessageDestination); + } + + // Try to receive a message from each destination. Wait for twice the default deliveryDelay time if required + // Only the persistentMessageDestination should receive something + + TextMessage recMsg1 = (TextMessage) consumer1.receive(defaultTestDeliveryDelay * 2); + TextMessage recMsg2 = (TextMessage) consumer2.receive(defaultTestDeliveryDelay * 2); + + // and check whether we got the expected results + if ( ((recMsg1 == null) || // If we failed to get a persistent message + (recMsg1.getText() == null) || // or the message had no payload... + !recMsg1.getText().equals("PersistentMessage_" + identifier)) || // ...or the payload wasn't what we expected (implying it's a message from some other test or something) + (recMsg2 != null) ) { // or we received a message from the nonpersistentMessageDestination (as the message there should not have persisted over the server restart) + testPassed = false; // ...then we need to mark the test as failed. + } + + // Tidy up + consumer1.close(); + consumer2.close(); + + if (pubSub) { + session.unsubscribe(subscriber1Name); + session.unsubscribe(subscriber2Name); + } + + return testPassed; + } + public void testPersistentMessageClassicApi( HttpServletRequest request, HttpServletResponse response) throws Exception { From 57f528ac50b4f76e9c324e9287fc85c749772ae2 Mon Sep 17 00:00:00 2001 From: Luke Saker <29537386+sakerl@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:35:03 +0000 Subject: [PATCH 11/11] Use classicAPI generic sender and receiver methods --- .../web/DeliveryDelayServlet.java | 236 +++--------------- 1 file changed, 31 insertions(+), 205 deletions(-) diff --git a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java index 6c978c73e6f..ffc9a0d63de 100644 --- a/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java +++ b/dev/com.ibm.ws.messaging.open_jms20deliverydelay_fat/test-applications/DeliveryDelay/src/deliverydelay/web/DeliveryDelayServlet.java @@ -1583,258 +1583,84 @@ private boolean testPersistentMessageClassicAPI_receive(ConnectionFactory cf, } + private String testPersistentQueueMessageClassicIdentifier = "testPersistentQueueMessageClassic"; + public void testPersistentMessageClassicApi( HttpServletRequest request, HttpServletResponse response) throws Exception { - - QueueConnection con = jmsQCFBindings.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueSender producer1 = sessionSender.createSender(jmsQueue); - emptyQueue(jmsQCFBindings, jmsQueue); - - QueueSender producer2 = sessionSender.createSender(jmsQueue1); - emptyQueue(jmsQCFBindings, jmsQueue1); - - producer1.setDeliveryMode(DeliveryMode.PERSISTENT); - producer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); - producer1.send(msg1); - - producer2.setDeliveryDelay(1000); - producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); - producer2.send(msg2); - - sessionSender.close(); - con.close(); + + testPersistentMessageClassicAPI_send(jmsQCFBindings, jmsQueue, jmsQueue1, testPersistentQueueMessageClassicIdentifier); + + return; } public void testPersistentMessageReceiveClassicApi( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - QueueConnection con = jmsQCFBindings.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueReceiver jmsConsumer1 = sessionSender.createReceiver(jmsQueue); - QueueReceiver jmsConsumer2 = sessionSender.createReceiver(jmsQueue); - - QueueSender producer = sessionSender.createSender(jmsQueue1); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - sessionSender.close(); - con.close(); + boolean testPassed = testPersistentMessageClassicAPI_receive(jmsQCFBindings, jmsQueue, jmsQueue1, testPersistentQueueMessageClassicIdentifier); - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceiveClassicApi failed"); } } + + + private String testPersistentQueueMessageClassicTcpIdentifier = "testPersistentQueueMessageClassicTcp"; public void testPersistentMessageClassicApi_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - QueueConnection con = jmsQCFTCP.createQueueConnection(); - con.start(); - - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - QueueSender producer1 = sessionSender.createSender(jmsQueue); - emptyQueue(jmsQCFBindings, jmsQueue); - - QueueSender producer2 = sessionSender.createSender(jmsQueue1); - emptyQueue(jmsQCFBindings, jmsQueue1); - - producer1.setDeliveryMode(DeliveryMode.PERSISTENT); - producer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgClassicApi"); - producer1.send(msg1); - - producer2.setDeliveryDelay(1000); - producer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgClassicApi"); - producer2.send(msg2); - - sessionSender.close(); - con.close(); + testPersistentMessageClassicAPI_send(jmsQCFTCP, jmsQueue, jmsQueue1, testPersistentQueueMessageClassicTcpIdentifier); + + return; } public void testPersistentMessageReceiveClassicApi_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - QueueConnection con = jmsQCFTCP.createQueueConnection(); - con.start(); + boolean testPassed = testPersistentMessageClassicAPI_receive(jmsQCFTCP, jmsQueue, jmsQueue1, testPersistentQueueMessageClassicTcpIdentifier); - QueueSession sessionSender = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - - MessageConsumer jmsConsumer1 = sessionSender.createConsumer(jmsQueue); - MessageConsumer jmsConsumer2 = sessionSender.createConsumer(jmsQueue); - - QueueSender producer = sessionSender.createSender(jmsQueue1); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - sessionSender.close(); - con.close(); - - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceiveClassicApi failed"); } } + + private String testPersistentTopicMessageClassicIdentifier = "testPersistentTopicMessageClassic"; + public void testPersistentMessageTopicClassicApi( HttpServletRequest request, HttpServletResponse response) throws Exception { - TopicConnection con = jmsTCFBindings.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); - - TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); - TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); - - jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); - jmsProducer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApi"); - jmsProducer1.send(msg1); - - jmsProducer2.setDeliveryDelay(1000); - jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApi"); - jmsProducer2.send(msg2); - - con.close(); + testPersistentMessageClassicAPI_send(jmsTCFBindings, jmsTopic, jmsTopic1, testPersistentTopicMessageClassicIdentifier); + + return; } public void testPersistentMessageReceiveTopicClassicApi( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - TopicConnection con = jmsTCFBindings.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCA1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCA2"); - - TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); + boolean testPassed = testPersistentMessageClassicAPI_receive(jmsTCFBindings, jmsTopic, jmsTopic1, testPersistentTopicMessageClassicIdentifier); - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApi")) || - (msg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - - sessionSender.unsubscribe("durPersMsgCA1"); - sessionSender.unsubscribe("durPersMsgCA2"); - sessionSender.close(); - - con.close(); - - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageReceiveTopicClassicApi failed"); } } + private String testPersistentTopicMessageClassicTcpIdentifier = "testPersistentTopicMessageClassicTcp"; + public void testPersistentMessageTopicClassicApi_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - TopicConnection con = jmsTCFTCP.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); - - TopicPublisher jmsProducer1 = sessionSender.createPublisher(jmsTopic); - TopicPublisher jmsProducer2 = sessionSender.createPublisher(jmsTopic1); - - jmsProducer1.setDeliveryMode(DeliveryMode.PERSISTENT); - jmsProducer1.setDeliveryDelay(1000); - TextMessage msg1 = sessionSender.createTextMessage("testPersistentMessage_PersistentMsgTopicClassicApiTcp"); - jmsProducer1.send(msg1); - - jmsProducer2.setDeliveryDelay(1000); - jmsProducer2.setDeliveryMode(DeliveryMode.NON_PERSISTENT); - TextMessage msg2 = sessionSender.createTextMessage("testPersistentMessage_NonPersistentMsgTopicClassicApiTcp"); - jmsProducer2.send(msg2); - - con.close(); + testPersistentMessageClassicAPI_send(jmsTCFTCP, jmsTopic, jmsTopic1, testPersistentTopicMessageClassicTcpIdentifier); + + return; } public void testPersistentMessageReceiveTopicClassicApi_Tcp( HttpServletRequest request, HttpServletResponse response) throws Exception { - boolean testFailed = false; - - TopicConnection con = jmsTCFTCP.createTopicConnection(); - con.start(); - - TopicSession sessionSender = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - TopicSubscriber jmsConsumer1 = sessionSender.createDurableSubscriber(jmsTopic, "durPersMsgCATcp1"); - TopicSubscriber jmsConsumer2 = sessionSender.createDurableSubscriber(jmsTopic1, "durPersMsgCATcp2"); - - TopicPublisher jmsProducer = sessionSender.createPublisher(jmsTopic); - - TextMessage msg1 = (TextMessage) jmsConsumer1.receive(30000); - TextMessage msg2 = (TextMessage) jmsConsumer2.receive(30000); - - if ( ((msg1 == null) || - (msg1.getText() == null) || - !msg1.getText().equals("testPersistentMessage_PersistentMsgTopicClassicApiTcp")) || - (msg2 != null) ) { - testFailed = true; - } - - jmsConsumer1.close(); - jmsConsumer2.close(); - - sessionSender.unsubscribe("durPersMsgCATcp1"); - sessionSender.unsubscribe("durPersMsgCATcp2"); - sessionSender.close(); - - con.close(); + boolean testPassed = testPersistentMessageClassicAPI_receive(jmsTCFTCP, jmsTopic, jmsTopic1, testPersistentTopicMessageClassicTcpIdentifier); - if ( testFailed ) { + if ( !testPassed ) { throw new Exception("testPersistentMessageStoreReceiveTopicClassicApi_Tcp failed"); } }