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());
}
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());
}
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++;
}
}
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);
}
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);
}
Aggregations