public final class TestContext extends java.lang.Object implements Context
Context
to to make it easier to test StatefulFunction
s in isolation. It can be instantiated with
the address of the function under test and optionally the address of the caller.Modifier and Type | Method and Description |
---|---|
java.util.Optional<Address> |
caller() |
void |
cancelDelayedMessage(java.lang.String cancellationToken)
Cancel a delayed message (a message that was send via
Context.sendAfter(Duration, Message) ). |
static TestContext |
forTarget(Address self) |
static TestContext |
forTargetWithCaller(Address self,
Address caller) |
java.util.List<SideEffects.SendAfterSideEffect> |
getSentDelayedMessages() |
java.util.List<SideEffects.EgressSideEffect> |
getSentEgressMessages()
This method returns a list of all egress messages sent by this function via
Context.send(EgressMessage) . |
java.util.List<SideEffects.SendSideEffect> |
getSentMessages()
This method returns a list of all messages sent by this function via
Context.send(Message) or Context.sendAfter(Duration, Message) . |
Address |
self() |
void |
send(EgressMessage message)
Sends out a
EgressMessage to an egress. |
void |
send(Message message)
Sends out a
Message to another function. |
void |
sendAfter(java.time.Duration duration,
Message message)
Sends out a
Message to another function, after a specified Duration delay. |
void |
sendAfter(java.time.Duration duration,
java.lang.String cancellationToken,
Message message)
Sends out a
Message to another function, after a specified Duration delay. |
AddressScopedStorage |
storage() |
public static TestContext forTarget(Address self)
public static TestContext forTargetWithCaller(Address self, Address caller)
public Address self()
public java.util.Optional<Address> caller()
public void send(Message message)
Context
Message
to another function.public void sendAfter(java.time.Duration duration, Message message)
Context
Message
to another function, after a specified Duration
delay.public void sendAfter(java.time.Duration duration, java.lang.String cancellationToken, Message message)
Context
Message
to another function, after a specified Duration
delay.sendAfter
in interface Context
duration
- the amount of time to delay the message delivery. * @param cancellationTokencancellationToken
- the non-empty, non-null, unique token to attach to this message, to be
used for message cancellation. (see Context.cancelDelayedMessage(String)
.)message
- the message to send.public void cancelDelayedMessage(java.lang.String cancellationToken)
Context
Context.sendAfter(Duration, Message)
).
NOTE: this is a best-effort operation, since the message might have been already delivered. If the message was delivered, this is a no-op operation.
cancelDelayedMessage
in interface Context
cancellationToken
- the id of the message to un-send.public void send(EgressMessage message)
Context
EgressMessage
to an egress.public AddressScopedStorage storage()
storage
in interface Context
AddressScopedStorage
, providing access to stored values scoped to the
current invoked function instance's Address
(which is obtainable using Context.self()
).public java.util.List<SideEffects.SendSideEffect> getSentMessages()
Context.send(Message)
or Context.sendAfter(Duration, Message)
.
Messages are wrapped in an SideEffects.SendSideEffect
that contains the message
itself and the duration after which the message was sent. The Duration is Duration.ZERO
for messages sent via Context.send(Message)
.
SideEffects.SendSideEffect
spublic java.util.List<SideEffects.SendAfterSideEffect> getSentDelayedMessages()
public java.util.List<SideEffects.EgressSideEffect> getSentEgressMessages()
Context.send(EgressMessage)
.EgressMessage
sCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.