use of org.quartz.CronExpression in project openremote by openremote.
the class TimerProtocol method doLinkProtocolConfiguration.
@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
AttributeRef protocolRef = protocolConfiguration.getReferenceOrThrow();
// Verify that this is a valid Timer Configuration
if (!isValidTimerConfiguration(protocolConfiguration)) {
LOG.warning("Timer Configuration is not valid so it will be ignored: " + protocolRef);
updateStatus(protocolRef, ConnectionStatus.ERROR);
return;
}
// Validate the cron expression
CronExpressionParser expressionParser = getCronExpression(protocolConfiguration).map(CronExpressionParser::new).orElse(null);
if (expressionParser == null || !expressionParser.isValid()) {
LOG.warning("Timer cron expression is missing or invalid");
updateStatus(protocolRef, ConnectionStatus.ERROR);
return;
}
cronExpressionMap.put(protocolRef, expressionParser);
if (protocolConfiguration.isEnabled()) {
updateStatus(protocolRef, ConnectionStatus.CONNECTED);
CronExpression cronExpression = createCronExpression(expressionParser.buildCronExpression());
if (cronExpression != null) {
getCronScheduler().addOrReplaceJob(getTimerId(protocolRef), cronExpression, () -> doTriggerAction(protocolConfiguration));
} else {
updateStatus(protocolRef, ConnectionStatus.DISABLED);
}
}
}
use of org.quartz.CronExpression in project OpenOLAT by OpenOLAT.
the class ReminderModuleTest method testCronJob_everyHeightHours.
@Test
public void testCronJob_everyHeightHours() throws ParseException {
reminderModule.setScheduler("8", "6:30");
sleep(1000);
String cron = reminderModule.getCronExpression();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 5);
CronExpression cronExpression = new CronExpression(cron);
Date d1 = cronExpression.getNextValidTimeAfter(cal.getTime());
Calendar triggerCal = Calendar.getInstance();
triggerCal.setTime(d1);
Assert.assertEquals(6, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
Date d2 = cronExpression.getNextValidTimeAfter(d1);
triggerCal.setTime(d2);
Assert.assertEquals(14, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
Date d3 = cronExpression.getNextValidTimeAfter(d2);
triggerCal.setTime(d3);
Assert.assertEquals(22, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
}
use of org.quartz.CronExpression in project kylo by Teradata.
the class CronExpressionTest method testTimerToCron.
@Test
public void testTimerToCron() {
String timer = "30 hours";
try {
CronExpression expression = CronExpressionUtil.timerToCronExpression(timer);
String cron = expression.getCronExpression();
Assert.assertNotNull(cron);
} catch (ParseException e) {
e.printStackTrace();
}
}
use of org.quartz.CronExpression in project kylo by Teradata.
the class FeedOnTimeArrivalMetricAssessorTest method testNoDataButStillBeforeLateTime.
@Test
public /**
* test use case where the date window is still valid, but still no data has been found for the Feed.
* This will return no Assessment result as it still could process data
*/
void testNoDataButStillBeforeLateTime() throws ParseException {
PowerMockito.mockStatic(DateTime.class);
PowerMockito.mockStatic(CronExpressionUtil.class);
DateTime now = new DateTime().minusHours(2);
// Some Cron Expression .. Mockito will overwrite
CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
// set the current time to a known time
BDDMockito.given(DateTime.now()).willReturn(now);
// set the previous fire date to a known time in the past,but within the window
DateTime previousFireTime = new DateTime(now).minusHours(3);
BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
// window is = (now - 3) - (now -3) + lateTime)
// Some Feed End Time to a time not within this window
DateTime lastFeedTime = new DateTime().minusWeeks(2);
when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
this.assessor.assess(metric, this.builder);
// assert values
DateTime lateTime = previousFireTime.plusHours(lateTimeGracePeriod);
Assert.assertTrue(now.isBefore(lateTime) && !(lastFeedTime.isAfter(previousFireTime) && lastFeedTime.isBefore(lateTime)));
verify(this.builder);
}
use of org.quartz.CronExpression in project kylo by Teradata.
the class FeedOnTimeArrivalMetricAssessorTest method setUp.
@Before
public void setUp() throws Exception {
initMocks(this);
when(this.builder.message(any(String.class))).thenReturn(this.builder);
when(this.builder.metric(any(Metric.class))).thenReturn(this.builder);
when(this.builder.result(any(AssessmentResult.class))).thenReturn(this.builder);
this.assessor.setMetadataAccess(this.metadataAccess);
// Noon every day
CronExpression cron = new CronExpression("0 0 12 1/1 * ? *");
this.lateTime = new DateTime(CronExpressionUtil.getPreviousFireTime(cron)).plusHours(4);
this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
}
Aggregations