mirror of https://github.com/apache/activemq.git
apply test patch for: https://issues.apache.org/jira/browse/AMQ-4273
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1438161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c5184983cf
commit
af9a1f0d0f
|
@ -26,14 +26,13 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
|
||||
import org.apache.activemq.util.IOHelper;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.IOHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JobSchedulerTest {
|
||||
|
||||
private JobSchedulerStore store;
|
||||
private JobScheduler scheduler;
|
||||
|
||||
|
@ -42,7 +41,7 @@ public class JobSchedulerTest {
|
|||
final int COUNT = 10;
|
||||
final CountDownLatch latch = new CountDownLatch(COUNT);
|
||||
scheduler.addListener(new JobListener() {
|
||||
|
||||
@Override
|
||||
public void scheduledJob(String id, ByteSequence job) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
@ -61,16 +60,15 @@ public class JobSchedulerTest {
|
|||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
scheduler.addListener(new JobListener() {
|
||||
|
||||
@Override
|
||||
public void scheduledJob(String id, ByteSequence job) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Calendar current = Calendar.getInstance();
|
||||
|
||||
int minutes = current.get(Calendar.MINUTE) + 1;
|
||||
current.add(Calendar.MINUTE, 1);
|
||||
int minutes = current.get(Calendar.MINUTE);
|
||||
int hour = current.get(Calendar.HOUR_OF_DAY);
|
||||
int day = current.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
|
||||
|
@ -89,11 +87,10 @@ public class JobSchedulerTest {
|
|||
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 = 2000;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
|
@ -118,11 +115,10 @@ public class JobSchedulerTest {
|
|||
tearDown();
|
||||
startStore(directory);
|
||||
scheduler.addListener(new JobListener() {
|
||||
|
||||
@Override
|
||||
public void scheduledJob(String id, ByteSequence job) {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
assertTrue(latch.getCount() == COUNT);
|
||||
latch.await(3000, TimeUnit.SECONDS);
|
||||
|
@ -137,12 +133,20 @@ public class JobSchedulerTest {
|
|||
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);
|
||||
}
|
||||
|
@ -152,6 +156,7 @@ public class JobSchedulerTest {
|
|||
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);
|
||||
|
@ -172,16 +177,17 @@ public class JobSchedulerTest {
|
|||
final int COUNT = 10;
|
||||
final String ID = "id:";
|
||||
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, 10 + i, -1);
|
||||
}
|
||||
|
||||
List<Job> list = scheduler.getAllJobs();
|
||||
|
||||
assertEquals(list.size(), COUNT);
|
||||
int count = 0;
|
||||
for (Job job : list) {
|
||||
|
||||
assertEquals(job.getJobId(), ID + count);
|
||||
count++;
|
||||
}
|
||||
|
@ -195,10 +201,9 @@ public class JobSchedulerTest {
|
|||
|
||||
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);
|
||||
|
@ -206,7 +211,6 @@ public class JobSchedulerTest {
|
|||
assertEquals(COUNT, list.size());
|
||||
int count = 0;
|
||||
for (Job job : list) {
|
||||
|
||||
assertEquals(job.getJobId(), ID + count);
|
||||
count++;
|
||||
}
|
||||
|
@ -220,9 +224,7 @@ public class JobSchedulerTest {
|
|||
|
||||
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);
|
||||
|
@ -251,5 +253,4 @@ public class JobSchedulerTest {
|
|||
public void tearDown() throws Exception {
|
||||
store.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue