From 9799c8ce880c671bb5ba2fe28017a24b6de18985 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Sat, 12 Oct 2024 09:56:08 -0400 Subject: [PATCH] Fix producer wrapper should not set delivery delay on wrapped resource The producer wrapper holds the delivery delay for the wrapped instance and should not be setting the value on the underlying JMS producer which could be shared amongst threads and can be retained across create calls --- .../pooled/jms/JmsPoolMessageProducer.java | 1 - .../jms/JmsPoolMessageProducerTest.java | 32 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pooled-jms/src/main/java/org/messaginghub/pooled/jms/JmsPoolMessageProducer.java b/pooled-jms/src/main/java/org/messaginghub/pooled/jms/JmsPoolMessageProducer.java index 72a395d..6a65b67 100644 --- a/pooled-jms/src/main/java/org/messaginghub/pooled/jms/JmsPoolMessageProducer.java +++ b/pooled-jms/src/main/java/org/messaginghub/pooled/jms/JmsPoolMessageProducer.java @@ -308,7 +308,6 @@ public void setDeliveryDelay(long deliveryDelay) throws JMSException { session.checkClientJMSVersionSupport(2, 0); this.deliveryDelay = deliveryDelay; - this.messageProducer.setDeliveryDelay(deliveryDelay); } @Override diff --git a/pooled-jms/src/test/java/org/messaginghub/pooled/jms/JmsPoolMessageProducerTest.java b/pooled-jms/src/test/java/org/messaginghub/pooled/jms/JmsPoolMessageProducerTest.java index 1932aa1..901873b 100644 --- a/pooled-jms/src/test/java/org/messaginghub/pooled/jms/JmsPoolMessageProducerTest.java +++ b/pooled-jms/src/test/java/org/messaginghub/pooled/jms/JmsPoolMessageProducerTest.java @@ -22,6 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.messaginghub.pooled.jms.mock.MockJMSDestination; +import org.messaginghub.pooled.jms.mock.MockJMSQueue; +import org.messaginghub.pooled.jms.mock.MockJMSTopic; + import jakarta.jms.CompletionListener; import jakarta.jms.DeliveryMode; import jakarta.jms.Destination; @@ -33,12 +39,6 @@ import jakarta.jms.Queue; import jakarta.jms.Session; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.Timeout; -import org.messaginghub.pooled.jms.mock.MockJMSDestination; -import org.messaginghub.pooled.jms.mock.MockJMSQueue; -import org.messaginghub.pooled.jms.mock.MockJMSTopic; - /** * Tests for the JMS Pool MessageProducer wrapper class. */ @@ -117,6 +117,26 @@ public void testSetDeliveryDelay() throws JMSException { } catch (IllegalStateException ise) {} } + @Test + public void testSetDeliveryDelayNoAppliedToUnderlyingProducer() throws JMSException { + JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); + + Session session = connection.createSession(); + Queue queue = session.createTemporaryQueue(); + MessageProducer producer1 = session.createProducer(queue); + + assertEquals(0, producer1.getDeliveryDelay()); + producer1.setDeliveryDelay(1); + assertEquals(1, producer1.getDeliveryDelay()); + + producer1.close(); + + MessageProducer producer2 = session.createProducer(queue); + assertEquals(0, producer2.getDeliveryDelay()); + producer2.setDeliveryDelay(1); + assertEquals(1, producer2.getDeliveryDelay()); + } + @Test public void testSetPriority() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();