|
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
|
/**
|
|
@@ -25,12 +26,12 @@ public class DynamicScheduleTests extends SimpleWebApplicationTests {
|
|
|
private ScheduleJobService scheduleJobService;
|
|
|
|
|
|
|
|
|
- public static final AtomicLong counter=new AtomicLong();
|
|
|
+ public static final CountDownLatch counter=new CountDownLatch(1);
|
|
|
+ public static final AtomicLong value=new AtomicLong();
|
|
|
private String id;
|
|
|
|
|
|
@Before
|
|
|
public void initJob() throws InterruptedException {
|
|
|
- Thread.sleep(5000);
|
|
|
id = scheduleJobService.insert(createJob());
|
|
|
scheduleJobService.enable(id);
|
|
|
}
|
|
@@ -41,7 +42,8 @@ public class DynamicScheduleTests extends SimpleWebApplicationTests {
|
|
|
entity.setType("test");
|
|
|
entity.setLanguage("javascript");
|
|
|
entity.setScript("" +
|
|
|
- "org.hswebframework.web.schedule.test.DynamicScheduleTests.counter.incrementAndGet()\n" +
|
|
|
+ "org.hswebframework.web.schedule.test.DynamicScheduleTests.value.incrementAndGet();\n" +
|
|
|
+ "org.hswebframework.web.schedule.test.DynamicScheduleTests.counter.countDown();\n" +
|
|
|
"java.lang.System.out.println('job running...')");
|
|
|
entity.setQuartzConfig("{\"type\":\"cron\",\"config\":\"0/1 * * * * ?\"}");
|
|
|
return entity;
|
|
@@ -49,7 +51,7 @@ public class DynamicScheduleTests extends SimpleWebApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
public void testCreateJob() throws InterruptedException {
|
|
|
- Thread.sleep(20000);
|
|
|
- Assert.assertTrue(counter.get()>0);
|
|
|
+ counter.await();
|
|
|
+ Assert.assertTrue(value.get()>0);
|
|
|
}
|
|
|
}
|