Package dev.restate.sdk.fake
Class FakeContext
java.lang.Object
dev.restate.sdk.fake.FakeContext
- All Implemented Interfaces:
Context,ObjectContext,SharedObjectContext,SharedWorkflowContext,WorkflowContext
@Experimental
public class FakeContext
extends Object
implements Context, ObjectContext, SharedObjectContext, WorkflowContext, SharedWorkflowContext
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionFakeContextwith default expectations.FakeContext(ContextExpectations expectations) FakeContext, seeContextExpectationsfor more details. -
Method Summary
Modifier and TypeMethodDescription<T> Awakeable<T> Create anAwakeable, addressable throughAwakeable.id().Create a newAwakeableHandlefor the provided identifier.<T,R> CallDurableFuture <R> Invoke another Restate service method.voidClears the state stored under key.voidclearAll()Clears all the state of this virtual object instance key-value state storage<T> Optional<T> <R> InvocationHandle<R> invocationHandle(String s, TypeTag<R> typeTag) key()<T> DurablePromise<T> promise(DurablePromiseKey<T> durablePromiseKey) Create aDurablePromisefor the given key.<T> DurablePromiseHandle<T> promiseHandle(DurablePromiseKey<T> durablePromiseKey) Create a newDurablePromiseHandlefor the provided key.random()Returns a deterministic random.request()<T> DurableFuture<T> runAsync(String s, TypeTag<T> typeTag, RetryPolicy retryPolicy, ThrowingSupplier<T> throwingSupplier) LikeContext.runAsync(String, TypeTag, ThrowingSupplier), but using a custom retry policy.<T,R> InvocationHandle <R> Invoke another Restate service without waiting for the response.<T> voidGets all the known state keys for this virtual object instance.Causes the start of a timer for the given duration.
-
Constructor Details
-
FakeContext
@Experimental public FakeContext()FakeContextwith default expectations.- See Also:
-
FakeContext
FakeContext, seeContextExpectationsfor more details.- See Also:
-
-
Method Details
-
request
-
call
Description copied from interface:ContextInvoke another Restate service method.- Specified by:
callin interfaceContext- Parameters:
request- Request object. For each service, a class called<your_class_name>Handlersis generated containing the request builders.- Returns:
- an
DurableFuturethat wraps the Restate service method result.
-
send
Description copied from interface:ContextInvoke another Restate service without waiting for the response.- Specified by:
sendin interfaceContext- Parameters:
request- Request object. For each service, a class called<your_class_name>Handlersis generated containing the request builders.duration- the delay to send the request- Returns:
- an
InvocationHandlethat can be used to retrieve the invocation id, cancel the invocation, attach to its result.
-
invocationHandle
Description copied from interface:Context- Specified by:
invocationHandlein interfaceContext
-
timer
Description copied from interface:ContextCauses the start of a timer for the given duration. You can await on the timer end by invokingDurableFuture.await(). -
runAsync
public <T> DurableFuture<T> runAsync(String s, TypeTag<T> typeTag, RetryPolicy retryPolicy, ThrowingSupplier<T> throwingSupplier) throws TerminalException Description copied from interface:ContextLikeContext.runAsync(String, TypeTag, ThrowingSupplier), but using a custom retry policy.When a retry policy is not specified, the
runwill be retried using the Restate invoker retry policy, which by default retries indefinitely.- Specified by:
runAsyncin interfaceContext- Throws:
TerminalException- See Also:
-
awakeable
Description copied from interface:ContextCreate anAwakeable, addressable throughAwakeable.id().You can use this feature to implement external asynchronous systems interactions, for example you can send a Kafka record including the
Awakeable.id(), and then let another service consume from Kafka the responses of given external system interaction by usingContext.awakeableHandle(String). -
awakeableHandle
Description copied from interface:ContextCreate a newAwakeableHandlefor the provided identifier. You can use it toAwakeableHandle.resolve(TypeTag, Object)orAwakeableHandle.reject(String)the linkedAwakeable.- Specified by:
awakeableHandlein interfaceContext- See Also:
-
random
Description copied from interface:ContextReturns a deterministic random. -
clear
Description copied from interface:ObjectContextClears the state stored under key.- Specified by:
clearin interfaceObjectContext- Parameters:
stateKey- identifying the state to clear.
-
clearAll
public void clearAll()Description copied from interface:ObjectContextClears all the state of this virtual object instance key-value state storage- Specified by:
clearAllin interfaceObjectContext
-
set
Description copied from interface:ObjectContext- Specified by:
setin interfaceObjectContext- Parameters:
stateKey- identifying the value to store and its type.t- to store under the given key. MUST NOT be null.
-
promise
Description copied from interface:SharedWorkflowContextCreate aDurablePromisefor the given key.You can use this feature to implement interaction between different workflow handlers, e.g. to send a signal from a shared handler to the workflow handler.
- Specified by:
promisein interfaceSharedWorkflowContext- Returns:
- the
DurablePromise. - See Also:
-
promiseHandle
Description copied from interface:SharedWorkflowContextCreate a newDurablePromiseHandlefor the provided key. You can use it toDurablePromiseHandle.resolve(Object)orDurablePromiseHandle.reject(String)the givenDurablePromise.- Specified by:
promiseHandlein interfaceSharedWorkflowContext- See Also:
-
key
- Specified by:
keyin interfaceSharedObjectContext- Returns:
- the key of this object
-
get
Description copied from interface:SharedObjectContext- Specified by:
getin interfaceSharedObjectContext- Parameters:
stateKey- identifying the state to get and its type.- Returns:
- an
Optionalcontaining the stored state deserialized or an emptyOptionalif not set yet.
-
stateKeys
Description copied from interface:SharedObjectContextGets all the known state keys for this virtual object instance.- Specified by:
stateKeysin interfaceSharedObjectContext- Returns:
- the immutable collection of known state keys.
-