ARTEMIS-4726 fix original commit

The original commit (1ee3e884b7) for this
issue wasn't completely correct. This commit fixes those issues so that
both the messageCount and scheduledMessageCount are accurate now when
a scheduled message is removed by its ID.
This commit is contained in:
Justin Bertram 2024-05-22 23:19:33 -05:00
parent 3244965155
commit c47713454c
6 changed files with 22 additions and 2 deletions

View File

@ -275,6 +275,11 @@ public class PagedReferenceImpl extends AbstractProtocolReference implements Pag
getQueue().acknowledge(tx, this, reason, consumer, true);
}
@Override
public void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer, boolean delivering) throws Exception {
getQueue().acknowledge(tx, this, reason, consumer, delivering);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -114,6 +114,8 @@ public interface MessageReference {
void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer) throws Exception;
void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer, boolean delivering) throws Exception;
void emptyConsumerID();
void setConsumerId(long consumerID);

View File

@ -168,6 +168,11 @@ public class GroupFirstMessageReference implements MessageReference {
messageReference.acknowledge(tx, reason, consumer);
}
@Override
public void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer, boolean delivering) throws Exception {
messageReference.acknowledge(tx, reason, consumer, delivering);
}
@Override
public void emptyConsumerID() {
messageReference.emptyConsumerID();

View File

@ -266,10 +266,15 @@ public class MessageReferenceImpl extends AbstractProtocolReference implements M
@Override
public void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer) throws Exception {
acknowledge(tx, reason, consumer, true);
}
@Override
public void acknowledge(Transaction tx, AckReason reason, ServerConsumer consumer, boolean delivering) throws Exception {
if (tx == null) {
getQueue().acknowledge(this, reason, consumer);
} else {
getQueue().acknowledge(tx, this, reason, consumer, true);
getQueue().acknowledge(tx, this, reason, consumer, delivering);
}
}

View File

@ -175,9 +175,10 @@ public class ScheduledDeliveryHandlerImpl implements ScheduledDeliveryHandler {
while (iter.hasNext()) {
MessageReference ref = iter.next().getRef();
if (ref.getMessage().getMessageID() == id) {
ref.acknowledge(tx);
ref.acknowledge(tx, AckReason.NORMAL, null, false);
iter.remove();
notifyScheduledReferencesUpdated();
metrics.decrementMetrics(ref);
return ref;
}
}

View File

@ -557,8 +557,10 @@ public class ScheduledMessageTest extends ActiveMQTestBase {
QueueControl queueControl = (QueueControl) server.getManagementService().getResource(ResourceNames.QUEUE + atestq);
assertEquals(1, queueControl.getMessageCount());
assertEquals(1, queueControl.getScheduledCount());
assertTrue(queueControl.removeMessage((long) queueControl.listScheduledMessages()[0].get("messageID")));
assertEquals(0, queueControl.getMessageCount());
assertEquals(0, queueControl.getScheduledCount());
}
@Test