Search in sources :

Example 31 with ByteSequence

use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.

the class InMemoryJobSchedulerStoreTest method testRestart.

@Test(timeout = 120 * 1000)
public void testRestart() throws Exception {
    InMemoryJobSchedulerStore store = new InMemoryJobSchedulerStore();
    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(0, test.size());
}
Also used : JobScheduler(org.apache.activemq.broker.scheduler.JobScheduler) ArrayList(java.util.ArrayList) Job(org.apache.activemq.broker.scheduler.Job) File(java.io.File) ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Aggregations

ByteSequence (org.apache.activemq.util.ByteSequence)31 Test (org.junit.Test)13 CountDownLatch (java.util.concurrent.CountDownLatch)6 File (java.io.File)4 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 ArrayList (java.util.ArrayList)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 DataStructure (org.apache.activemq.command.DataStructure)2 MessageId (org.apache.activemq.command.MessageId)2 ProducerId (org.apache.activemq.command.ProducerId)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Deflater (java.util.zip.Deflater)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1