use of com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand in project concord by walmartlabs.
the class Runner method start.
public ProcessSnapshot start(ProcessConfiguration processConfiguration, ProcessDefinition processDefinition, Map<String, Object> input) throws Exception {
statusCallback.onRunning(instanceId.getValue());
log.debug("start ['{}'] -> running...", processConfiguration.entryPoint());
Command cmd = CompilerUtils.compile(compiler, processConfiguration, processDefinition, processConfiguration.entryPoint());
State state = new InMemoryState(cmd);
// install the exception handler into the root frame
// takes care of all unhandled errors bubbling up
VMUtils.assertNearestRoot(state, state.getRootThreadId()).setExceptionHandler(new SaveLastErrorCommand());
VM vm = createVM(processDefinition);
// update the global variables using the input map by running a special command
// TODO merge with the cfg's arguments
vm.run(state, new UpdateLocalsCommand(input));
// start the normal execution
vm.start(state);
log.debug("start ['{}'] -> done", processConfiguration.entryPoint());
return ProcessSnapshot.builder().vmState(state).processDefinition(processDefinition).build();
}
use of com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand in project concord by walmartlabs.
the class SaveLastErrorCommandTest method test.
@Test
public void test() throws Exception {
ObjectMapper om = new ObjectMapper();
PersistenceService persistenceService = mock(PersistenceService.class);
Runtime runtime = mock(Runtime.class);
when(runtime.getService(eq(ObjectMapper.class))).thenReturn(om);
when(runtime.getService(eq(PersistenceService.class))).thenReturn(persistenceService);
MyException error = new MyException("BOOM1");
error.setSomeCyclicField(error);
Frame rootFrame = Frame.builder().root().locals(Collections.singletonMap(Frame.LAST_EXCEPTION_KEY, error)).build();
State state = new InMemoryState(rootFrame);
ThreadId threadId = state.getRootThreadId();
// ---
SaveLastErrorCommand cmd = new SaveLastErrorCommand();
rootFrame.push(new SaveLastErrorCommand());
try {
cmd.eval(runtime, state, threadId);
} catch (MyException e) {
assertEquals(error, e);
}
ArgumentCaptor<PersistenceService.Writer> writerCaptor = ArgumentCaptor.forClass(PersistenceService.Writer.class);
verify(persistenceService, times(1)).persistFile(eq(Constants.Files.OUT_VALUES_FILE_NAME), writerCaptor.capture());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
writerCaptor.getValue().write(bos);
assertThat(bos.toString(), containsString("\"message\":\"BOOM1\""));
assertThat(bos.toString(), containsString("\"someCyclicField\":1"));
assertThat(bos.toString(), containsString("\"@id\":1"));
}
Aggregations