Search in sources :

Example 6 with Frame

use of com.walmartlabs.concord.svm.Frame in project concord by walmartlabs.

the class VMUtilsTest method testLocals.

@Test
public void testLocals() {
    Frame rootFrame = Frame.builder().root().locals(Collections.singletonMap("x", 123)).build();
    State state = new InMemoryState(rootFrame);
    ThreadId threadId = state.getRootThreadId();
    Frame levelOneFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("y", 234)).build();
    state.pushFrame(threadId, levelOneFrame);
    Frame levelTwoFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("x", 345)).build();
    state.pushFrame(threadId, levelTwoFrame);
    Map<String, Object> locals = VMUtils.getCombinedLocals(state, threadId);
    assertEquals(2, locals.size());
    assertEquals(345, locals.get("x"));
    assertEquals(234, locals.get("y"));
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) Test(org.junit.jupiter.api.Test)

Example 7 with Frame

use of com.walmartlabs.concord.svm.Frame in project concord by walmartlabs.

the class ContextUtils method getCurrentRetryAttemptNumber.

/**
 * Returns the current "retry" attempt number (if applicable).
 *
 * @param ctx current {@link Context}
 * @return the current attemp number of {@code null} if the current call is a retry.
 * @see Constants.Runtime#RETRY_ATTEMPT_NUMBER
 */
public static Integer getCurrentRetryAttemptNumber(Context ctx) {
    Execution execution = ctx.execution();
    State state = execution.state();
    ThreadId threadId = execution.currentThreadId();
    Frame frame = state.peekFrame(threadId);
    Serializable value = frame.getLocal(Constants.Runtime.RETRY_ATTEMPT_NUMBER);
    if (value == null) {
        return null;
    }
    if (!(value instanceof Integer)) {
        throw new IllegalStateException(String.format("%s is expected to be a number, got: %s. This is most likely a bug", Constants.Runtime.RETRY_ATTEMPT_NUMBER, value.getClass()));
    }
    return (Integer) value;
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) Serializable(java.io.Serializable) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 8 with Frame

use of com.walmartlabs.concord.svm.Frame in project concord by walmartlabs.

the class SuspendStepCommand method execute.

@Override
protected void execute(Runtime runtime, State state, ThreadId threadId) {
    Frame frame = state.peekFrame(threadId);
    frame.pop();
    frame.push(new SuspendCommand(getStep().getEvent()));
}
Also used : Frame(com.walmartlabs.concord.svm.Frame)

Aggregations

Frame (com.walmartlabs.concord.svm.Frame)8 State (com.walmartlabs.concord.svm.State)3 TaskCallInterceptor (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor)2 TaskException (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException)2 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)2 ThreadId (com.walmartlabs.concord.svm.ThreadId)2 TaskCall (com.walmartlabs.concord.runtime.v2.model.TaskCall)1 TaskCallOptions (com.walmartlabs.concord.runtime.v2.model.TaskCallOptions)1 ExpressionEvaluator (com.walmartlabs.concord.runtime.v2.runner.el.ExpressionEvaluator)1 LogContext (com.walmartlabs.concord.runtime.v2.runner.logging.LogContext)1 CallContext (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor.CallContext)1 InMemoryState (com.walmartlabs.concord.svm.InMemoryState)1 Serializable (java.io.Serializable)1 Test (org.junit.jupiter.api.Test)1