CheckpointSchedulerAction implements ISchedulerAction { @Override public void init(final ISchedulerEntry entry, final IObject args) throws SchedulerActionInitializationException { try { IObject recoverConfig = (IObject) args.getValue(recoverFieldName); String recoverStrategyId = (String) recoverConfig.getValue(strategyFieldName); IObject message = (IObject) args.getValue(messageFieldName); if (null == message) { throw new SchedulerActionInitializationException( "Checkpoint scheduler action arguments should contain message object.", null); } entry.getState().setValue(messageFieldName, message); IRecoverStrategy strategy = IOC.resolve(Keys.getOrAdd(recoverStrategyId)); strategy.init(entry.getState(), recoverConfig, (IMessageProcessor) args.getValue(processorFieldName)); entry.getState().setValue(recoverStrategyFieldName, recoverStrategyId); entry.getState().setValue(responsibleCheckpointIdFieldName, args.getValue(responsibleCheckpointIdFieldName)); entry.getState().setValue(prevCheckpointIdFieldName, args.getValue(prevCheckpointIdFieldName)); entry.getState().setValue(prevCheckpointEntryIdFieldName, args.getValue(prevCheckpointEntryIdFieldName)); } catch (ReadValueException | InvalidArgumentException | ResolutionException | RecoverStrategyInitializationException | ChangeValueException e) { throw new SchedulerActionInitializationException("Error occurred initializing checkpoint action.", e); } } CheckpointSchedulerAction(); @Override void init(final ISchedulerEntry entry, final IObject args); @Override void execute(final ISchedulerEntry entry);  }
@Test(expected = SchedulerActionInitializationException.class) public void Should_throwWhenInitializationArgumentsDoNotContainMessage() throws Exception { CheckpointSchedulerAction action = new CheckpointSchedulerAction(); IObject args = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'recover':{'strategy':'the recover strategy'},'message':null}".replace('\'','"')); action.init(entryMock, args); }
@Test public void Should_initializeRecoverStrategyAndCopyFieldsToEntryStateOnInitialization() throws Exception { CheckpointSchedulerAction action = new CheckpointSchedulerAction(); IMessageProcessor processorMock = mock(IMessageProcessor.class); IObject args = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{'recover':{'strategy':'the recover strategy'}," + "'message':{'a':'1'}," + "'responsibleCheckpointId':'rCP'," + "'prevCheckpointId':'prCP'," + "'prevCheckpointEntryId':'pcpEi'}").replace('\'','"')); args.setValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "processor"), processorMock); action.init(entryMock, args); verify(recoverStrategy).init(same(entryState), any(), same(processorMock)); assertEquals("rCP", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "responsibleCheckpointId"))); assertEquals("prCP", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointId"))); assertEquals("pcpEi", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointEntryId"))); assertEquals("the recover strategy", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "recoverStrategy"))); assertEquals("1", ((IObject) entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "message"))) .getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "a"))); }