public async Task GetInterfacedPoisonPill_WaitForAllReentrantHandlersDone() { // Arrange var log = new LogBoard <string>(); var a = ActorOf(() => new TestGracefulShutdownActor(log)).Cast <WorkerRef>(); // Act a.WithNoReply().Reentrant(1); a.WithNoReply().Reentrant(2); await a.CastToIActorRef().GracefulStop(TimeSpan.FromMinutes(1), InterfacedPoisonPill.Instance); // Assert Assert.True(new HashSet <string> { "Reentrant(1)", "Reentrant(1) done", "Reentrant(2)", "Reentrant(2) done", }.SetEquals(log.Take(4))); Assert.Equal(new List <string> { "OnGracefulStop", "OnGracefulStop done" }, log.Skip(4)); }
public async Task FilterPerMessage_Work() { // Arrange var log = new LogBoard <string>(); var actor = ActorOf(() => new MessageFilterPerMessageActor(log)); // Act actor.Tell("A"); actor.Tell("B"); await actor.GracefulStop(TimeSpan.FromMinutes(1), InterfacedPoisonPill.Instance); // Assert Assert.Equal( new[] { "MessageFilterPerMessageActor.Handle.Constructor", "MessageFilterPerMessageActor.Handle.OnPreMessage", "Handle(A)", "MessageFilterPerMessageActor.Handle.OnPostMessage", "MessageFilterPerMessageActor.Handle.Constructor", "MessageFilterPerMessageActor.Handle.OnPreMessage", "Handle(B)", "MessageFilterPerMessageActor.Handle.OnPostMessage", }, log); }
public async Task FilterPerRequest_Work() { // Arrange var log = new LogBoard <string>(); var a = ActorOf(() => new RequestFilterPerRequestActor(log)).Cast <DummyExRef>(); // Act await a.Call("A"); await a.Call("B"); await a.CallEx("C"); // Assert Assert.Equal( new[] { "RequestFilterPerRequestActor.Call.Constructor", "RequestFilterPerRequestActor.Call.OnPreRequest", "Call(A)", "RequestFilterPerRequestActor.Call.OnPostRequest", "RequestFilterPerRequestActor.Call.Constructor", "RequestFilterPerRequestActor.Call.OnPreRequest", "Call(B)", "RequestFilterPerRequestActor.Call.OnPostRequest", "RequestFilterPerRequestActor.CallEx.Constructor", "RequestFilterPerRequestActor.CallEx.OnPreRequest", "CallEx(C)", "RequestFilterPerRequestActor.CallEx.OnPostRequest" }, log); }
public async Task FilterPerNotification_Work() { // Arrange var log = new LogBoard <string>(); var subject = await SetupActors <NotificationFilterPerNotificationActor>(log); // Act await subject.MakeEvent("A"); await subject.MakeEvent("B"); // Assert Assert.Equal( new[] { "NotificationFilterPerNotificationActor.Event.Constructor", "NotificationFilterPerNotificationActor.Event.OnPreNotification", "Event(A)", "NotificationFilterPerNotificationActor.Event.OnPostNotification", "NotificationFilterPerNotificationActor.Event.Constructor", "NotificationFilterPerNotificationActor.Event.OnPreNotification", "Event(B)", "NotificationFilterPerNotificationActor.Event.OnPostNotification", }, log); }
public async Task FilterOrder_Work() { // Arrange var log = new LogBoard <string>(); var subject = ActorOf(() => new SubjectActor()).Cast <SubjectRef>(); var observingActor = ActorOf(() => new TestFilterActor(log)); await subject.Subscribe(new SubjectObserver(new AkkaReceiverNotificationChannel(observingActor))); // Act await subject.MakeEvent("A"); await Task.Delay(10); // Assert Assert.Equal( new[] { "TestFilterActor_1.OnPreNotification", "TestFilterActor_2.OnPreNotification", "Event(A)", "TestFilterActor_2.OnPostNotification", "TestFilterActor_1.OnPostNotification" }, log); }
public MessageFilterPerMessageFilter(string name, object actor) { if (name != null) { _name = name; LogBoard <string> .Add(actor, $"{_name}.Constructor"); } }
public NotificationFilterPerNotificationFilter(string name, object actor) { if (name != null) { _name = name; LogBoard <string> .Add(actor, $"{_name}.Constructor"); } }
public RequestFilterPerInstanceMethodFilter(string name, object actor) { if (name != null) { _name = name; LogBoard <string> .Add(actor, $"{_name}.Constructor"); } }
async Task IPreRequestAsyncFilter.OnPreRequestAsync(PreRequestFilterContext context) { LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPreRequestAsync"); await Task.Yield(); LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPreRequestAsync Done"); }
async Task IPostMessageAsyncFilter.OnPostMessageAsync(PostMessageFilterContext context) { LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync"); await Task.Yield(); LogBoard <string> .Add(context.Actor, $"{_actorType.Name} Async.OnPostMessageAsync Done"); }
private async Task <Tuple <Subject2Ref, IActorRef> > SetupActors2(LogBoard <string> log) { var subjectActor = ActorOfAsTestActorRef <Subject2Actor>("Subject"); var subject = subjectActor.Cast <Subject2Ref>(); var observingActor = ActorOf(() => new TestExceptionActor(log)); await subject.Subscribe(new Subject2Observer(new AkkaReceiverNotificationChannel(observingActor))); return(Tuple.Create(subject, (IActorRef)observingActor)); }
private async Task <Subject2Ref> SetupActors2 <TObservingActor>(LogBoard <string> log) where TObservingActor : ActorBase { var subjectActor = ActorOfAsTestActorRef <Subject2Actor>("Subject"); var subject = subjectActor.Cast <Subject2Ref>(); var observingActor = ActorOfAsTestActorRef <TObservingActor>(Props.Create <TObservingActor>(log)); await subject.Subscribe(new Subject2Observer(new AkkaReceiverNotificationChannel(observingActor))); return(subject); }
public async Task BasicCallWithParameter_Done(Type actorType) { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(actorType, log)).Cast <BasicRef>(); // Act await a.CallWithParameter(1); // Assert Assert.Equal(new[] { "CallWithParameter(1)" }, log); }
public async Task BasicActor_ObserveSubject(object context) { // Arrange var log = new LogBoard <string>(); var subject = ActorOf(() => new SubjectExActor()).Cast <SubjectExRef>(); var a = ActorOf(() => new TestObserverActor(subject, log)).Cast <DummyRef>(); // Act await a.Call(context); // Assert Assert.Equal(new[] { "Event:A", "Event:B" }, log); }
public async Task BasicThrowExceptionWithFilter_Done(Type actorType) { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(actorType, log)).Cast <BasicRef>(); // Act var e = await Record.ExceptionAsync(() => a.ThrowException(ThrowExceptionType.ResponsiveByFilter)); // Assert Assert.Equal(new[] { "ThrowException(ResponsiveByFilter)" }, log); Assert.IsType <ArgumentException>(e); }
public async Task Mins_Done(Type actorType) { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(actorType, log)).Cast <OverloadedRef>(); // Act var ret = await a.Min(1, 2, 3, 4); // Assert Assert.Equal(1, ret); Assert.Equal(new[] { "Min(1, 2, 3, 4)" }, log); }
public async Task BasicCallWithReturn_Done(Type actorType) { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(actorType, log)).Cast <BasicRef>(); // Act var r = await a.CallWithReturn(); // Assert Assert.Equal(new[] { "CallWithReturn()" }, log); Assert.Equal(1, r); }
public async Task GetGenericNotification(Type actorType) { // Arrange var log = new LogBoard <string>(); var subject = ActorOf(() => new SubjectActor <string>()).Cast <SubjectRef <string> >(); var a = ActorOf(Props.Create(actorType, subject, log)).Cast <DummyRef>(); // Act await a.Call(null); // Assert Assert.Equal(new[] { $"A", $"B,10" }, log); }
public async Task TaskRun_SyncHandler_ExecutedSequantially() { // Arrange var log = new LogBoard <string>(); var actor = ActorOf(() => new TestRunActor(log)); // Act actor.Tell("S:1"); await actor.GracefulStop(TimeSpan.FromMinutes(1), "X"); // Assert Assert.Equal(new[] { "S:1" }, log); }
public async Task StopActor_RunningAsyncMessageHandler_Canceled() { var log = new LogBoard <string>(); var worker = ActorOf(() => new TaskCancellationActor(log, 100)).Cast <WorkerRef>(); worker.CastToIActorRef().Tell(1); worker.CastToIActorRef().Tell("E"); Watch(worker.CastToIActorRef()); ExpectTerminated(worker.CastToIActorRef()); await Task.Delay(100); Assert.Equal(new[] { "Handle(1)" }, log); }
public async Task ExceptionThrown_At_Request_With_ResponsiveException() { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(() => new TestExceptionActor(log, 0))).Cast <DummyRef>(); // Act var exception = await Record.ExceptionAsync(() => a.Call("e")); // Assert Assert.IsType <ArgumentException>(exception); Assert.Equal(new[] { "Call(e)" }, log); }
public async Task ExceptionThrown_At_NotificationReentrantAsyncDone() { // Arrange var log = new LogBoard <string>(); var actors = await SetupActors2(log); // Act await actors.Item1.MakeEvent2("F"); // Assert Watch(actors.Item2); ExpectTerminated(actors.Item2); Assert.Equal(new[] { "Event2(F)", "Event2(F) Done" }, log); }
public void ExceptionThrown_At_HandleAsync() { // Arrange var log = new LogBoard <string>(); var actor = ActorOf(Props.Create(() => new TestExceptionActor(log))); // Act actor.Tell(1); // Assert Watch(actor); ExpectTerminated(actor); Assert.Equal(new[] { "HandleAsync(1)" }, log); }
public async Task ExceptionThrown_At_Notification() { // Arrange var log = new LogBoard <string>(); var actors = await SetupActors(log); // Act await actors.Item1.MakeEvent("E"); // Assert Watch(actors.Item2); ExpectTerminated(actors.Item2); Assert.Equal(new[] { "Event(E)" }, log); }
public async Task BasicActor_ObserveSubject(object context) { // Arrange var log = new LogBoard <string>(); var subject = ActorOf(() => new SubjectActor()).Cast <SubjectRef>(); var a = ActorOf(() => new TestObserverActor(subject, log)).Cast <DummyRef>(); // Act await a.Call(context); // Assert var c = context != null ? context + ":" : ""; Assert.Equal(new[] { $"{c}A" }, log); }
public async Task CallGenericMethod(Type actorType) { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(actorType, log)).Cast <DummyRef <string> >(); // Act var ret1 = await a.Call("A"); var ret2 = await a.Call("B", 10); // Assert Assert.Equal("A", ret1); Assert.Equal("B", ret2); Assert.Equal(new[] { "Call(A)", "Call(B, 10)" }, log); }
public async Task StopActor_RunningAsyncRequestHandler_Canceled() { var log = new LogBoard <string>(); var worker = ActorOf(() => new TaskCancellationActor(log, 100)).Cast <WorkerRef>(); var exceptionTask = Record.ExceptionAsync(() => worker.Reentrant(1)); worker.CastToIActorRef().Tell("E"); Assert.IsType <RequestHaltException>(await exceptionTask); Watch(worker.CastToIActorRef()); ExpectTerminated(worker.CastToIActorRef()); await Task.Delay(100); Assert.Equal(new[] { "Reentrant(1)" }, log); }
public async Task ExceptionThrown_At_RequestReentrantAsyncDone() { // Arrange var log = new LogBoard <string>(); var a = ActorOf(Props.Create(() => new TestExceptionActor(log, 0))).Cast <WorkerRef>(); // Act var exception = await Record.ExceptionAsync(() => a.Reentrant(2)); // Assert Assert.IsType <RequestFaultException>(exception); Watch(a.CastToIActorRef()); ExpectTerminated(a.CastToIActorRef()); Assert.Equal(new[] { "Reentrant(2)", "Reentrant(2) Done" }, log); }
public async Task Message_SyncHandler_ExecutedSequantially() { // Arrange var log = new LogBoard <string>(); var actor = ActorOf(() => new TestMessageActor(log)); // Act actor.Tell(new PlainMessages.Func { Value = "A" }); await actor.GracefulStop(TimeSpan.FromMinutes(1), InterfacedPoisonPill.Instance); // Assert Assert.Equal(new[] { "A_1" }, log); }
public async Task Schedule_ReentrantHandler_Interleaved() { // Arrange var log = new LogBoard <Tuple <int, int> >(); var a = ActorOf(() => new TestScheduleActor(log)).Cast <WorkerRef>(); // Act var t1 = a.Reentrant(1); var t2 = a.Reentrant(2); await Task.WhenAll(t1, t2); // Assert Assert.Equal(new[] { 1, 2, 3 }, log.Where(t => t.Item1 == 1).Select(t => t.Item2)); Assert.Equal(new[] { 1, 2, 3 }, log.Where(t => t.Item1 == 1).Select(t => t.Item2)); }