@@ -0,0 +1,3078 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.addthis.hydra.job;%0A%0Aimport java.util.Arrays;%0A%0Aimport com.addthis.hydra.job.spawn.JobAlert;%0A%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class JobAlertTest %7B%0A%0A    @Test%0A    public void basicTriggerTest() throws Exception %7B%0A        long now = System.currentTimeMillis();%0A%0A        Job idleJob = createJobWithState(JobState.IDLE);%0A        Job errorJob = createJobWithState(JobState.ERROR);%0A        Job runningJob = createJobWithState(JobState.RUNNING);%0A%0A        JobAlert errorAlert = new JobAlert(%22errorAlert%22, 0, -1, %22noone%22, null);%0A        assertTrue(%22Error alert should trigger with at least one error job%22, errorAlert.checkAlertForJobs(Arrays.asList(idleJob, errorJob)));%0A        errorAlert.clear();%0A        assertTrue(%22Error alert should not trigger with only idle job%22, !errorAlert.checkAlertForJobs(Arrays.asList(idleJob)));%0A%0A        JobAlert completeAlert = new JobAlert(%22completeAlert%22, 1, -1, %22noone%22, null);%0A        assertTrue(%22Complete alert should not trigger with running job%22, !completeAlert.checkAlertForJobs(Arrays.asList(runningJob)));%0A        runningJob.setState(JobState.IDLE);%0A        assertTrue(%22Complete alert should trigger on job completion%22, completeAlert.checkAlertForJobs(Arrays.asList(runningJob)));%0A        runningJob.setState(JobState.RUNNING);%0A%0A        JobAlert runtimeAlert = new JobAlert(%22runtimeAlert%22, 2, 60, %22noone%22, null);%0A        assertTrue(%22Runtime alert should not trigger with idle job%22, !runtimeAlert.checkAlertForJobs(Arrays.asList(idleJob)));%0A        runningJob.setSubmitTime(now - 1000);%0A        assertTrue(%22Runtime alert should not trigger with recently-submitted job%22, !runtimeAlert.checkAlertForJobs(Arrays.asList(runningJob)));%0A        runningJob.setSubmitTime(now - 180 * 60 * 1000);%0A        assertTrue(%22Runtime alert should trigger with long-running job%22, runtimeAlert.checkAlertForJobs(Arrays.asList(runningJob)));%0A%0A        JobAlert rekickAlert = new JobAlert(%22rekickAlert%22, 3, 60, %22noone%22, null);%0A        idleJob.setEndTime(now - 10 * 60 * 1000);%0A        assertTrue(%22Rekick alert should not fire after short time period%22, !rekickAlert.checkAlertForJobs(Arrays.asList(idleJob)));%0A        idleJob.setEndTime(now - 300 * 60 * 1000);%0A        assertTrue(%22Rekick alert should fire after long time period%22, rekickAlert.checkAlertForJobs(Arrays.asList(idleJob)));%0A%0A    %7D%0A%0A    private Job createJobWithState(JobState jobState) throws Exception %7B%0A        Job job = new Job();%0A        job.setState(jobState);%0A        return job;%0A    %7D%0A%7D%0A

Add unit tests for basic alert functionality.