Commits

Zemian Deng  committed 44b0aa5

Added CrontabService.load() and unit test.

  • Participants
  • Parent commits c69e636

Comments (0)

Files changed (2)

File timemachine-scheduler/src/main/java/timemachine/scheduler/userservice/CrontabService.java

 	public void onScheduler(Scheduler scheduler) {
 		this.scheduler = scheduler;
 	}
+	
+	/** Allow user to use this service programmatically as static utility. */
+	public static void load(Scheduler scheduler, String configUrl) {
+		Props props = new Props(configUrl);
+		CrontabService service = new CrontabService();
+		service.onScheduler(scheduler);
+		service.onConfigProps(props);
+		service.init();
+	}
 }

File timemachine-scheduler/src/test/java/integration/timemachine/scheduler/userservice/CrontabServiceTest.java

 import timemachine.scheduler.SchedulerFactory;
 import timemachine.scheduler.support.ProcessUtils;
 import timemachine.scheduler.support.Utils;
+import timemachine.scheduler.userservice.CrontabService;
 import unit.timemachine.scheduler.TestUtils;
 
 /**
 			scheduler.destroy();
 		}
 	}
+	
+	@Test
+	public void testCrontabOsCommandsWithLoad() throws Exception {
+		String config = "classpath:///integration/timemachine/scheduler/userservice/CrontabServiceTest.properties";
+		if (ProcessUtils.getOsType() == ProcessUtils.EOSType.WINDOWS)
+			config = "classpath:///integration/timemachine/scheduler/userservice/CrontabServiceTest-windows.properties";
+		Scheduler scheduler = new SchedulerFactory().createScheduler();
+		try {
+			logger.info("About to start a 7 secs tests.");
+			scheduler.init();
+			CrontabService.load(scheduler, config);
+			scheduler.start();
+			Utils.sleep(7000L);
+			
+			String result = TestUtils.readText(file);
+			String result2 = TestUtils.readText(file2);
+			
+			assertThat(result, containsString("A A A "));
+			assertThat(result2, containsString("B B "));
+		} finally {
+			scheduler.destroy();
+		}
+	}
 }