Search in sources :

Example 21 with ByteSequence

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

the class JobSchedulerStoreCheckpointTest method test.

@Test
public void test() throws Exception {
    final int COUNT = 10;
    final CountDownLatch latch = new CountDownLatch(COUNT);
    scheduler.addListener(new JobListener() {

        @Override
        public void scheduledJob(String id, ByteSequence job) {
            latch.countDown();
        }
    });
    long time = TimeUnit.SECONDS.toMillis(30);
    for (int i = 0; i < COUNT; i++) {
        scheduler.schedule("id" + i, payload, "", time, 0, 0);
    }
    int size = scheduler.getAllJobs().size();
    assertEquals(size, COUNT);
    LOG.info("Number of journal log files: {}", getNumJournalFiles());
    // need a little slack so go over 60 seconds
    assertTrue(latch.await(70, TimeUnit.SECONDS));
    assertEquals(0, latch.getCount());
    for (int i = 0; i < COUNT; i++) {
        scheduler.schedule("id" + i, payload, "", time, 0, 0);
    }
    LOG.info("Number of journal log files: {}", getNumJournalFiles());
    // need a little slack so go over 60 seconds
    assertTrue(latch.await(70, TimeUnit.SECONDS));
    assertEquals(0, latch.getCount());
    assertTrue("Should be only one log left: " + getNumJournalFiles(), Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return getNumJournalFiles() == 1;
        }
    }, TimeUnit.MINUTES.toMillis(2)));
    LOG.info("Number of journal log files: {}", getNumJournalFiles());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Example 22 with ByteSequence

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

the class JobSchedulerTest method testAddLongStringByteSequence.

@Test
public void testAddLongStringByteSequence() throws Exception {
    final int COUNT = 10;
    final CountDownLatch latch = new CountDownLatch(COUNT);
    scheduler.addListener(new JobListener() {

        @Override
        public void scheduledJob(String id, ByteSequence job) {
            latch.countDown();
        }
    });
    for (int i = 0; i < COUNT; i++) {
        String test = new String("test" + i);
        scheduler.schedule("id" + i, new ByteSequence(test.getBytes()), 1000);
    }
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(0, latch.getCount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Example 23 with ByteSequence

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

the class JobSchedulerTest method testgetAllJobsInRange.

@Test
public void testgetAllJobsInRange() throws Exception {
    final int COUNT = 10;
    final String ID = "id:";
    long start = 10000;
    for (int i = 0; i < COUNT; i++) {
        String str = new String("test" + i);
        scheduler.schedule(ID + i, new ByteSequence(str.getBytes()), "", start + (i * 1000), 10000 + i, 0);
    }
    start = System.currentTimeMillis();
    long finish = start + 12000 + (COUNT * 1000);
    List<Job> list = scheduler.getAllJobs(start, finish);
    assertEquals(COUNT, list.size());
    int count = 0;
    for (Job job : list) {
        assertEquals(job.getJobId(), ID + count);
        count++;
    }
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Example 24 with ByteSequence

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

the class JobSchedulerTest method testRemoveString.

@Test
public void testRemoveString() throws Exception {
    final int COUNT = 10;
    final String test = "TESTREMOVE";
    long time = 20000;
    for (int i = 0; i < COUNT; i++) {
        String str = new String("test" + i);
        scheduler.schedule("id" + i, new ByteSequence(str.getBytes()), "", time, 1000, -1);
        if (i == COUNT / 2) {
            scheduler.schedule(test, new ByteSequence(test.getBytes()), "", time, 1000, -1);
        }
    }
    int size = scheduler.getAllJobs().size();
    assertEquals(size, COUNT + 1);
    scheduler.remove(test);
    size = scheduler.getAllJobs().size();
    assertEquals(size, COUNT);
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence) Test(org.junit.Test)

Example 25 with ByteSequence

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

the class JobSchedulerTest method testRemoveLong.

@Test
public void testRemoveLong() throws Exception {
    final int COUNT = 10;
    long time = 60000;
    for (int i = 0; i < COUNT; i++) {
        String str = new String("test" + i);
        scheduler.schedule("id" + i, new ByteSequence(str.getBytes()), "", time, 1000, -1);
    }
    int size = scheduler.getAllJobs().size();
    assertEquals(size, COUNT);
    long removeTime = scheduler.getNextScheduleTime();
    scheduler.remove(removeTime);
    // If all jobs are not started within the same second we need to call remove again
    if (size != 0) {
        removeTime = scheduler.getNextScheduleTime();
        scheduler.remove(removeTime);
    }
    size = scheduler.getAllJobs().size();
    assertEquals(0, size);
}
Also used : 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