[ 
https://issues.apache.org/jira/browse/ARTEMIS-5142?focusedWorklogId=948597&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-948597
 ]

ASF GitHub Bot logged work on ARTEMIS-5142:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Dec/24 16:00
            Start Date: 16/Dec/24 16:00
    Worklog Time Spent: 10m 
      Work Description: gemmellr commented on code in PR #5390:
URL: https://github.com/apache/activemq-artemis/pull/5390#discussion_r1886922435


##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;

Review Comment:
   The even number, 10_000_000, would be more readable and better align with 
the later division by 2.
   
   



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;
+   private final long WINDOW = 20L;
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageExpiryDelay() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageExpiryDelay() throws Exception {
+      testExpiry(createConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageExpiryDelay() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageNeverExpire() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageNeverExpire() throws Exception {
+      testExpiry(createConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageNeverExpire() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NEVER, true);
+   }
+
+   private void testExpiry(Connection connection, DelayType delayType, boolean 
setTimeToLive) throws Exception {
+      AddressSettings addressSettings = new AddressSettings();
+      if (delayType == DelayType.NORMAL) {
+         addressSettings.setExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MIN) {
+         addressSettings.setMinExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MAX) {
+         addressSettings.setMaxExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.NEVER) {
+         addressSettings.setNeverExpire(true);
+      }
+      server.getAddressSettingsRepository().addMatch(getQueueName(), 
addressSettings);
+
+      Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue q = s.createQueue(getQueueName());
+      MessageProducer p = s.createProducer(q);
+      if (setTimeToLive) {
+         if (delayType == DelayType.MIN) {
+            p.setTimeToLive(EXPIRY_DELAY / 2);
+         } else if (delayType == DelayType.MAX) {
+            p.setTimeToLive(EXPIRY_DELAY * 2);
+         } else if (delayType == DelayType.NEVER) {
+            p.setTimeToLive(EXPIRY_DELAY);
+         }
+      }
+      long start = System.currentTimeMillis();
+      p.send(s.createMessage());
+      p.close();
+      MessageConsumer c = s.createConsumer(q);
+      connection.start();
+      Message m = c.receive(100);
+      assertNotNull(m);
+      if (delayType == DelayType.NEVER) {
+         assertEquals(0, m.getJMSExpiration());
+      } else {
+         long duration = System.currentTimeMillis() - start;
+         long delayOnMessage = m.getJMSExpiration() - 
System.currentTimeMillis();
+         assertTrue(delayOnMessage >= (EXPIRY_DELAY - duration - WINDOW));

Review Comment:
   Feels like WINDOW shouldnt really be doing anything (at least after using 
same reference for both calcs above) since you are already deducting a 
'duration' which is including the consumer receive (and an assertNotNull) which 
necessarily makes it >= the broker-side elapsed time which could have 
influenced the actual expiration stamped by the broker, i.e you should already 
be deducting more than enough with just that?



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;
+   private final long WINDOW = 20L;
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageExpiryDelay() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageExpiryDelay() throws Exception {
+      testExpiry(createConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageExpiryDelay() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NORMAL, false);
+   }

Review Comment:
   Given the differences in handling of 'large' and 'normal' messages I think 
both need covered in at least 1 test. Also, given there is explicit handling of 
expiration in the persisting and reload of durable messages, I think a test 
which restarts the broker before consumption is probably needed for both also.



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;
+   private final long WINDOW = 20L;
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageExpiryDelay() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageExpiryDelay() throws Exception {
+      testExpiry(createConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageExpiryDelay() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageNeverExpire() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageNeverExpire() throws Exception {
+      testExpiry(createConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageNeverExpire() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NEVER, true);
+   }
+
+   private void testExpiry(Connection connection, DelayType delayType, boolean 
setTimeToLive) throws Exception {
+      AddressSettings addressSettings = new AddressSettings();
+      if (delayType == DelayType.NORMAL) {
+         addressSettings.setExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MIN) {
+         addressSettings.setMinExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MAX) {
+         addressSettings.setMaxExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.NEVER) {
+         addressSettings.setNeverExpire(true);
+      }
+      server.getAddressSettingsRepository().addMatch(getQueueName(), 
addressSettings);
+
+      Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue q = s.createQueue(getQueueName());
+      MessageProducer p = s.createProducer(q);
+      if (setTimeToLive) {
+         if (delayType == DelayType.MIN) {
+            p.setTimeToLive(EXPIRY_DELAY / 2);
+         } else if (delayType == DelayType.MAX) {
+            p.setTimeToLive(EXPIRY_DELAY * 2);
+         } else if (delayType == DelayType.NEVER) {
+            p.setTimeToLive(EXPIRY_DELAY);
+         }
+      }
+      long start = System.currentTimeMillis();
+      p.send(s.createMessage());

Review Comment:
   Would be better to create the message then record start, since the period of 
interest begins with the send itself.



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;
+   private final long WINDOW = 20L;
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageExpiryDelay() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageExpiryDelay() throws Exception {
+      testExpiry(createConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageExpiryDelay() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageNeverExpire() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageNeverExpire() throws Exception {
+      testExpiry(createConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageNeverExpire() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NEVER, true);
+   }
+
+   private void testExpiry(Connection connection, DelayType delayType, boolean 
setTimeToLive) throws Exception {
+      AddressSettings addressSettings = new AddressSettings();
+      if (delayType == DelayType.NORMAL) {
+         addressSettings.setExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MIN) {
+         addressSettings.setMinExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MAX) {
+         addressSettings.setMaxExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.NEVER) {
+         addressSettings.setNeverExpire(true);
+      }
+      server.getAddressSettingsRepository().addMatch(getQueueName(), 
addressSettings);
+
+      Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue q = s.createQueue(getQueueName());
+      MessageProducer p = s.createProducer(q);
+      if (setTimeToLive) {
+         if (delayType == DelayType.MIN) {
+            p.setTimeToLive(EXPIRY_DELAY / 2);
+         } else if (delayType == DelayType.MAX) {
+            p.setTimeToLive(EXPIRY_DELAY * 2);
+         } else if (delayType == DelayType.NEVER) {
+            p.setTimeToLive(EXPIRY_DELAY);
+         }
+      }
+      long start = System.currentTimeMillis();
+      p.send(s.createMessage());
+      p.close();
+      MessageConsumer c = s.createConsumer(q);
+      connection.start();
+      Message m = c.receive(100);

Review Comment:
   Since we do expect to get a message, this seems a bit short and potentially 
brittle to sporadic failure.



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSMessageExpiryTest.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import java.lang.invoke.MethodHandles;
+
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JMSMessageExpiryTest extends MultiprotocolJMSClientTestSupport {
+
+   protected static final Logger logger = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+   private final long EXPIRY_DELAY = 9999999L;
+   private final long WINDOW = 20L;
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageExpiryDelay() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageExpiryDelay() throws Exception {
+      testExpiry(createConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageExpiryDelay() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NORMAL, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayNoExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, false);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMaxExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MAX, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMinExpiryDelayWithExpiration() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.MIN, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testCoreMessageNeverExpire() throws Exception {
+      testExpiry(createCoreConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testAmqpMessageNeverExpire() throws Exception {
+      testExpiry(createConnection(), DelayType.NEVER, true);
+   }
+
+   @Test
+   @Timeout(30)
+   public void testOpenWireMessageNeverExpire() throws Exception {
+      testExpiry(createOpenWireConnection(), DelayType.NEVER, true);
+   }
+
+   private void testExpiry(Connection connection, DelayType delayType, boolean 
setTimeToLive) throws Exception {
+      AddressSettings addressSettings = new AddressSettings();
+      if (delayType == DelayType.NORMAL) {
+         addressSettings.setExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MIN) {
+         addressSettings.setMinExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.MAX) {
+         addressSettings.setMaxExpiryDelay(EXPIRY_DELAY);
+      } else if (delayType == DelayType.NEVER) {
+         addressSettings.setNeverExpire(true);
+      }
+      server.getAddressSettingsRepository().addMatch(getQueueName(), 
addressSettings);
+
+      Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue q = s.createQueue(getQueueName());
+      MessageProducer p = s.createProducer(q);
+      if (setTimeToLive) {
+         if (delayType == DelayType.MIN) {
+            p.setTimeToLive(EXPIRY_DELAY / 2);
+         } else if (delayType == DelayType.MAX) {
+            p.setTimeToLive(EXPIRY_DELAY * 2);
+         } else if (delayType == DelayType.NEVER) {
+            p.setTimeToLive(EXPIRY_DELAY);
+         }
+      }
+      long start = System.currentTimeMillis();
+      p.send(s.createMessage());
+      p.close();
+      MessageConsumer c = s.createConsumer(q);
+      connection.start();
+      Message m = c.receive(100);
+      assertNotNull(m);
+      if (delayType == DelayType.NEVER) {
+         assertEquals(0, m.getJMSExpiration());
+      } else {
+         long duration = System.currentTimeMillis() - start;
+         long delayOnMessage = m.getJMSExpiration() - 
System.currentTimeMillis();

Review Comment:
   Could also just call System.currentTimeMillis() once after the receive and 
record it so both duration and delayOnMessage are more precisely calculated 
from the same reference.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 948597)
    Time Spent: 6h 40m  (was: 6.5h)

> Setting 0 for min/max-expiry-delay not working as expected
> ----------------------------------------------------------
>
>                 Key: ARTEMIS-5142
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-5142
>             Project: ActiveMQ Artemis
>          Issue Type: Improvement
>            Reporter: Justin Bertram
>            Assignee: Justin Bertram
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 6h 40m
>  Remaining Estimate: 0h
>
> In an attempt to never expire messages I tried setting either 
> {{max-expiry-delay}} or {{min-expiry-delay}} to {{0}}. However, this caused 
> messages to be expired _immediately_ rather than not expired at. There 
> doesn't appear to be any way to categorically prevent incoming messages sent 
> to a particular from expiring.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to