From e8a4a32c8384ee6eaa528596afcf042ccb8c99d1 Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Wed, 8 Sep 2010 12:19:43 +0000 Subject: [PATCH] https://issues.apache.org/activemq/browse/AMQ-2897 - start job scheduler on start git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@995016 13f79535-47bb-0310-9956-ffa450edef68 --- .../broker/scheduler/SchedulerBroker.java | 1 + .../broker/scheduler/JmsSchedulerTest.java | 40 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java b/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java index 1e7b098857..438be97365 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java @@ -82,6 +82,7 @@ public class SchedulerBroker extends BrokerFilter implements JobListener { @Override public void start() throws Exception { this.started.set(true); + getInternalScheduler(); super.start(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java index 83df65e1ce..9e07060dc0 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java @@ -176,6 +176,36 @@ public class JmsSchedulerTest extends EmbeddedBrokerTestSupport { Thread.sleep(1000); assertEquals(NUMBER, count.get()); } + + public void testScheduleRestart() throws Exception { + // send a message + Connection connection = createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + connection.start(); + MessageProducer producer = session.createProducer(destination); + TextMessage message = session.createTextMessage("test msg"); + long time = 5000; + message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); + producer.send(message); + producer.close(); + + //restart broker + broker.stop(); + broker.waitUntilStopped(); + + broker = createBroker(false); + broker.start(); + broker.waitUntilStarted(); + + + // consume the message + connection = createConnection(); + connection.start(); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consumer = session.createConsumer(destination); + Message msg = consumer.receive(5000); + assertNotNull("Didn't receive the message", msg); + } @Override protected void setUp() throws Exception { @@ -185,9 +215,15 @@ public class JmsSchedulerTest extends EmbeddedBrokerTestSupport { @Override protected BrokerService createBroker() throws Exception { + return createBroker(true); + } + + protected BrokerService createBroker(boolean delete) throws Exception { File schedulerDirectory = new File("target/scheduler"); - IOHelper.mkdirs(schedulerDirectory); - IOHelper.deleteChildren(schedulerDirectory); + if (delete) { + IOHelper.mkdirs(schedulerDirectory); + IOHelper.deleteChildren(schedulerDirectory); + } BrokerService answer = new BrokerService(); answer.setPersistent(isPersistent()); answer.setDeleteAllMessagesOnStartup(true);