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();