job.setResultQuery(rs.getString("resultQuery")); job.setResultTable(rs.getString("resultTable")); job.setCronString(rs.getString("cronString")); job.setDriver(rs.getString("driver")); job.setEnabled(rs.getBoolean("enabled"));
public static JobSpec getTestJob(String aName, JobDao dao) { JobSpec aJob = new JobSpec(); aJob.setName(aName); DateTime now = Utils.getCurrentTime(); aJob.setCronString(String.format("%d * * * *", now.getHourOfDay())); aJob.setDriver(H2TestUtil.H2_NAME); aJob.setCode("show tables;"); aJob.setResultTable("ARESULTTABLE"); aJob.setEnabled(true); aJob.setStatusEmail(Collections.singletonList("blah@example.com")); aJob.setType(JobType.Query); return aJob; }
@Test public void testBasicDependent() throws Exception { String jobName = "TE Lawrence"; JobSpec parent = getTestJob(jobName, dao); JobSpec child = getTestJob(jobName + " arabia", dao); child.setCronString(null); try { dao.createJob(parent); child.setParent(parent.getId()); long id = dao.createJob(child); } catch (Exception ex) { ex.printStackTrace(); } TestAgent.runRunnable(agentDriver); assertEquals(1, dao.getQueue(null).size()); runRunnable(consumer); Thread.sleep(100); // child job should have been queued assertEquals(1, dao.getQueue(null).size()); runRunnable(consumer); waitUntilJobsFinished(consumer, 2); assertEquals(2, consumer.getSuccesfulQueries(AgentConsumer.LIMIT_JOB_RUNS) .values().size()); } }
aJob.setCronString("0 0 1 * *"); boolean actual = AgentDriver.shouldJobRun(aJob, Utils.getCurrentTime().withDayOfMonth(1)); aJob.setCronString("0 0 * * 4"); boolean actual = AgentDriver.shouldJobRun(aJob, Utils.getCurrentTime()); aJob.setCronString("0 0 * * *"); boolean actual = AgentDriver.shouldJobRun(aJob, Utils.getCurrentTime()); aJob.setCronString("0 * * * *"); boolean actual = AgentDriver.shouldJobRun(aJob, Utils.getCurrentTime());