@Override public Void call() throws Exception { begin(); try { callInternal(); } catch (Exception ex) { handleException(ex); } finally { end(); } return null; }
@Override public void run() { while (isAlive) { doRun(); } }
@Test public void testCleanupPreviouslyRunningJobs() { JobSpec aJob = TestAgent.getTestJob("Mary Wollstonecraft", dao); long id = dao.createJob(aJob); PlannedJob pj = new PlannedJob(dao.getJob(id), Utils.getCurrentTime()); SleepyCallableQuery cj = new SleepyCallableQuery( pj, dao, reporting, "example.com", mailInfo, null, null, drivers.get(0), 1, 10000); consumer.submitJob(cj); doSleep(); assertEquals(0, consumer.getFailedQueries(limit).size()); assertEquals(1, dao.getRunningJobs().size()); AgentConsumer.cleanupPreviouslyRunningJobs(dao, dao.getRunningJobs()); assertEquals(0, dao.getRunningJobs().size()); assertEquals(1, consumer.getFailedQueries(limit).size()); }
@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 public void testReplacedReportQuery() { JobSpec aJob = TestAgent.getTestJob("Mark Rothko", dao); aJob.setResultQuery("select * from blah where dt=${YYYMMDDHH}"); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableQuery cq = new CallableQuery(pj, dao, null, "example.com", null, null, null, null, 1); String expected = "select * from blah where dt=1970010100"; Assert.assertEquals(expected, cq.getReplacedReportQuery()); }
public CallableScript(PlannedJob plannedJob, JobDao dao, Reporting reporting, long jobId, String hostname, MailInfo mailInfo, Session session, int attemptNumber) { this.plannedJob = plannedJob; this.dao = dao; this.reporting = reporting; this.jobId = jobId; this.mailInfo = mailInfo; this.session = session; this.attemptNumber = attemptNumber; setReplacedCode(); runner = new BashRunner(); runner.init(); }
private boolean areAllFuturesDone(AgentConsumer consumer){ boolean result = true; for (Entry<Long, CallableJob> i : dao.getJobRuns(null, AgentConsumer.LIMIT_JOB_RUNS).entrySet()){ if (!i.getValue().isDone()){ result = false; } } return result; }
public void run() { for (int i = 0 ; i < 1000; i++) { TestAgent.runRunnable(consumer); TestAgentConsumer.doSleep(); } } });
public static void waitUntilJobsFinished(AgentConsumer c, int count) { while (c.getFinishedJobs(AgentConsumer.LIMIT_JOB_RUNS).size() != count) { runRunnable(c); try { Thread.sleep(100); } catch (Exception ignore) { } } }
@After public void cleanup() throws Exception { consumer.close(); }
public String getError() { return stderr.getStream().toString(); }
@Override public void run() { while (isAlive) { try { doRun(); } catch (RuntimeException ex) { LOG.error("Exception when running consumer:", ex); } } }
public static void runRunnable(Stoppable stoppable) { stoppable.doRun(); }
@Override public void close() throws IOException { super.close(); if (dao != null) { dao.close(); } }
public static AgentDriver getMockedDriver(JobDao dao, Reporting reporting) { return spy(new AgentDriver(dao, reporting)); }
public static JobSpec getTestScript(String aName, JobDao dao) { JobSpec aJob = getTestJob(aName, dao); aJob.setType(JobType.Script); aJob.setCode("echo 'beep';"); aJob.setResultTable(null); return aJob; }
@After public void cleanup() throws Exception { consumer.close(); }
public String getOutput() { return stdout.getStream().toString(); }