TriggerManager extends EventHandler implements
    TriggerManagerAdapter { public void insertTrigger(final Trigger t) throws TriggerManagerException { logger.info("Inserting trigger " + t + " in TriggerManager"); synchronized (this.syncObj) { try { this.triggerLoader.addTrigger(t); } catch (final TriggerLoaderException e) { throw new TriggerManagerException(e); } this.runnerThread.addTrigger(t); triggerIdMap.put(t.getTriggerId(), t); } } @Inject  TriggerManager(final Props props, final TriggerLoader triggerLoader,
      final ExecutorManagerAdapter executorManagerAdapter); @Override void start(); void insertTrigger(final Trigger t); void removeTrigger(final int id); void updateTrigger(final Trigger t); void removeTrigger(final Trigger t); List<Trigger> getTriggers(); Map<String, Class<? extends ConditionChecker>> getSupportedCheckers(); Trigger getTrigger(final int triggerId); void expireTrigger(final int triggerId); @Override List<Trigger> getTriggers(final String triggerSource); @Override List<Trigger> getTriggerUpdates(final String triggerSource,
      final long lastUpdateTime); @Override List<Trigger> getAllTriggerUpdates(final long lastUpdateTime); @Override void insertTrigger(final Trigger t, final String user); @Override void removeTrigger(final int id, final String user); @Override void updateTrigger(final Trigger t, final String user); @Override void shutdown(); @Override TriggerJMX getJMX(); @Override void registerCheckerType(final String name,
      final Class<? extends ConditionChecker> checker); @Override void registerActionType(final String name,
      final Class<? extends TriggerAction> action); static final long DEFAULT_SCANNER_INTERVAL_MS; }
@Test public void neverExpireTriggerTest() throws TriggerManagerException { final Trigger t1 = createNeverExpireTrigger("triggerLoader", 10); this.triggerManager.insertTrigger(t1); t1.setResetOnTrigger(false); final ThresholdChecker triggerChecker = (ThresholdChecker) t1.getTriggerCondition().getCheckers().values() .toArray()[0]; final BasicTimeChecker expireChecker = (BasicTimeChecker) t1.getExpireCondition().getCheckers().values() .toArray()[0]; ThresholdChecker.setVal(15); sleep(300); sleep(300); assertTrue(triggerChecker.isCheckerMet() == true); assertTrue(expireChecker.eval() == false); ThresholdChecker.setVal(25); sleep(300); assertTrue(triggerChecker.isCheckerMet() == true); assertTrue(expireChecker.eval() == false); }
@Test public void timeCheckerAndExpireTriggerTest() throws TriggerManagerException { final long curr = System.currentTimeMillis(); final Trigger t1 = createPeriodAndEndCheckerTrigger(curr); this.triggerManager.insertTrigger(t1); t1.setResetOnTrigger(true); final BasicTimeChecker expireChecker = (BasicTimeChecker) t1.getExpireCondition().getCheckers().values() .toArray()[0]; sleep(1000); assertTrue(expireChecker.eval() == false); assertTrue(t1.getStatus() == TriggerStatus.READY); sleep(1000); sleep(1000); sleep(1000); assertTrue(expireChecker.eval() == true); assertTrue(t1.getStatus() == TriggerStatus.PAUSED); sleep(1000); assertTrue(expireChecker.eval() == true); assertTrue(t1.getStatus() == TriggerStatus.PAUSED); }