use of org.apache.oozie.util.Pair in project oozie by apache.
the class TestSLACalculatorMemory method testDisablingAlertsEvents.
@SuppressWarnings("serial")
public void testDisablingAlertsEvents() throws Exception {
SLAService slaService = Services.get().get(SLAService.class);
EventHandlerService ehs = Services.get().get(EventHandlerService.class);
SLACalculator slaCalculator = slaService.getSLACalculator();
// create dummy sla records and coord action records
String id1 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 1);
String id2 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 2);
SLACalcStatus slaCalcObj1 = slaCalculator.get(id1);
assertFalse(slaCalcObj1.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
SLACalcStatus slaCalcObj2 = slaCalculator.get(id2);
assertFalse(slaCalcObj2.getSLAConfigMap().containsKey(OozieClient.SLA_DISABLE_ALERT));
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().size() > 0);
// check that SLACalculator sends no event
ehs.getEventQueue().clear();
SLASummaryBean persistentSla = new SLASummaryBean(slaCalcObj1);
// reset eventProcessed for the sla calc objects
persistentSla.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
persistentSla = new SLASummaryBean(slaCalcObj2);
persistentSla.setEventProcessed(0);
SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_EVENTPROCESSED, persistentSla);
// CASE I : list of sla ids, no new params
slaService.enableChildJobAlert(Arrays.asList(id1, id2));
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().isEmpty());
// CASE II : ALL
_setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 3);
_setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 4);
slaCalculator.enableChildJobAlert(Arrays.asList("00020-1234567-wrkf-C"));
slaCalculator.updateAllSlaStatus();
assertFalse(ehs.getEventQueue().isEmpty());
// CASE III : resume w/ new params
final String id5 = _setupSlaMap(slaCalculator, "00020-1234567-wrkf-C", 5);
Date now = new Date();
now.setTime(now.getTime() - 10 * 60 * 1000);
final String newParams = RestConstants.SLA_NOMINAL_TIME + "=" + DateUtils.formatDateOozieTZ(now) + ";" + RestConstants.SLA_SHOULD_END + "=5";
slaCalculator.changeDefinition(new ArrayList<Pair<String, Map<String, String>>>() {
{
add(new Pair<String, Map<String, String>>(id5, JobUtils.parseChangeValue(newParams)));
}
});
slaCalculator.updateAllSlaStatus();
assertTrue(ehs.getEventQueue().size() > 0);
}
Aggregations