Esempio n. 1
0
        public void TestDirectoryScanMaybeActor()
        {
            var address1 = World.AddressFactory.UniqueWith("test-actor1");
            var address2 = World.AddressFactory.UniqueWith("test-actor2");
            var address3 = World.AddressFactory.UniqueWith("test-actor3");
            var address4 = World.AddressFactory.UniqueWith("test-actor4");
            var address5 = World.AddressFactory.UniqueWith("test-actor5");

            var address6 = World.AddressFactory.UniqueWith("test-actor6");
            var address7 = World.AddressFactory.UniqueWith("test-actor7");

            World.Stage.Directory.Register(address1, new TestInterfaceActor());
            World.Stage.Directory.Register(address2, new TestInterfaceActor());
            World.Stage.Directory.Register(address3, new TestInterfaceActor());
            World.Stage.Directory.Register(address4, new TestInterfaceActor());
            World.Stage.Directory.Register(address5, new TestInterfaceActor());

            var scanResults = new ScanResult();

            scanResults.AfterCompleting(7);

            Action <Optional <INoProtocol> > afterConsumer = maybe =>
            {
                Assert.True(maybe.IsPresent);
                scanResults.ScanFound.WriteUsing("foundCount", 1);
            };

            World.Stage.MaybeActorOf <INoProtocol>(address5).AndThenConsume(afterConsumer);
            World.Stage.MaybeActorOf <INoProtocol>(address4).AndThenConsume(afterConsumer);
            World.Stage.MaybeActorOf <INoProtocol>(address3).AndThenConsume(afterConsumer);
            World.Stage.MaybeActorOf <INoProtocol>(address2).AndThenConsume(afterConsumer);
            World.Stage.MaybeActorOf <INoProtocol>(address1).AndThenConsume(afterConsumer);

            World.Stage.MaybeActorOf <INoProtocol>(address6)
            .AndThen(maybe =>
            {
                Assert.False(maybe.IsPresent);
                scanResults.ScanFound.WriteUsing("notFoundCount", 1);
                return(maybe);
            });

            World.Stage.MaybeActorOf <INoProtocol>(address7)
            .AndThen(maybe =>
            {
                Assert.False(maybe.IsPresent);
                scanResults.ScanFound.WriteUsing("notFoundCount", 1);
                return(maybe);
            });

            Assert.Equal(5, scanResults.ScanFound.ReadFrom <int>("foundCount"));
            Assert.Equal(2, scanResults.ScanFound.ReadFrom <int>("notFoundCount"));
        }
Esempio n. 2
0
        public void TestDirectoryScan()
        {
            var address1 = World.AddressFactory.UniqueWith("test-actor1");
            var address2 = World.AddressFactory.UniqueWith("test-actor2");
            var address3 = World.AddressFactory.UniqueWith("test-actor3");
            var address4 = World.AddressFactory.UniqueWith("test-actor4");
            var address5 = World.AddressFactory.UniqueWith("test-actor5");

            var address6 = World.AddressFactory.UniqueWith("test-actor6");
            var address7 = World.AddressFactory.UniqueWith("test-actor7");

            World.Stage.Directory.Register(address1, new TestInterfaceActor());
            World.Stage.Directory.Register(address2, new TestInterfaceActor());
            World.Stage.Directory.Register(address3, new TestInterfaceActor());
            World.Stage.Directory.Register(address4, new TestInterfaceActor());
            World.Stage.Directory.Register(address5, new TestInterfaceActor());

            var scanResults = new ScanResult();

            scanResults.AfterCompleting(7);

            Action <INoProtocol> afterConsumer = actor =>
            {
                Assert.NotNull(actor);
                scanResults.ScanFound.WriteUsing("foundCount", 1);
            };

            World.Stage.ActorOf <INoProtocol>(address5).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address4).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address3).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address2).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address1).AndThenConsume(afterConsumer);

            World.Stage.ActorOf <INoProtocol>(address6)
            .AndThen(null, actor =>
            {
                Assert.Null(actor);
                scanResults.ScanFound.WriteUsing("foundCount", 1);
                return(actor);
            })
            .Otherwise(noSuchActor =>
            {
                Assert.Null(noSuchActor);
                scanResults.ScanFound.WriteUsing("notFoundCount", 1);
                return(null);
            });
            World.Stage.ActorOf <INoProtocol>(address7)
            .AndThen(null, actor =>
            {
                Assert.Null(actor);
                scanResults.ScanFound.WriteUsing("foundCount", 1);
                return(actor);
            })
            .Otherwise(noSuchActor =>
            {
                Assert.Null(noSuchActor);
                scanResults.ScanFound.WriteUsing("notFoundCount", 1);
                return(null);
            });

            Assert.Equal(5, scanResults.ScanFound.ReadFrom <int>("foundCount"));
            Assert.Equal(2, scanResults.ScanFound.ReadFrom <int>("notFoundCount"));
        }