private <R> Task<R> doRun(final TaskFunction<LocalObjects.LocalObjectEntry<T>, R> function) { runtime.bind(); final ActorTaskContext actorTaskContext = ActorTaskContext.pushNew(); try { // using await makes the actorTaskContext.pop() run in the wrong thread. // the the internal par is separated return doRunInternal(function, actorTaskContext); } finally { actorTaskContext.pop(); } }
protected void starting(Description description) { logger = loggerExtension.getLogger(description.getMethodName()); taskContext.push(); taskContext.setProperty(TEST_NAME_PROP, description.getMethodName()); taskContext.setProperty(ActorBaseTest.class.getName(), description); testDescription = description; }
/** * Creates a new actor task context and pushes it to the current thread context stack. * * @return the new execution context */ public static ActorTaskContext pushNew() { final ActorTaskContext context = new ActorTaskContext(); context.push(); return context; }
public ActorTaskContext cloneContext() { final ActorTaskContext tc = new ActorTaskContext(); tc.actor = actor; tc.runtime = runtime; tc.properties().putAll(properties()); return tc; }
final ActorTaskContext context = ActorTaskContext.current(); if (context != null) context.setProperty(key, value); context.setDefaultExecutor(r -> entry.run(o -> })); context.setRuntime(runtime);
/** * Sets the runtime associated with the current thread. * <p> * It also tries to set the static runtime if the previous one got garbage collected. * </p> * <p> It's not necessary to "unset" the runtime because: * <ol> * <li>there should normally exist only one (only test cases are expected to have more than one)</li> * <li>it is already a weak reference</li> * <li>if another runtime is using the same thread later (shared thread pools) it will set the runtime before each usage</li> * </ol></p> * * @param runtimeRef a reference to the runtime */ public static void setRuntime(final WeakReference<? extends BasicRuntime> runtimeRef) { if (runtimeRef.get() instanceof ActorRuntime) { final ActorTaskContext context = ActorTaskContext.current(); if (context != null) { context.setRuntime((ActorRuntime) runtimeRef.get()); } } currentRuntime.set(runtimeRef); lastRuntime = runtimeRef; }
final ActorTaskContext context = ActorTaskContext.current(); if (context != null) final ActorRuntime runtime = context.getRuntime(); if (runtime != null)
@Override public Task<?> invoke(final RemoteReference toReference, final Method m, final boolean oneWay, final int methodId, final Object[] params) { if (state == NodeCapabilities.NodeState.STOPPED) { throw new IllegalStateException("Stage is stopped. " + this.toString()); } final Invocation invocation = new Invocation(toReference, m, oneWay, methodId, params, null); // copy stick context valued to the message headers headers final ActorTaskContext context = ActorTaskContext.current(); if (context != null) { Map<String, Object> headers = null; for (final String key : stickyHeaders) { final Object value = context.getProperty(key); if (value != null) { if (headers == null) { headers = new HashMap<>(); } headers.put(key, value); } } invocation.setHeaders(headers); } final Task<Void> result = pipeline.write(invocation); return result; }
final ActorTaskContext context1 = ActorTaskContext.currentFor(thread); final StackTraceElement[] stackTrace = thread.getStackTrace(); final ActorTaskContext context2 = ActorTaskContext.currentFor(thread); Object key = null; if (context1 != null && context1 == context2 && context1.getActor() != null) final RemoteReference reference = RemoteReference.from(context1.getActor()); key = reference._interfaceClass();
/** * Invoked when a test method finishes (whether passing or failing) */ protected void finished(Description description) { try { taskContext.pop(); } catch (Exception ex) { // ignore } }
.findFirst().orElseThrow(() -> new UncheckedException(String.format("Provider: %s not found", providerName))); final AbstractActor<?> actor = ActorTaskContext.currentActor(); if (actor != null)
/** * Sets the runtime associated with the current thread. * <p> * It also tries to set the static runtime if the previous one got garbage collected. * </p> * <p> It's not necessary to "unset" the runtime because: * <ol> * <li>there should normally exist only one (only test cases are expected to have more than one)</li> * <li>it is already a weak reference</li> * <li>if another runtime is using the same thread later (shared thread pools) it will set the runtime before each usage</li> * </ol></p> * * @param runtimeRef a reference to the runtime */ public static void setRuntime(final WeakReference<? extends BasicRuntime> runtimeRef) { if (runtimeRef.get() instanceof ActorRuntime) { final ActorTaskContext context = ActorTaskContext.current(); if (context != null) { context.setRuntime((ActorRuntime) runtimeRef.get()); } } currentRuntime.set(runtimeRef); lastRuntime = runtimeRef; }
final ActorTaskContext context = ActorTaskContext.current(); if (context != null) final ActorRuntime runtime = context.getRuntime(); if (runtime != null)
/** * Creates a new actor task context and pushes it to the current thread context stack. * * @return the new execution context */ public static ActorTaskContext pushNew() { final ActorTaskContext context = new ActorTaskContext(); context.push(); return context; }
public ActorTaskContext cloneContext() { final ActorTaskContext tc = new ActorTaskContext(); tc.actor = actor; tc.runtime = runtime; tc.properties().putAll(properties()); return tc; }
private String getFrom(final RemoteReference reference, final Method method) final ActorTaskContext context = ActorTaskContext.current(); String from; if (context != null && context.getActor() != null) final RemoteReference contextReference = RemoteReference.from(context.getActor()); from = RemoteReference.getInterfaceClass(contextReference).getSimpleName() + ":"