Search in sources :

Example 1 with JobSchedulerStoreImpl

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());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Connection(javax.jms.Connection) JobSchedulerStoreImpl(org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl) File(java.io.File) Test(org.junit.Test)

Example 2 with JobSchedulerStoreImpl

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;
}
Also used : JobSchedulerStoreImpl(org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl)

Example 3 with JobSchedulerStoreImpl

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());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ScheduledMessage(org.apache.activemq.ScheduledMessage) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobSchedulerStoreImpl(org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl) File(java.io.File) BrokerService(org.apache.activemq.broker.BrokerService) Queue(javax.jms.Queue) Session(javax.jms.Session)

Example 4 with JobSchedulerStoreImpl

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();
}
Also used : JobSchedulerStoreImpl(org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl)

Example 5 with JobSchedulerStoreImpl

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);
    }
}
Also used : ArrayList(java.util.ArrayList) JobSchedulerStoreImpl(org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl) File(java.io.File) ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Aggregations

JobSchedulerStoreImpl (org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl)8 File (java.io.File)5 Connection (javax.jms.Connection)4 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Queue (javax.jms.Queue)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 ScheduledMessage (org.apache.activemq.ScheduledMessage)1 BrokerService (org.apache.activemq.broker.BrokerService)1 ByteSequence (org.apache.activemq.util.ByteSequence)1 Ignore (org.junit.Ignore)1