CheckpointSchedulerAction implements ISchedulerAction { @Override public void execute(final ISchedulerEntry entry) throws SchedulerActionExecutionException { try { if (null != entry.getState().getValue(completedFieldName)) { if (null == entry.getState().getValue(gotFeedbackFieldName)) { IAction<IObject> failureAction = IOC.resolve(Keys.getOrAdd("checkpoint failure action")); failureAction.execute((IObject) entry.getState().getValue(messageFieldName)); } return; } IRecoverStrategy recoverStrategy = IOC.resolve(IOC.resolve( IOC.getKeyForKeyStorage(), entry.getState().getValue(recoverStrategyFieldName) )); recoverStrategy.reSend(entry.getState()); } catch (ResolutionException | ReadValueException | InvalidArgumentException | RecoverStrategyExecutionException | ActionExecuteException e) { throw new SchedulerActionExecutionException("Error occurred executing checkpoint action.", e); } } CheckpointSchedulerAction(); @Override void init(final ISchedulerEntry entry, final IObject args); @Override void execute(final ISchedulerEntry entry);  }
@Test public void Should_sendCloneOfMessageFillingCheckpointStatusOnExecution() throws Exception { IObject entryState = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{'recoverStrategy':'the recover strategy'," + "'message':{'a':'1'}," + "'responsibleCheckpointId':'rCP'," + "'prevCheckpointId':'prCP'," + "'prevCheckpointEntryId':'pcpEi'}").replace('\'','"')); when(entryMock.getState()).thenReturn(entryState); CheckpointSchedulerAction action = new CheckpointSchedulerAction(); action.execute(entryMock); verify(recoverStrategy).reSend(same(entryState)); }
@Test public void Should_notSendMessageIfEntryIsMarkedAsCompleted() throws Exception { IObject entryState = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{'recoverStrategy':'the recover strategy'," + "'message':{'a':'1'}," + "'responsibleCheckpointId':'rCP'," + "'prevCheckpointId':'prCP'," + "'prevCheckpointEntryId':'pcpEi'," + "'completed':true," + "'gotFeedback':true}").replace('\'','"')); when(entryMock.getState()).thenReturn(entryState); CheckpointSchedulerAction action = new CheckpointSchedulerAction(); action.execute(entryMock); verify(messageBusHandlerMock, never()).handle(any(), any()); }
@Test public void Should_notExecuteFailureActionIfEntryIsMarkedAsCompletedButGotNoFeedback() throws Exception { IObject entryState = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{'recoverStrategy':'the recover strategy'," + "'message':{'a':'1'}," + "'responsibleCheckpointId':'rCP'," + "'prevCheckpointId':'prCP'," + "'prevCheckpointEntryId':'pcpEi'," + "'completed':true}").replace('\'','"')); when(entryMock.getState()).thenReturn(entryState); CheckpointSchedulerAction action = new CheckpointSchedulerAction(); action.execute(entryMock); verify(messageBusHandlerMock, never()).handle(any(), any()); verify(failureAction).execute(same(entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "message")))); }