예제 #1
0
        public async Task TestNoTask(IActorFactory fact)
        {
            Output(fact.Type.ToString());

            var one    = new PingPongerSimple("Bjorg");
            var actor1 = fact.Build <IPingPonger>(one);

            var two    = new PingPongerSimple("Lendl");
            var actor2 = fact.Build <IPingPonger>(two);

            one.Ponger = actor2;
            two.Ponger = actor1;

            var watch = Stopwatch.StartNew();

            actor1.Ping();
            Thread.Sleep(10000);

            await fact.DisposeAsync();

            watch.Stop();

            Output($"Total Ping:{one.Count}, Total Pong:{two.Count} Total Time: {watch.ElapsedMilliseconds} ms");
            Output($"Operation/ms:{(one.Count + two.Count) / watch.ElapsedMilliseconds}");
        }
예제 #2
0
        public async Task TestTask_T_CancellationToken(IActorFactory fact)
        {
            Output(fact.Type.ToString());

            var one    = new PingPongerAsyncCancellable("Noa");
            var actor1 = fact.Build <IPingPongerAsyncCancellable>(one);

            var two    = new PingPongerAsyncCancellable("Wilander");
            var actor2 = fact.Build <IPingPongerAsyncCancellable>(two);

            one.PongerAsync = actor2;
            two.PongerAsync = actor1;

            var watch = Stopwatch.StartNew();

            await actor1.Ping(CancellationToken.None);

            Thread.Sleep(10000);

            await fact.DisposeAsync();

            watch.Stop();

            Output($"Total Ping:{one.Count}, Total Pong:{two.Count} Total Time: {watch.ElapsedMilliseconds} ms");
            Output($"Operation/ms:{(one.Count + two.Count) / watch.ElapsedMilliseconds}");
        }
예제 #3
0
        public async Task Proxy_Method_WithoutResult_Should_Be_Called()
        {
            //arrange
            var obj   = new DummyClass();
            var actor = _Factory.Build <IDummyInterface2>(obj);

            //act
            await actor.DoAsync();

            //assert
            obj.Done.Should().BeTrue();
        }
        public async Task All_Actors_Should_Run_On_Same_Thread()
        {
            //arrange
            var target1 = new DummyClass();
            var target2 = new DummyClass();

            _Actor1 = _Factory.Build <IDummyInterface2>(target1);
            _Actor2 = _Factory.Build <IDummyInterface2>(target2);

            //act
            await _Actor1.DoAsync();

            await _Actor2.DoAsync();

            //assert
            target1.CallingThread.Should().Be(target2.CallingThread);
        }
        public async Task Method_Should_Run_On_Separated_Pooled_Thread()
        {
            var current = Thread.CurrentThread;
            var target  = new DummyClass();
            var intface = _TaskPoolActorFactory.Build <IDummyInterface2>(target);
            await intface.DoAsync();

            target.Done.Should().BeTrue();
            target.CallingThread.Should().NotBeNull();
            target.CallingThread.IsThreadPoolThread.Should().BeTrue();
            target.CallingThread.Should().NotBe(current);
        }
예제 #6
0
 private static object[] BuildTestData(IActorFactory factory, IDoStuff stuffer)
 {
     return(new object[] { factory.Build(stuffer), true });
 }
예제 #7
0
 private static object[] BuildTestData(IActorFactory factory, IDoStuff stuffer) 
 {
     return new object[] { factory.Build(stuffer), true };
 }
예제 #8
0
 private static IBindingWhenInNamedWithOrOnSyntax <TInterface> BindAsActor <TInterface, T>(IKernel standardKernel, IActorFactory factory)
     where T : TInterface
     where TInterface : class
 {
     return(standardKernel.Bind <TInterface>().ToMethod(ctx => factory.Build <TInterface>(ctx.Kernel.Get <T>())));
 }