Search in sources :

Example 1 with SaveLastErrorCommand

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();
}
Also used : SaveLastErrorCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand) UpdateLocalsCommand(com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand) SaveLastErrorCommand(com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand) UpdateLocalsCommand(com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)

Example 2 with SaveLastErrorCommand

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"));
}
Also used : PersistenceService(com.walmartlabs.concord.runtime.v2.runner.PersistenceService) Runtime(com.walmartlabs.concord.svm.Runtime) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PersistenceService (com.walmartlabs.concord.runtime.v2.runner.PersistenceService)1 SaveLastErrorCommand (com.walmartlabs.concord.runtime.v2.runner.vm.SaveLastErrorCommand)1 UpdateLocalsCommand (com.walmartlabs.concord.runtime.v2.runner.vm.UpdateLocalsCommand)1 Runtime (com.walmartlabs.concord.svm.Runtime)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.jupiter.api.Test)1