com.elephantdrummer.trigger.test.JobTester Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of drummer Show documentation
Show all versions of drummer Show documentation
Elephant Drummer Java Job Scheduler
package com.elephantdrummer.trigger.test;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.elephantdrummer.annotation.TestJob;
import com.elephantdrummer.annotation.trigger.At;
import com.elephantdrummer.container.ContainerElement;
import com.elephantdrummer.parser.ParserDateMaskToDate;
import com.elephantdrummer.trigger.base.DrumTrigger;
/**
* Copyright 2018 Elephant Software Klaudiusz Wojtkowiak e-mail: [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class JobTester implements ContainerElement{
private Logger log=Logger.getLogger(JobTester.class.getSimpleName());
public void testTrigger(String testname,DrumTrigger trigger,TestJob testJobAnn){
if (testJobAnn==null) return;
log.info(testname);
log.info(""+trigger.getClass());
Date dateToTest=isJobDatePeriodFilled(testJobAnn.at())?ParserDateMaskToDate.applyToCurrentDate(testJobAnn.at()):new Date();
if (dateToTest.before(new Date())){
dateToTest=trigger.getNextRunTime(new Date());
}
testTriggerForDate(testname,trigger,testJobAnn.steps(),dateToTest);
}
public void testTriggerForDate(String testname,DrumTrigger trigger,int steps,Date date){
if (trigger==null){
log.log(Level.SEVERE, "trigger is null");
return;
}
if (steps<=0){
log.log(Level.SEVERE, "steps must be greater than 0");
return;
}
StringBuffer sb=new StringBuffer();
String endline=System.getProperty("line.separator");
sb.append(endline);
sb.append("*** TEST JOB: "+ testname+" FOR DATE: "+date +" and "+steps+" STEPS ***");
sb.append(endline);
for (int i=0;i0
||in.month()==0==false
||in.day()==0==false
||in.hour()>=0
||in.minute()>=0
||in.second()>=0;
return rv;
}
}