TriggerManager implements Closeable { void tick() { try (Scope ignored = tracer.spanBuilder("Styx.TriggerManager.tick") .setRecordEvents(true) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { tick0(); } } TriggerManager(TriggerListener triggerListener,
                 Time time,
                 Storage storage,
                 Stats stats); @Override void close();  }
@Test public void shouldNotUpdateNextNaturalTriggerIfTriggerExecutionFails() throws Exception { setupWithNextNaturalTrigger(true, parse("2016-10-01T00:00:00Z"), WORKFLOW_DAILY); doThrow(new RuntimeException("trigger execution failure!")) .when(triggerListener).event(any(), any(), any(), any()); triggerManager.tick(); verify(triggerListener).event(WORKFLOW_DAILY, NATURAL_TRIGGER, parse("2016-10-01T00:00:00Z"), TriggerParameters.zero()); verify(storage, never()).updateNextNaturalTrigger(any(WorkflowId.class), any(TriggerInstantSpec.class)); }
@Test public void shouldTriggerExecutionOnEnabledWithNextNaturalTrigger() throws IOException { setupWithNextNaturalTrigger(true, parse("2016-10-01T00:00:00Z"), WORKFLOW_DAILY); triggerManager.tick(); verify(triggerListener).event(WORKFLOW_DAILY, NATURAL_TRIGGER, parse("2016-10-01T00:00:00Z"), TriggerParameters.zero()); verify(storage).updateNextNaturalTrigger( WORKFLOW_DAILY.id(), TriggerInstantSpec.create(parse("2016-10-02T00:00:00Z"), parse("2016-10-03T00:00:00Z"))); }
@Test public void shouldNotTriggerExecutionOnDisabledWorkflowWithNextNaturalTrigger() throws IOException { setupWithNextNaturalTrigger(false, parse("2016-10-09T00:00:00Z"), WORKFLOW_DAILY); triggerManager.tick(); verify(triggerListener, never()).event(any(), any(), any(), any()); verify(storage).updateNextNaturalTrigger( WORKFLOW_DAILY.id(), TriggerInstantSpec.create(parse("2016-10-10T00:00:00Z"), parse("2016-10-11T00:00:00Z"))); }
@Test public void shouldNotTriggerExecutionIfNextNaturalTriggerAfterManagerTime() throws IOException { setupWithNextNaturalTrigger(true, parse("2016-10-11T00:00:00Z"), WORKFLOW_DAILY); triggerManager.tick(); verify(triggerListener, never()).event(any(), any(), any(), any()); verify(storage, never()).updateNextNaturalTrigger(any(), any()); }
@Test public void shouldNotTriggerExecutionOnDisabledGlobally() throws IOException { when(config.globalEnabled()).thenReturn(false); triggerManager.tick(); verify(triggerListener, never()).event(any(), any(), any(), any()); verify(storage, never()).updateNextNaturalTrigger(any(), any()); }
@Test public void shouldNotTriggerExecutionWhenFailedToReadConfig() throws IOException { when(storage.config()).thenThrow(new IOException()); triggerManager.tick(); verify(triggerListener, never()).event(any(), any(), any(), any()); verify(storage, never()).updateNextNaturalTrigger(any(), any()); }
@Test public void shouldNotUpdateNextNaturalTriggerIfTriggerListenerThrows() throws Exception { setupWithNextNaturalTrigger(true, parse("2016-10-01T00:00:00Z"), WORKFLOW_DAILY); doThrow(new RuntimeException()).when(triggerListener).event(any(), any(), any(), any()); triggerManager.tick(); verify(storage, never()).updateNextNaturalTrigger(any(), any()); }
@Test public void shouldUpdateNextNaturalTriggerIfAlreadyInitialized() throws Exception { setupWithNextNaturalTrigger(true, parse("2016-10-01T00:00:00Z"), WORKFLOW_DAILY); doThrow(new AlreadyInitializedException("")). when(triggerListener).event(any(), any(), any(), any()); triggerManager.tick(); verify(storage).updateNextNaturalTrigger( WORKFLOW_DAILY.id(), TriggerInstantSpec.create(parse("2016-10-02T00:00:00Z"), parse("2016-10-03T00:00:00Z"))); }
@Test public void shouldNotUpdateNextNaturalTriggerIfOtherException() throws Exception { setupWithNextNaturalTrigger(true, parse("2016-10-01T00:00:00Z"), WORKFLOW_DAILY); doThrow(new RuntimeException()) .when(triggerListener).event(any(), any(), any(), any()); triggerManager.tick(); verify(storage, never()).updateNextNaturalTrigger( WORKFLOW_DAILY.id(), TriggerInstantSpec.create(parse("2016-10-02T00:00:00Z"), parse("2016-10-03T00:00:00Z"))); }