public void When_timing_out_Then_AskTimeoutException_is_thrown() { var actorSystem = new TestBootstrapper().CreateSystem(); var promiseActorRef = PromiseActorRef.Create(actorSystem, 10, "target"); Assert.Throws <AggregateException>(() => promiseActorRef.Future.Wait()).ContainsException <AskTimeoutException>().Should().BeTrue(); }
public void Given_a_timed_out_instance_When_sending_messages_to_it_Then_messages_are_forwarded_to_deadLetter() { var deadLetterActor = A.Fake <ActorRef>(); var testBootstrapper = new TestBootstrapper() { DeadLetterActorCreator = (path, system) => deadLetterActor }; var actorSystem = testBootstrapper.CreateSystem(); var promiseActorRef = PromiseActorRef.Create(actorSystem, 10, "target"); try{ promiseActorRef.Future.Wait(); } catch (Exception) {} var fakeSender = A.Fake <ActorRef>(); var message1 = new object(); var message2 = new object(); promiseActorRef.Send(message1, fakeSender); promiseActorRef.Send(message2, fakeSender); A.CallTo(() => deadLetterActor.Send(message1, fakeSender)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => deadLetterActor.Send(message2, fakeSender)).MustHaveHappened(Repeated.Exactly.Once); }
public static AskResult <TResponse> Ask <TResponse>(this ActorRef actor, object message, ActorRef sender, int timeoutMilliseconds = Timeout.Infinite) { var intActor = actor as InternalActorRef; if (intActor == null) { return(new AskResult <TResponse>(Promise.Failed <TResponse>(new ArgumentException("Unsupported recipient ActorRef type, question not sent to " + actor, "actor")), actor)); } if (intActor.IsTerminated) { intActor.Send(message, sender); return(new AskResult <TResponse>(Promise.Failed <TResponse>(new AskTimeoutException("Recipient " + actor + " had already been terminated.")), actor)); } if (timeoutMilliseconds < 0 && timeoutMilliseconds != Timeout.Infinite) { return(new AskResult <TResponse>(Promise.Failed <TResponse>(new ArgumentOutOfRangeException("timeoutMilliseconds", timeoutMilliseconds, "Timeout must be positive or Infinite=" + Timeout.Infinite + ", question not sent to " + actor)), actor)); } var system = intActor.System; var promiseActor = PromiseActorRef.Create <TResponse>(system, timeoutMilliseconds, actor.ToString()); actor.Send(message, promiseActor); //Send to actor and expect response to promiseActor if (system.Settings.DebugMessages) { system.EventStream.Publish(new DebugLogEvent(actor.Path.ToString(), intActor.SafeGetTypeForLogging(), "Ask: " + Envelope.ToString(sender, actor, message))); } return(new AskResult <TResponse>(promiseActor.Future, actor)); }