From af9a1f0d0f5d00897e9ab42499245d138582a4e1 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Thu, 24 Jan 2013 20:25:47 +0000 Subject: [PATCH] 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 --- .../broker/scheduler/JobSchedulerTest.java | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JobSchedulerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JobSchedulerTest.java index f91f49f4e2..79000d8e6b 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JobSchedulerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JobSchedulerTest.java @@ -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(); } @@ -53,7 +52,7 @@ public class JobSchedulerTest { scheduler.schedule("id" + i, new ByteSequence(test.getBytes()), 1000); } latch.await(5, TimeUnit.SECONDS); - assertEquals(0,latch.getCount()); + assertEquals(0, latch.getCount()); } @Test @@ -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++) { @@ -109,7 +106,7 @@ public class JobSchedulerTest { public void testAddStopThenDeliver() throws Exception { final int COUNT = 10; final CountDownLatch latch = new CountDownLatch(COUNT); - long time = 2000; + long time = 2000; for (int i = 0; i < COUNT; i++) { String test = new String("test" + i); scheduler.schedule("id" + i, new ByteSequence(test.getBytes()), "", time, 1000, -1); @@ -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); @@ -171,17 +176,18 @@ public class JobSchedulerTest { public void testgetAllJobs() throws Exception { final int COUNT = 10; final String ID = "id:"; - long time = 20000; + 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 list = scheduler.getAllJobs(); assertEquals(list.size(), COUNT); int count = 0; for (Job job : list) { - assertEquals(job.getJobId(), ID + count); count++; } @@ -195,18 +201,16 @@ 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); - + scheduler.schedule(ID + i, new ByteSequence(str.getBytes()), "", start + (i * 1000), 10000 + i, 0); } + start = System.currentTimeMillis(); - long finish = start + 12000+ (COUNT * 1000); + long finish = start + 12000 + (COUNT * 1000); List list = scheduler.getAllJobs(start, finish); - assertEquals( COUNT,list.size()); + assertEquals(COUNT, list.size()); int count = 0; for (Job job : list) { - assertEquals(job.getJobId(), ID + count); count++; } @@ -220,12 +224,10 @@ 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); - + scheduler.schedule(ID + i, new ByteSequence(str.getBytes()), "", start + (i * 1000), 10000 + i, 0); } start = System.currentTimeMillis(); - long finish = start + 12000+ (COUNT * 1000); + long finish = start + 12000 + (COUNT * 1000); scheduler.removeAllJobs(start, finish); assertTrue(scheduler.getAllJobs().isEmpty()); @@ -251,5 +253,4 @@ public class JobSchedulerTest { public void tearDown() throws Exception { store.stop(); } - }