use of org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl in project activemq-artemis by apache.
the class KahaDBSchedulerIndexRebuildTest method testIndexRebuildsAfterSomeJobsExpire.
@Test
public void testIndexRebuildsAfterSomeJobsExpire() throws Exception {
IOHelper.deleteFile(schedulerStoreDir);
JobSchedulerStoreImpl schedulerStore = createScheduler();
broker = createBroker(schedulerStore);
broker.start();
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost");
Connection connection = cf.createConnection();
connection.start();
for (int i = 0; i < NUM_JOBS; ++i) {
scheduleRepeating(connection);
scheduleOneShot(connection);
}
connection.close();
JobScheduler scheduler = schedulerStore.getJobScheduler("JMS");
assertNotNull(scheduler);
assertEquals(NUM_JOBS * 2, scheduler.getAllJobs().size());
final JobScheduler awaitingOneShotTimeout = scheduler;
assertTrue("One shot jobs should time out", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return awaitingOneShotTimeout.getAllJobs().size() == NUM_JOBS;
}
}, TimeUnit.MINUTES.toMillis(2)));
broker.stop();
IOHelper.delete(new File(schedulerStoreDir, "scheduleDB.data"));
schedulerStore = createScheduler();
broker = createBroker(schedulerStore);
broker.start();
scheduler = schedulerStore.getJobScheduler("JMS");
assertNotNull(scheduler);
assertEquals(NUM_JOBS, scheduler.getAllJobs().size());
}
use of org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl in project activemq-artemis by apache.
the class KahaDBSchedulerMissingJournalLogsTest method createScheduler.
protected JobSchedulerStoreImpl createScheduler() {
JobSchedulerStoreImpl scheduler = new JobSchedulerStoreImpl();
scheduler.setDirectory(schedulerStoreDir);
scheduler.setJournalMaxFileLength(10 * 1024);
return scheduler;
}
use of org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl in project activemq-artemis by apache.
the class SchedulerDBVersionTest method doTestScheduleRepeated.
public void doTestScheduleRepeated(File existingStore) throws Exception {
File testDir = new File("target/activemq-data/store/scheduler/versionDB");
IOHelper.deleteFile(testDir);
IOHelper.copyFile(existingStore, testDir);
final int NUMBER = 10;
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost");
for (int i = 0; i < 3; ++i) {
JobSchedulerStoreImpl scheduler = new JobSchedulerStoreImpl();
scheduler.setDirectory(testDir);
scheduler.setJournalMaxFileLength(1024 * 1024);
BrokerService broker = createBroker(scheduler);
broker.start();
broker.waitUntilStarted();
final AtomicInteger count = new AtomicInteger();
Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("test.queue");
MessageConsumer consumer = session.createConsumer(queue);
final CountDownLatch latch = new CountDownLatch(NUMBER);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
LOG.info("Received scheduled message: {}", message);
latch.countDown();
count.incrementAndGet();
}
});
connection.start();
assertEquals(latch.getCount(), NUMBER);
latch.await(30, TimeUnit.SECONDS);
connection.close();
broker.stop();
broker.waitUntilStopped();
assertEquals(0, latch.getCount());
}
}
use of org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl in project activemq-artemis by apache.
the class JobSchedulerStoreCheckpointTest method startStore.
protected void startStore(File directory) throws Exception {
store = new JobSchedulerStoreImpl();
store.setDirectory(directory);
store.setCheckpointInterval(5000);
store.setCleanupInterval(10000);
store.setJournalMaxFileLength(10 * 1024);
store.start();
scheduler = store.getJobScheduler("test");
scheduler.startDispatching();
}
use of org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl in project activemq-artemis by apache.
the class JobSchedulerStoreTest method testRestart.
@Test(timeout = 120 * 1000)
public void testRestart() throws Exception {
JobSchedulerStore store = new JobSchedulerStoreImpl();
File directory = new File("target/test/ScheduledDB");
IOHelper.mkdirs(directory);
IOHelper.deleteChildren(directory);
store.setDirectory(directory);
final int NUMBER = 1000;
store.start();
List<ByteSequence> list = new ArrayList<>();
for (int i = 0; i < NUMBER; i++) {
ByteSequence buff = new ByteSequence(new String("testjob" + i).getBytes());
list.add(buff);
}
JobScheduler js = store.getJobScheduler("test");
js.startDispatching();
int count = 0;
long startTime = 10 * 60 * 1000;
long period = startTime;
for (ByteSequence job : list) {
js.schedule("id:" + (count++), job, "", startTime, period, -1);
}
List<Job> test = js.getAllJobs();
LOG.debug("Found {} jobs in the store before restart", test.size());
assertEquals(list.size(), test.size());
store.stop();
store.start();
js = store.getJobScheduler("test");
test = js.getAllJobs();
LOG.debug("Found {} jobs in the store after restart", test.size());
assertEquals(list.size(), test.size());
for (int i = 0; i < list.size(); i++) {
String orig = new String(list.get(i).getData());
String payload = new String(test.get(i).getPayload());
assertEquals(orig, payload);
}
}
Aggregations