AgentConsumer extends Stoppable { synchronized public Map<Long, CallableJob> getFailedQueries(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(); if (isJobFailed(value)) { toRet.put(key, value); } } return toRet; } AgentConsumer(JobDao dao, Reporting reporter,
      String hostname, MailInfo mailInfo, Session session,
      List<SupportedDriver> drivers, int numOfConcurrentJobs,
      int numOfConcurrentReruns, int maxReruns, long waitBeforeRetrySeconds,
      int minAttemptsForNotification); void writeReportToLocal(String reportRootPath); String getReportRootPath(); void init(); static void cleanupPreviouslyRunningJobs(
      JobDao dao, Map<Long, CallableJob> jobRuns); void doRun(); CallableJob assembleCallableJob(PlannedJob plannedJob,
      int attemptNumber); void submitJob(final CallableJob cj); @Override void run(); @Override void close(); static void setShouldSendErrorReports(boolean shouldSend); @CoverageIgnore static void sendErrorReport(JobSpec jobSpec, String query,
                                     Exception ex, Long myId, String hostname,
                                     MailInfo mailInfo, Session session,
                                     int attemptNumber); synchronized Map<Long, CallableJob> getFinishedJobs(int limit); static boolean isJobFailed(CallableJob cj); synchronized Map<Long, CallableJob> getFailedQueries(int limit); synchronized Map<Long, CallableJob> getSuccesfulQueries(int limit); synchronized CallableJob getLatestMatching(PlannedJob pj, int limit); static Logger LOG; public int SLEEP_FOR; final ThreadPoolExecutor executor; static int maxReruns; final static int LIMIT_JOB_RUNS; final static int START_ATTEMPT_NUM; }
@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()); }