agave-jobs/jobs-core/src/test/java/org/iplantc/service/jobs/queue/actions/MonitoringActionTest.java
/**
     * Generic submission test used by all the methods testing job submission is some
     * form or fashion.
     * 
     * @param job
     * @param message
     * @param shouldThrowException
     */
Generic submission test used by all the methods testing job submission is some
form or fashion.


Generic submission test used by all the methods testing job submission is some form or fashion .
protected Job genericRemoteMonitoringTestCase(Job job, JobStatusType expectedStatus, String message, boolean shouldThrowException) 
    {
        MonitoringAction action = new MonitoringAction(job);
        try
        {
            JobDao.persist(job, false);
            long lastUpdated = job.getLastUpdated().getTime();
            int statusChecks = job.getStatusChecks();
            action.setJob(job);
            action.run();
            job = action.getJob();
            Assert.assertEquals(job.getStatus(), expectedStatus,
                    "Job status did not match " + expectedStatus + " after submission");
            Assert.assertNotNull(action.getJob().getLocalJobId(),
                    "Local job id was not obtained during submission");
            Assert.assertFalse(job.getStatusChecks() == statusChecks,
                    "Status check count was not updated.");
            Assert.assertTrue(job.getLastUpdated().getTime() > lastUpdated,
                    "Timestamp was not updated.");
            if (expectedStatus == JobStatusType.RUNNING) 
            {
                Assert.assertNotNull(job.getStartTime(),
                    "Job submit time should be set during job submission");
                Assert.assertNull(job.getEndTime(),
                        "Job end time should not be set on queued jobs");
            }
            else if (expectedStatus == JobStatusType.QUEUED) 
            {
                Assert.assertNull(job.getStartTime(),
                        "Job submit time was should not be set for a queued job");
                Assert.assertNull(job.getEndTime(),
                        "Job end time was should not be set for a queued job");
            }
            else if (expectedStatus == JobStatusType.FAILED) 
            {
                Assert.assertNotNull(job.getStartTime(),
                        "Job submit time was not updated during job submission");
                Assert.assertNotNull(job.getEndTime(),
                        "Job end time was not set on failed job");
            }
            else if (expectedStatus == JobStatusType.CLEANING_UP) 
            {
                Assert.assertNotNull(job.getEndTime(),
                        "Job end time was not set during by monitoring process");
                Assert.assertNotNull(job.getStartTime(),
                        "Job start time was not set during job submission");
            }
            else 
            {
                Assert.assertNull(job.getLocalJobId(),
                        "Local job id should be null if submission fails");
                Assert.assertNull(job.getSubmitTime(),
                    "Job submit time should not be updated if the job did not submit.");
            }
        }
        catch (Exception e)
        {
            if (shouldThrowException) {
                Assert.assertEquals(action.getJob().getStatus(), expectedStatus, message);
            } else {
                Assert.fail("Unexpected exception thrown checking remote job status", e);
            }
        }
        return job;
    }
protected Job genericRemoteMonitoringTestCase ( Job job , JobStatusType expectedStatus , String message , boolean shouldThrowException ) { MonitoringAction action = new MonitoringAction ( job ) ; try { JobDao . persist ( job , false ) ; long lastUpdated = job . getLastUpdated ( ) . getTime ( ) ; int statusChecks = job . getStatusChecks ( ) ; action . setJob ( job ) ; action . run ( ) ; job = action . getJob ( ) ; Assert . assertEquals ( job . getStatus ( ) , expectedStatus , "Job status did not match " + expectedStatus + " after submission" ) ; Assert . assertNotNull ( action . getJob ( ) . getLocalJobId ( ) , "Local job id was not obtained during submission" ) ; Assert . assertFalse ( job . getStatusChecks ( ) == statusChecks , "Status check count was not updated." ) ; Assert . assertTrue ( job . getLastUpdated ( ) . getTime ( ) > lastUpdated , "Timestamp was not updated." ) ; if ( expectedStatus == JobStatusType . RUNNING ) { Assert . assertNotNull ( job . getStartTime ( ) , "Job submit time should be set during job submission" ) ; Assert . assertNull ( job . getEndTime ( ) , "Job end time should not be set on queued jobs" ) ; } else if ( expectedStatus == JobStatusType . QUEUED ) { Assert . assertNull ( job . getStartTime ( ) , "Job submit time was should not be set for a queued job" ) ; Assert . assertNull ( job . getEndTime ( ) , "Job end time was should not be set for a queued job" ) ; } else if ( expectedStatus == JobStatusType . FAILED ) { Assert . assertNotNull ( job . getStartTime ( ) , "Job submit time was not updated during job submission" ) ; Assert . assertNotNull ( job . getEndTime ( ) , "Job end time was not set on failed job" ) ; } else if ( expectedStatus == JobStatusType . CLEANING_UP ) { Assert . assertNotNull ( job . getEndTime ( ) , "Job end time was not set during by monitoring process" ) ; Assert . assertNotNull ( job . getStartTime ( ) , "Job start time was not set during job submission" ) ; } else { Assert . assertNull ( job . getLocalJobId ( ) , "Local job id should be null if submission fails" ) ; Assert . assertNull ( job . getSubmitTime ( ) , "Job submit time should not be updated if the job did not submit." ) ; } } catch ( Exception e ) { if ( shouldThrowException ) { Assert . assertEquals ( action . getJob ( ) . getStatus ( ) , expectedStatus , message ) ; } else { Assert . fail ( "Unexpected exception thrown checking remote job status" , e ) ; } } return job ; }
Generic submission test used by all the methods testing job submission is some
 form or fashion.
Generic submission test used by all the methods testing job submission is some form or fashion .