-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for deleting all scheduled messages on startup
- Loading branch information
Showing
6 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...org/apache/activemq/broker/scheduler/JmsSchedulerDeleteAllMessageOnStartupOptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.apache.activemq.broker.scheduler; | ||
|
||
import jakarta.jms.Connection; | ||
import jakarta.jms.Message; | ||
import jakarta.jms.MessageConsumer; | ||
import jakarta.jms.MessageListener; | ||
import jakarta.jms.MessageProducer; | ||
import jakarta.jms.Session; | ||
import jakarta.jms.TextMessage; | ||
import org.apache.activemq.ScheduledMessage; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class JmsSchedulerDeleteAllMessageOnStartupOptionTest extends JobSchedulerTestSupport { | ||
|
||
private static final transient Logger LOG = LoggerFactory.getLogger(JmsSchedulerDeleteAllMessageOnStartupOptionTest.class); | ||
|
||
@Override | ||
protected boolean shouldDeleteAllScheduledMessagesOnStartup() throws Exception { | ||
return true; | ||
} | ||
|
||
@Test | ||
public void testDeleteAllMessageOnRestart() throws Exception { | ||
// Send a message delayed by 8 seconds | ||
Connection connection = createConnection(); | ||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); | ||
connection.start(); | ||
long time_ms = 10 * 1000; | ||
MessageProducer producer = session.createProducer(destination); | ||
TextMessage message = session.createTextMessage("test msg"); | ||
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time_ms); | ||
producer.send(message); | ||
producer.close(); | ||
// Shutdown broker | ||
restartBroker(RestartType.NORMAL); | ||
// Make sure the consumer won't get the message | ||
connection = createConnection(); | ||
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); | ||
MessageConsumer consumer = session.createConsumer(destination); | ||
final int COUNT = 1; | ||
final CountDownLatch latch = new CountDownLatch(COUNT); | ||
consumer.setMessageListener(new MessageListener() { | ||
@Override | ||
public void onMessage(Message message) { | ||
latch.countDown(); | ||
} | ||
}); | ||
latch.await(20, TimeUnit.SECONDS); | ||
assertEquals(latch.getCount(), COUNT); | ||
connection.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters