Commits

Zemian Deng committed e80cd3e

Added static JobLoaderService.load method.

Comments (0)

Files changed (2)

timemachine-scheduler/src/main/java/timemachine/scheduler/userservice/JobLoaderService.java

 	public void onScheduler(Scheduler scheduler) {
 		this.scheduler = scheduler;
 	}
+	
+	/** Allow user any load jobs in configUrl into a scheduler on demand. */
+	public static void load(Scheduler scheduler, String configUrl) {
+		Props props = new Props(configUrl);
+		JobLoaderService loader = new JobLoaderService();
+		loader.onScheduler(scheduler);
+		loader.onConfigProps(props);
+		loader.init();
+	}
 }

timemachine-scheduler/src/test/java/integration/timemachine/scheduler/userservice/JobLoaderServiceTest.java

 import timemachine.scheduler.JobTask;
 import timemachine.scheduler.Scheduler;
 import timemachine.scheduler.SchedulerFactory;
+import timemachine.scheduler.userservice.JobLoaderService;
 
 /**
  * @author Zemian Deng
 		}
 	}
 	
+	@Test
+	public void testJobLoaderServiceWithStaticLoad() throws Exception {
+		String config = "classpath:///integration/timemachine/scheduler/userservice/JobLoaderServiceTest.properties";
+		Scheduler scheduler = new SchedulerFactory().createScheduler();
+		try {
+			logger.info("About to run 5 seconds test.");
+			scheduler.init();
+			JobLoaderService.load(scheduler, config);
+			scheduler.startAndWait(5000L);
+			scheduler.stop();
+			assertThat(scheduler.getJobDefCount(), is(3L));
+			assertThat(MyJob1.result, containsString("AA"));
+			assertThat(MyJob2.result, containsString("BBBB"));
+			assertThat(MyJob3.result, containsString(""));
+		} finally {
+			scheduler.destroy();
+		}
+	}
+	
 	public static class MyJob1 implements JobTask {
 		volatile static String result = "";
 		@Override