From d158e7eff0f984d844fbb4e7ea040552d8d56b94 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 11 Aug 2022 11:50:00 -0500 Subject: [PATCH] ARTEMIS-3925 LVQ pruning nulls Messages without a last-value property sent to an LVQ are being pruned rather than just passing through. Only messages with a non-null last-value property should be subject to pruning. --- .../core/server/impl/LastValueQueue.java | 3 +++ .../tests/integration/server/LVQTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LastValueQueue.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LastValueQueue.java index 50dc850c09..82cc672450 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LastValueQueue.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/LastValueQueue.java @@ -224,6 +224,9 @@ public class LastValueQueue extends QueueImpl { if (current == ref) { currentLastValue = true; } + } else { + // if the ref has no last value + return true; } return currentLastValue; } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/LVQTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/LVQTest.java index 763f6ee3cd..e9a1049ebb 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/LVQTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/LVQTest.java @@ -140,6 +140,28 @@ public class LVQTest extends ActiveMQTestBase { Assert.assertEquals(m.getBodyBuffer().readString(), "m4"); } + @Test + public void testMultipleMessagesWithoutLastValue() throws Exception { + ClientProducer producer = clientSession.createProducer(address); + ClientMessage m1 = createTextMessage(clientSession, "message1"); + ClientMessage m2 = createTextMessage(clientSession, "message2"); + producer.send(m1); + producer.send(m2); + + Wait.assertEquals(2L, () -> server.locateQueue(qName1).getMessageCount(), 2000, 100); + + ClientConsumer consumer = clientSession.createConsumer(qName1); + clientSession.start(); + ClientMessage m = consumer.receive(1000); + Assert.assertNotNull(m); + m.acknowledge(); + Assert.assertEquals("message1", m.getBodyBuffer().readString()); + m = consumer.receive(1000); + Assert.assertNotNull(m); + m.acknowledge(); + Assert.assertEquals("message2", m.getBodyBuffer().readString()); + } + @Test public void testMultipleRollback() throws Exception { AddressSettings qs = new AddressSettings();