synchronized public Map<Long, CallableJob> getSuccesfulQueries(int limit) { Map<Long, CallableJob> toRet = new TreeMap<>(); Map<Long, CallableJob> runs = dao.getJobRuns(null, limit); for (Entry<Long, CallableJob> entry : runs.entrySet()) { Long key = entry.getKey(); CallableJob value = entry.getValue(); boolean isRunning = value.isRunning(); boolean isDone = value.isDone(); boolean isSuccess = value.isSuccess(); if (!isRunning && isDone && isSuccess) { toRet.put(key, value); } } return toRet; }
public static boolean isJobFailed(CallableJob cj) { boolean isRunning = cj.isRunning(); boolean isDone = cj.isDone(); boolean isSuccess = cj.isSuccess(); return !isRunning && isDone && !isSuccess; }
@Test(timeout=2000) public void testScriptReplace() { JobSpec aJob = getTestScript("Doug Lea", dao); String strFormat = "YYYYMMdd"; DateTimeFormatter format = QueryReplaceUtil.makeDateTimeFormat(strFormat); DateTime now = Utils.getCurrentTime(); String command = String.format("echo '${%s-1D} ${%s}' >&2; exit 1;", strFormat, strFormat); String error = String.format("%s %s", format.print(now.minusDays(1)), format.print(now)); aJob.setCode(command); dao.createJob(aJob); runRunnable(agentDriver); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals(false, actual.isSuccess()); assertEquals(true, actual.isFailed()); String expected = CallableScript.genErrorMessage(aJob, error+"\n"); assertEquals(expected, actual.getExceptionMessage().get()); }
@Test public void testScriptRun() { JobSpec aJob = getTestScript("Chenoweth", dao); aJob.setCode("echo 'hi'; echo 'bye';"); dao.createJob(aJob); runRunnable(agentDriver); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals("", actual.getExceptionMessage().get()); assertEquals(true, actual.isSuccess()); }
@Test(timeout=2000) public void testScriptRunFail() { JobSpec aJob = getTestScript("Chenoweth", dao); String error = "error"; aJob.setCode(String.format("echo '%s' >&2; exit 1;", error)); dao.createJob(aJob); runRunnable(agentDriver); runRunnable(consumer); waitUntilJobsFinished(consumer, 1); CallableJob actual = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).get(1L); assertEquals(false, actual.isSuccess()); assertEquals(true, actual.isFailed()); String expected = CallableScript.genErrorMessage(aJob, error+"\n"); assertEquals(expected, actual.getExceptionMessage().get()); }
@Test public void testGetFailedQueries() { JobSpec aJob = TestAgent.getTestJob("David Foster Wallace", dao); aJob.setCode("not a valid query..."); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableJob cj = new CallableQuery(pj, dao, reporting, "example.com", mailInfo, null, drivers.get(0), null, 1); consumer.submitJob(cj); TestAgent.waitForFail(consumer, 1); boolean isSuccess = cj.isSuccess(); assertEquals(false, isSuccess); assertEquals(true, cj.isDone()); Map<Long, CallableJob> expected = new HashMap<>(); expected.put(cj.getJobId(), cj); assertEquals(expected, consumer.getFailedQueries(limit)); assertEquals(1, consumer.getFinishedJobs(limit).size()); }
@Test public void testJobNoResubmit() throws BackendException { consumer.SLEEP_FOR = 1; JobSpec aJob = TestAgent.getTestJob("Hannah Arendt", dao); aJob.setCode("not a valid query..."); aJob.setShouldRerun(false); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableJob cj = new CallableQuery(pj, dao, reporting, "example.com", mailInfo, null, drivers.get(0), null, 1); consumer.submitJob(cj); // let the job run and fail TestAgent.waitUntilJobsFinished(consumer, 1); boolean isSuccess = cj.isSuccess(); assertEquals(false, isSuccess); Map<Long, CallableJob> expected = new HashMap<>(); expected.put(cj.getJobId(), cj); assertEquals(expected, consumer.getFailedQueries(limit)); // See if the job retries TestAgent.runRunnable(consumer); TestAgentConsumer.doSleep(); assertEquals(0, dao.getRunningJobs().size()); Map<Long, CallableJob> jobRuns = dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS); assertEquals("jobRuns: " + jobRuns, 1, jobRuns.values().size()); assertEquals(1, consumer.getFinishedJobs(limit).size()); assertEquals(0, consumer.getSuccesfulQueries(limit).size()); }
boolean isSuccess = cj.isSuccess(); assertEquals(false, isSuccess); Map<Long, CallableJob> expected = new HashMap<>();
@Test public void testJobResubmitSuccessUpdateQuery() throws BackendException { JobSpec aJob = TestAgent.getTestJob("Robert Frank", dao); String tableName = "table_dne_yet"; aJob.setCode(String.format("select * from %s", tableName)); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableJob cj = new CallableQuery(pj, dao, reporting, "example.com", mailInfo, null, drivers.get(0), null, 1); consumer.submitJob(cj); TestAgent.waitForFail(consumer, 1); boolean isSuccess = cj.isSuccess(); assertEquals(false, isSuccess); Map<Long, CallableJob> expected = new HashMap<>(); expected.put(cj.getJobId(), cj); assertEquals(expected, consumer.getFailedQueries(limit)); Long nextId = cj.getJobId()+1; aJob = dao.getJob(aJob.getId()); aJob.setCode("show tables;"); dao.updateJob(aJob); TestAgent.runRunnable(consumer); doSleep(); assertEquals(0, dao.getRunningJobs().size()); assertEquals(2, consumer.getFinishedJobs(limit).size()); assertEquals(1, consumer.getSuccesfulQueries(limit).size()); assertEquals(0, consumer.getFinishedJobs(limit).get(nextId).getStatus().get()); } @Test