=act Reset receiveTimeoutData to emptyReceiveTimeoutData when cancel (#31059)

This commit is contained in:
kerr 2022-01-19 19:17:51 +08:00 committed by GitHub
parent 9d0684d875
commit 4585c3823e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View file

@ -585,6 +585,46 @@ public class ActorDocTest extends AbstractJavaTest {
};
}
static class ReceiveTimeoutWithCancelActor extends AbstractActor {
private ActorRef target = getContext().getSystem().deadLetters();
public ReceiveTimeoutWithCancelActor() {
getContext().setReceiveTimeout(Duration.ofSeconds(1));
}
@Override
public Receive createReceive() {
return receiveBuilder()
.matchEquals(
"Hello",
s -> {
target = getSender();
target.tell("Hello world", getSelf());
getContext().setReceiveTimeout(Duration.ofMillis(200));
})
.match(
ReceiveTimeout.class,
r -> {
getContext().cancelReceiveTimeout();
target.tell("timeout", getSelf());
})
.build();
}
}
@Test
public void cancel_receiveTimeout() {
final ActorRef myActor = system.actorOf(Props.create(ReceiveTimeoutWithCancelActor.class));
new TestKit(system) {
{
myActor.tell("Hello", getRef());
expectMsgEquals("Hello world");
expectMsgEquals("timeout");
expectNoMessage(Duration.ofMillis(400));
}
};
}
public
// #hot-swap-actor
static class HotSwapActor extends AbstractActor {