ReSendRestoringSequenceRecoverStrategy implements IRecoverStrategy { @Override public void reSend(final IObject state) throws RecoverStrategyExecutionException { try { String sMessage = ((IObject) state.getValue(messageFieldName)).serialize(); IObject messageClone = IOC.resolve(Keys.getOrAdd(IObject.class.getName()), sMessage); IObject checkpointStatus = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject")); checkpointStatus.setValue(responsibleCheckpointIdFieldName, state.getValue(responsibleCheckpointIdFieldName)); checkpointStatus.setValue(checkpointEntryIdFieldName, state.getValue(entryIdFieldName)); checkpointStatus.setValue(prevCheckpointEntryIdFieldName, state.getValue(prevCheckpointEntryIdFieldName)); checkpointStatus.setValue(prevCheckpointIdFieldName, state.getValue(prevCheckpointIdFieldName)); messageClone.setValue(checkpointStatusFieldName, checkpointStatus); IMessageProcessingSequence sequence = IOC.resolve(Keys.getOrAdd("recover message processing sequence"), state.getValue(sequenceDumpFieldName)); IMessageProcessor processor = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"), IOC.resolve(Keys.getOrAdd("task_queue")), sequence ); processor.process(messageClone, IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"))); } catch (ReadValueException | InvalidArgumentException | SerializeException | ResolutionException | ChangeValueException | MessageProcessorProcessException e) { throw new RecoverStrategyExecutionException("Error occurred re-sending message.", e); } } ReSendRestoringSequenceRecoverStrategy(); @Override void init(final IObject state, final IObject args, final IMessageProcessor processor); @Override void reSend(final IObject state);  }
@Test public void Should_recoverMessageProcessingSequence() throws Exception { IObject state = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), ("{" + "'responsibleCheckpointId':'rcid'," + "'entryId':'eid'," + "'prevCheckpointEntryId':'pceid'," + "'prevCheckpointId':'pcid'," + "'sequenceDump':'This is a sequence dump. Trust me I am IObject.'," + "'message':{'is-a-message':true}" + "}").replace('\'','"')); IResolveDependencyStrategy recoverSequenceStrategy = mock(IResolveDependencyStrategy.class); IResolveDependencyStrategy messageProcessorStrategy = mock(IResolveDependencyStrategy.class); IMessageProcessingSequence sequenceMock = mock(IMessageProcessingSequence.class); IMessageProcessor processorMock = mock(IMessageProcessor.class); Object taskQueue = new Object(); IOC.register(Keys.getOrAdd("recover message processing sequence"), recoverSequenceStrategy); IOC.register(Keys.getOrAdd("info.smart_tools.smartactors.message_processing_interfaces.message_processing.IMessageProcessor"), messageProcessorStrategy); IOC.register(Keys.getOrAdd("task_queue"), new SingletonStrategy(taskQueue)); when(recoverSequenceStrategy.resolve(eq("This is a sequence dump. Trust me I am IObject."))).thenReturn(sequenceMock); when(messageProcessorStrategy.resolve(same(taskQueue), same(sequenceMock))).thenReturn(processorMock); new ReSendRestoringSequenceRecoverStrategy().reSend(state); ArgumentCaptor<IObject> mc = ArgumentCaptor.forClass(IObject.class); verify(processorMock).process(mc.capture(), any()); assertNotNull(mc.getValue()); assertEquals(true, mc.getValue().getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "is-a-message"))); IObject checkpointStatus = (IObject) mc.getValue().getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpointStatus")); assertNotNull(checkpointStatus); assertEquals("rcid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "responsibleCheckpointId"))); assertEquals("eid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "checkpointEntryId"))); assertEquals("pceid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointEntryId"))); assertEquals("pcid", checkpointStatus.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "prevCheckpointId"))); }