Package dev.restate.sdk.fake
Record Class ContextExpectations
java.lang.Object
java.lang.Record
dev.restate.sdk.fake.ContextExpectations
@Experimental
public record ContextExpectations(long randomSeed, String invocationId, Map<String,String> requestHeaders, Map<String,ContextExpectations.RunExpectation> runExpectations, BiPredicate<Duration,String> completeTimerIf, SerdeFactory serdeFactory)
extends Record
Expectation configuration for
FakeContext.
This record defines the expected behavior and configuration for a fake context used in testing. It controls various aspects including:
- Random seed used by
Context.random() - Expectations for
Context.run(java.lang.String, java.lang.Class<T>, dev.restate.common.function.ThrowingSupplier<T>) - Timers' completion conditions (for
Context.timer(java.time.Duration))
By default, the FakeContext will execute all ctx.run.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionContextExpectations(long randomSeed, String invocationId, Map<String, String> requestHeaders, Map<String, ContextExpectations.RunExpectation> runExpectations, BiPredicate<Duration, String> completeTimerIf, SerdeFactory serdeFactory) Creates an instance of aContextExpectationsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionSpecify that all timers immediately complete.Returns the value of thecompleteTimerIfrecord component.completeTimerLongerOrEqualThan(Duration duration) Specify that all timers with duration longer than the given value complete as soon as they're created.completeTimerNamed(String timerName) Specify that the timer with the given name complete as soon as they're created.dontExecuteRun(String runName) Specify that the run with the given name should not be executed.dontRetryRun(String runName) Specify that the run with the given name should not be retried.final booleanIndicates whether some other object is "equal to" this one.executeRun(String runName) Specify that the run with the given name should be executed.final inthashCode()Returns a hash code value for this object.Returns the value of theinvocationIdrecord component.longReturns the value of therandomSeedrecord component.Returns the value of therequestHeadersrecord component.Returns the value of therunExpectationsrecord component.Returns the value of theserdeFactoryrecord component.final StringtoString()Returns a string representation of this record class.withInvocationId(String invocationId) Set the invocation id returned byctx.request().invocationId().withRandomSeed(long randomSeed) Set the random seed to be used byContext.random().withRequestHeaders(Map<String, String> requestHeaders) Set the request headers returned byctx.request().headers().
-
Constructor Details
-
ContextExpectations
public ContextExpectations() -
ContextExpectations
public ContextExpectations(long randomSeed, String invocationId, Map<String, String> requestHeaders, Map<String, ContextExpectations.RunExpectation> runExpectations, BiPredicate<Duration, String> completeTimerIf, SerdeFactory serdeFactory) Creates an instance of aContextExpectationsrecord class.- Parameters:
randomSeed- the value for therandomSeedrecord componentinvocationId- the value for theinvocationIdrecord componentrequestHeaders- the value for therequestHeadersrecord componentrunExpectations- the value for therunExpectationsrecord componentcompleteTimerIf- the value for thecompleteTimerIfrecord componentserdeFactory- the value for theserdeFactoryrecord component
-
-
Method Details
-
withRandomSeed
Set the random seed to be used byContext.random().- Parameters:
randomSeed- the random seed to use
-
withInvocationId
Set the invocation id returned byctx.request().invocationId().- Parameters:
invocationId- the invocation ID to use
-
withRequestHeaders
Set the request headers returned byctx.request().headers().- Parameters:
requestHeaders- the request headers to use
-
executeRun
Specify that the run with the given name should be executed.The mocked context will try to execute the run, and in case of a failure, the given exception will be thrown as is.
- Parameters:
runName- the name of the run that should be executed
-
dontRetryRun
Specify that the run with the given name should not be retried.The mocked context will try to execute the run, and in case of a failure, the given exception will be converted to
TerminalException.This is useful when unit testing a saga, and you want to simulate the "catch" branch.
- Parameters:
runName- the name of the run that should not be retried
-
dontExecuteRun
Specify that the run with the given name should not be executed.The mocked context will not execute the run.
This is useful when testing a flow where you either want to wait a
ctx.runto complete, or another event (such as timers)- Parameters:
runName- the name of the run that should not be executed
-
completeAllTimersImmediately
Specify that all timers immediately complete. -
completeTimerNamed
Specify that the timer with the given name complete as soon as they're created. -
completeTimerLongerOrEqualThan
Specify that all timers with duration longer than the given value complete as soon as they're created. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
randomSeed
public long randomSeed()Returns the value of therandomSeedrecord component.- Returns:
- the value of the
randomSeedrecord component
-
invocationId
Returns the value of theinvocationIdrecord component.- Returns:
- the value of the
invocationIdrecord component
-
requestHeaders
Returns the value of therequestHeadersrecord component.- Returns:
- the value of the
requestHeadersrecord component
-
runExpectations
Returns the value of therunExpectationsrecord component.- Returns:
- the value of the
runExpectationsrecord component
-
completeTimerIf
Returns the value of thecompleteTimerIfrecord component.- Returns:
- the value of the
completeTimerIfrecord component
-
serdeFactory
Returns the value of theserdeFactoryrecord component.- Returns:
- the value of the
serdeFactoryrecord component
-