*/
public void testCoordActionsInDateRange() {
try {
int actionNum = 1;
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
CoordinatorActionBean actionId1 = addRecordToCoordActionTable(job.getId(), actionNum,
CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
Date nominalTime = actionId1.getNominalTime();
long nominalTimeMilliseconds = nominalTime.getTime();
long noOfMillisecondsinOneHour = 3600000;
String date1 = DateUtils.formatDateUTC(new Date(nominalTimeMilliseconds - (noOfMillisecondsinOneHour / 2)));
String date2 = DateUtils.formatDateUTC(new Date(nominalTimeMilliseconds + noOfMillisecondsinOneHour));
// Test a bad date format.
try {
String badDate = "bad" + date1;
CoordActionsInDateRange.getCoordActionIdsFromDates(
job.getId().toString(),
badDate + "::" + date2);
fail("Accepted badly formatted date: " + badDate);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Test a bad scope.
try {
String badScope = date1 + "0xbad5c09e" + date2;
CoordActionsInDateRange.getCoordActionIdsFromDates(
job.getId().toString(),
badScope);
fail("Accepted bad range scope: " + badScope);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Test inverted start and end dates.
try {
CoordActionsInDateRange.getCoordActionIdsFromDates(
job.getId().toString(),
date2 + "::" + date1);
fail("Accepted inverted dates: [Start::End] = " + date2 + "::" + date1);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Testing for the number of coordinator actions in a date range that spans from half an hour prior to the nominal time to 1 hour after the nominal time
int noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
assertEquals(1, noOfActions);
// Testing for the number of coordinator actions in a date range that spans from half an hour after the nominal time to 1 hour after the nominal time
date1 = DateUtils.formatDateUTC(new Date(nominalTimeMilliseconds + (noOfMillisecondsinOneHour / 2)));
noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
assertEquals(0, noOfActions);
}
catch (Exception e) {
e.printStackTrace();
fail();