public CoordinatedShutdownShardingSpec(ITestOutputHelper helper) : base(SpecConfig, helper)
        {
            _sys1 = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
            _sys2 = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
            _sys3 = Sys;

            var props = Props.Create(() => new EchoActor());

            _region1 = ClusterSharding.Get(_sys1).Start("type1", props, ClusterShardingSettings.Create(_sys1),
                                                        _extractEntityId, _extractShard);
            _region2 = ClusterSharding.Get(_sys2).Start("type1", props, ClusterShardingSettings.Create(_sys2),
                                                        _extractEntityId, _extractShard);
            _region3 = ClusterSharding.Get(_sys3).Start("type1", props, ClusterShardingSettings.Create(_sys3),
                                                        _extractEntityId, _extractShard);


            _probe1 = CreateTestProbe(_sys1);
            _probe2 = CreateTestProbe(_sys2);
            _probe3 = CreateTestProbe(_sys3);

            CoordinatedShutdown.Get(_sys1).AddTask(CoordinatedShutdown.PhaseBeforeServiceUnbind, "unbind", () =>
            {
                _probe1.Ref.Tell("CS-unbind-1");
                return(Task.FromResult(Done.Instance));
            });

            CoordinatedShutdown.Get(_sys2).AddTask(CoordinatedShutdown.PhaseBeforeServiceUnbind, "unbind", () =>
            {
                _probe2.Ref.Tell("CS-unbind-2");
                return(Task.FromResult(Done.Instance));
            });

            CoordinatedShutdown.Get(_sys3).AddTask(CoordinatedShutdown.PhaseBeforeServiceUnbind, "unbind", () =>
            {
                _probe3.Ref.Tell("CS-unbind-3");
                return(Task.FromResult(Done.Instance));
            });
        }
Esempio n. 2
0
            public CancelStateTimeoutFsm(TestProbe p)
            {
                StartWith(OverrideInitState, "");

                When(OverrideInitState, evt =>
                {
                    if (evt.FsmEvent is StateTimeout)
                    {
                        p.Ref.Tell(StateTimeout.Instance);
                        return(Stay());
                    }

                    if (evt.FsmEvent.Equals(OverrideTimeoutToInf))
                    {
                        p.Ref.Tell(OverrideTimeoutToInf);
                        return(Stay().ForMax(TimeSpan.MaxValue));
                    }

                    return(null);
                }, 1.Seconds());

                Initialize();
            }
Esempio n. 3
0
        private static void DeviceGroupQuery_must_return_temperature_value_for_working_devices()
        {
            TestProbe requester = CreateTestProbe();
            TestProbe device1   = CreateTestProbe();
            TestProbe device2   = CreateTestProbe();
            TestKit   testKit   = new TestKit();
            Dictionary <IActorRef, string> actorToDeviceId = new Dictionary <IActorRef, string>
            {
                [device1.Ref] = "device1",
                [device2.Ref] = "device2"
            };
            TimeSpan  timeout    = TimeSpan.FromSeconds(3);
            Props     props      = DeviceGroupQuery.Props(actorToDeviceId, 1, requester.Ref, timeout);
            IActorRef queryActor = testKit.Sys.ActorOf(props);

            device1.ExpectMsg <ReadTemperature>(read => read.RequestId == 0);
            device2.ExpectMsg <ReadTemperature>(read => read.RequestId == 0);
            queryActor.Tell(new RespondTemperature(requestId: 0, value: 1.0), device1.Ref);
            queryActor.Tell(new RespondTemperature(requestId: 0, value: 2.0), device2.Ref);
            requester.ExpectMsg <RespondAllTemperatures>(msg =>
                                                         msg.Temperatures["device1"].AsInstanceOf <Temperature>().Value == 1.0 &&
                                                         msg.Temperatures["device2"].AsInstanceOf <Temperature>().Value == 2.0 &&
                                                         msg.RequestId == 1);
        }
Esempio n. 4
0
        public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart()
        {
            TestProbe subscriber = CreateTestProbe();
            var       mockWallet = new Mock <Wallet>();

            mockWallet.Setup(p => p.GetAccount(It.IsAny <UInt160>())).Returns <UInt160>(p => new TestWalletAccount(p));
            ConsensusContext context = new ConsensusContext(mockWallet.Object, TestBlockchain.GetStore());

            int timeIndex  = 0;
            var timeValues = new[] {
                //new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc), // For tests here
                new DateTime(1968, 06, 01, 0, 0, 1, DateTimeKind.Utc),                               // For receiving block
                new DateTime(1968, 06, 01, 0, 0, (int)Blockchain.SecondsPerBlock, DateTimeKind.Utc), // For Initialize
                new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc),                              // unused
                new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc)                               // unused
            };

            //TimeProvider.Current.UtcNow.ToTimestamp().Should().Be(4244941711); //1968-06-01 00:00:15

            Console.WriteLine($"time 0: {timeValues[0].ToString()} 1: {timeValues[1].ToString()} 2: {timeValues[2].ToString()} 3: {timeValues[3].ToString()}");

            var timeMock = new Mock <TimeProvider>();

            timeMock.SetupGet(tp => tp.UtcNow).Returns(() => timeValues[timeIndex])
            .Callback(() => timeIndex++);
            //new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc));
            TimeProvider.Current = timeMock.Object;

            //public void Log(string message, LogLevel level)
            // TODO: create ILogPlugin for Tests

            /*
             * mockConsensusContext.Setup(mr => mr.Log(It.IsAny<string>(), It.IsAny<LogLevel>()))
             *           .Callback((string message, LogLevel level) => {
             *                           Console.WriteLine($"CONSENSUS LOG: {message}");
             *                                                     }
             *                    );
             */

            // Creating proposed block
            Header header = new Header();

            TestUtils.SetupHeaderWithValues(header, UInt256.Zero, out UInt256 merkRootVal, out UInt160 val160, out uint timestampVal, out uint indexVal, out Witness scriptVal);
            header.Size.Should().Be(101);

            Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}");

            timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00
                                                  // check basic ConsensusContext
                                                  //mockConsensusContext.Object.block_received_time.ToTimestamp().Should().Be(4244941697); //1968-06-01 00:00:01

            // ============================================================================
            //                      creating ConsensusService actor
            // ============================================================================

            TestActorRef <ConsensusService> actorConsensus = ActorOfAsTestActorRef <ConsensusService>(
                Akka.Actor.Props.Create(() => (ConsensusService)Activator.CreateInstance(typeof(ConsensusService), BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { subscriber, subscriber, context }, null))
                );

            Console.WriteLine("will trigger OnPersistCompleted!");
            actorConsensus.Tell(new Blockchain.PersistCompleted
            {
                Block = new Block
                {
                    Version       = header.Version,
                    PrevHash      = header.PrevHash,
                    MerkleRoot    = header.MerkleRoot,
                    Timestamp     = header.Timestamp,
                    Index         = header.Index,
                    NextConsensus = header.NextConsensus
                }
            });

            // OnPersist will not launch timer, we need OnStart

            Console.WriteLine("will start consensus!");
            actorConsensus.Tell(new ConsensusService.Start
            {
                IgnoreRecoveryLogs = true
            });

            Console.WriteLine("OnTimer should expire!");
            Console.WriteLine("Waiting for subscriber message!");
            // Timer should expire in one second (block_received_time at :01, initialized at :02)

            var answer = subscriber.ExpectMsg <LocalNode.SendDirectly>();

            Console.WriteLine($"MESSAGE 1: {answer}");
            //var answer2 = subscriber.ExpectMsg<LocalNode.SendDirectly>(); // expects to fail!

            // ============================================================================
            //                      finalize ConsensusService actor
            // ============================================================================

            //Thread.Sleep(4000);
            Sys.Stop(actorConsensus);
            TimeProvider.ResetToDefault();

            Assert.AreEqual(1, 1);
        }
 public void Setup()
 {
     _csvWriterActor = CreateTestProbe();
     CreateStreamReader();
     _streamReaderFactory = new Mock <IStreamReaderFactory>();
 }
Esempio n. 6
0
 protected JournalPerfSpec(Config config, string actorSystem, ITestOutputHelper output)
     : base(config ?? Config.Empty, actorSystem, output)
 {
     testProbe = CreateTestProbe();
 }
Esempio n. 7
0
 internal ManualProbe(TestKitBase system, bool autoOnSubscribe = true)
 {
     _probe          = system.CreateTestProbe();
     AutoOnSubscribe = autoOnSubscribe;
 }
Esempio n. 8
0
 public static TestSinkStage <T, TMat> Create(GraphStageWithMaterializedValue <SinkShape <T>, TMat> stageUnderTest,
                                              TestProbe probe) => new TestSinkStage <T, TMat>(stageUnderTest, probe);
Esempio n. 9
0
 public static Source <T, TMat> Create(GraphStageWithMaterializedValue <SourceShape <T>, TMat> stageUnderTest,
                                       TestProbe probe) => Source.FromGraph(new TestSourceStage <T, TMat>(stageUnderTest, probe));
Esempio n. 10
0
 internal ManualProbe(TestKitBase testKit)
 {
     _testKit = testKit;
     _probe   = testKit.CreateTestProbe();
 }
Esempio n. 11
0
 public void Setup()
 {
     //배치가 컬렉션단위로 잘 수행하는지 관찰자 셋팅
     probe = this.CreateTestProbe();
 }
 public DirectoryTest()
 {
     probe  = this.CreateTestProbe();
     sender = probe.TestActor;
 }
Esempio n. 13
0
 private TestSinkStage <ByteString, Stream> TestSink(TestProbe probe)
 => TestSinkStage <ByteString, Stream> .Create(new InputStreamSinkStage(Timeout), probe);
Esempio n. 14
0
        public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart()
        {
            TestProbe subscriber = CreateTestProbe();

            var mockConsensusContext = new Mock <IConsensusContext>();
            var mockStore            = new Mock <Store>();

            // context.Reset(): do nothing
            //mockConsensusContext.Setup(mr => mr.Reset()).Verifiable(); // void
            mockConsensusContext.SetupGet(mr => mr.MyIndex).Returns(2); // MyIndex == 2
            mockConsensusContext.SetupGet(mr => mr.BlockIndex).Returns(2);
            mockConsensusContext.SetupGet(mr => mr.PrimaryIndex).Returns(2);
            mockConsensusContext.SetupGet(mr => mr.ViewNumber).Returns(0);
            mockConsensusContext.SetupProperty(mr => mr.Nonce);
            mockConsensusContext.SetupProperty(mr => mr.NextConsensus);
            mockConsensusContext.Object.NextConsensus = UInt160.Zero;
            mockConsensusContext.SetupGet(mr => mr.PreparationPayloads).Returns(new ConsensusPayload[7]);
            mockConsensusContext.SetupGet(mr => mr.CommitPayloads).Returns(new ConsensusPayload[7]);

            int timeIndex  = 0;
            var timeValues = new[] {
                //new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc), // For tests here
                new DateTime(1968, 06, 01, 0, 0, 1, DateTimeKind.Utc),                               // For receiving block
                new DateTime(1968, 06, 01, 0, 0, (int)Blockchain.SecondsPerBlock, DateTimeKind.Utc), // For Initialize
                new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc),                              // unused
                new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc)                               // unused
            };

            //TimeProvider.Current.UtcNow.ToTimestamp().Should().Be(4244941711); //1968-06-01 00:00:15

            Console.WriteLine($"time 0: {timeValues[0].ToString()} 1: {timeValues[1].ToString()} 2: {timeValues[2].ToString()} 3: {timeValues[3].ToString()}");

            //mockConsensusContext.Object.block_received_time = new DateTime(1968, 06, 01, 0, 0, 1, DateTimeKind.Utc);
            //mockConsensusContext.Setup(mr => mr.GetUtcNow()).Returns(new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc));

            var timeMock = new Mock <TimeProvider>();

            timeMock.SetupGet(tp => tp.UtcNow).Returns(() => timeValues[timeIndex])
            .Callback(() => timeIndex++);
            //new DateTime(1968, 06, 01, 0, 0, 15, DateTimeKind.Utc));
            TimeProvider.Current = timeMock.Object;

            //public void Log(string message, LogLevel level)
            // TODO: create ILogPlugin for Tests

            /*
             * mockConsensusContext.Setup(mr => mr.Log(It.IsAny<string>(), It.IsAny<LogLevel>()))
             *           .Callback((string message, LogLevel level) => {
             *                           Console.WriteLine($"CONSENSUS LOG: {message}");
             *                                                     }
             *                    );
             */

            // Creating proposed block
            Header header = new Header();

            TestUtils.SetupHeaderWithValues(header, UInt256.Zero, out UInt256 merkRootVal, out UInt160 val160, out uint timestampVal, out uint indexVal, out ulong consensusDataVal, out Witness scriptVal);
            header.Size.Should().Be(109);

            Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}");

            timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00
                                                  // check basic ConsensusContext
            mockConsensusContext.Object.MyIndex.Should().Be(2);
            //mockConsensusContext.Object.block_received_time.ToTimestamp().Should().Be(4244941697); //1968-06-01 00:00:01

            MinerTransaction minerTx = new MinerTransaction
            {
                Attributes = new TransactionAttribute[0],
                Inputs     = new CoinReference[0],
                Outputs    = new TransactionOutput[0],
                Witnesses  = new Witness[0],
                Nonce      = 42
            };

            PrepareRequest prep = new PrepareRequest
            {
                Nonce             = mockConsensusContext.Object.Nonce,
                NextConsensus     = mockConsensusContext.Object.NextConsensus,
                TransactionHashes = new UInt256[0],
                MinerTransaction  = minerTx //(MinerTransaction)Transactions[TransactionHashes[0]],
            };

            ConsensusPayload prepPayload = new ConsensusPayload
            {
                Version          = 0,
                PrevHash         = mockConsensusContext.Object.PrevHash,
                BlockIndex       = mockConsensusContext.Object.BlockIndex,
                ValidatorIndex   = (ushort)mockConsensusContext.Object.MyIndex,
                ConsensusMessage = prep
            };

            mockConsensusContext.Setup(mr => mr.MakePrepareRequest()).Returns(prepPayload);

            // ============================================================================
            //                      creating ConsensusService actor
            // ============================================================================

            TestActorRef <ConsensusService> actorConsensus = ActorOfAsTestActorRef <ConsensusService>(
                Akka.Actor.Props.Create(() => new ConsensusService(subscriber, subscriber, mockConsensusContext.Object))
                );

            Console.WriteLine("will trigger OnPersistCompleted!");
            actorConsensus.Tell(new Blockchain.PersistCompleted
            {
                Block = new Block
                {
                    Version       = header.Version,
                    PrevHash      = header.PrevHash,
                    MerkleRoot    = header.MerkleRoot,
                    Timestamp     = header.Timestamp,
                    Index         = header.Index,
                    ConsensusData = header.ConsensusData,
                    NextConsensus = header.NextConsensus
                }
            });

            // OnPersist will not launch timer, we need OnStart

            Console.WriteLine("will start consensus!");
            actorConsensus.Tell(new ConsensusService.Start());

            Console.WriteLine("OnTimer should expire!");
            Console.WriteLine("Waiting for subscriber message!");
            // Timer should expire in one second (block_received_time at :01, initialized at :02)

            var answer = subscriber.ExpectMsg <LocalNode.SendDirectly>();

            Console.WriteLine($"MESSAGE 1: {answer}");
            //var answer2 = subscriber.ExpectMsg<LocalNode.SendDirectly>(); // expects to fail!

            // ============================================================================
            //                      finalize ConsensusService actor
            // ============================================================================

            //Thread.Sleep(4000);
            Sys.Stop(actorConsensus);
            TimeProvider.ResetToDefault();

            Assert.AreEqual(1, 1);
        }
Esempio n. 15
0
        public static async Task ExpectTerminatedAsync <T>(this TestProbe testProbe, IActorRef actorRef, string hint = null)
        {
            await testProbe.Sys.Idle();

            testProbe.ExpectTerminated(actorRef, TimeSpan.Zero, hint);
        }
Esempio n. 16
0
 public PersistentActorJournalProtocolSpec() : base(Config)
 {
     _journal = JournalProbeExtension.Instance.Apply(Sys).Probe;
 }
 public TestClusterHeartbeatSender(TestProbe probe)
 {
     _probe = probe;
 }
Esempio n. 18
0
 private void SubscribeToReplay(TestProbe probe)
 {
     Sys.EventStream.Subscribe(probe.Ref, typeof(ReplayMessages));
 }
Esempio n. 19
0
 private TestSourceStage(GraphStageWithMaterializedValue <SourceShape <T>, TMat> stageUnderTest, TestProbe probe)
 {
     _stageUnderTest = stageUnderTest;
     _probe          = probe;
     Shape           = new SourceShape <T>(_out);
 }
Esempio n. 20
0
 public DebugSniffer(TestProbe testProbe)
 {
     _testProbe = testProbe;
 }
Esempio n. 21
0
 private TestSinkStage(GraphStageWithMaterializedValue <SinkShape <T>, TMat> stageUnderTest, TestProbe probe)
 {
     _stageUnderTest = stageUnderTest;
     _probe          = probe;
     Shape           = new SinkShape <T>(_in);
 }
 private void RequestPermit(TestProbe probe)
 {
     permitter.Tell(RequestRecoveryPermit.Instance, probe.Ref);
     probe.ExpectMsg <RecoveryPermitGranted>();
 }
Esempio n. 23
0
        public void Pruning_of_durable_CRDT_should_move_data_from_removed_node()
        {
            Join(first, first);
            Join(second, first);

            var sys2        = ActorSystem.Create(Sys.Name, Sys.Settings.Config);
            var cluster2    = Akka.Cluster.Cluster.Get(sys2);
            var replicator2 = StartReplicator(sys2);
            var probe2      = new TestProbe(sys2, new XunitAssertions());

            cluster2.Join(Node(first).Address);

            Within(TimeSpan.FromSeconds(5), () => AwaitAssert(() =>
            {
                replicator.Tell(Dsl.GetReplicaCount);
                ExpectMsg(new ReplicaCount(4));
                replicator2.Tell(Dsl.GetReplicaCount, probe2.Ref);
                probe2.ExpectMsg(new ReplicaCount(4));
            }));

            replicator.Tell(Dsl.Update(keyA, GCounter.Empty, WriteLocal.Instance, c => c.Increment(cluster)));
            ExpectMsg(new UpdateSuccess(keyA, null));

            replicator2.Tell(Dsl.Update(keyA, GCounter.Empty, WriteLocal.Instance, c => c.Increment(cluster2, 2)), probe2.Ref);
            probe2.ExpectMsg(new UpdateSuccess(keyA, null));

            EnterBarrier("updates-done");

            Within(TimeSpan.FromSeconds(10), () => AwaitAssert(() =>
            {
                replicator.Tell(Dsl.Get(keyA, new ReadAll(TimeSpan.FromSeconds(1))));
                var counter1 = ExpectMsg <GetSuccess>().Get(keyA);
                counter1.Value.ShouldBe(10UL);
                counter1.State.Count.ShouldBe(4);
            }));

            Within(TimeSpan.FromSeconds(10), () => AwaitAssert(() =>
            {
                replicator2.Tell(Dsl.Get(keyA, new ReadAll(TimeSpan.FromSeconds(1))), probe2.Ref);
                var counter2 = probe2.ExpectMsg <GetSuccess>().Get(keyA);
                counter2.Value.ShouldBe(10UL);
                counter2.State.Count.ShouldBe(4);
            }));
            EnterBarrier("get1");

            RunOn(() => cluster.Leave(cluster2.SelfAddress), first);

            Within(TimeSpan.FromSeconds(15), () => AwaitAssert(() =>
            {
                replicator.Tell(Dsl.GetReplicaCount);
                ExpectMsg(new ReplicaCount(3));
            }));
            EnterBarrier("removed");

            RunOn(() => sys2.Terminate().Wait(TimeSpan.FromSeconds(5)), first);

            Within(TimeSpan.FromSeconds(15), () =>
            {
                var values = ImmutableHashSet <int> .Empty;
                AwaitAssert(() =>
                {
                    replicator.Tell(Dsl.Get(keyA, ReadLocal.Instance));
                    var counter3 = ExpectMsg <GetSuccess>().Get(keyA);
                    var value    = counter3.Value;
                    values       = values.Add((int)value);
                    value.ShouldBe(10UL);
                    counter3.State.Count.ShouldBe(3);
                });
                values.ShouldBe(ImmutableHashSet.Create(10));
            });
            EnterBarrier("prunned");

            RunOn(() =>
            {
                var addr        = cluster2.SelfAddress;
                var sys3        = ActorSystem.Create(Sys.Name, ConfigurationFactory.ParseString(@"
                ").WithFallback(Sys.Settings.Config));
                var cluster3    = Akka.Cluster.Cluster.Get(sys3);
                var replicator3 = StartReplicator(sys3);
                var probe3      = new TestProbe(sys3, new XunitAssertions());
                cluster3.Join(Node(first).Address);

                Within(TimeSpan.FromSeconds(10), () =>
                {
                    var values = ImmutableHashSet <int> .Empty;
                    AwaitAssert(() =>
                    {
                        replicator3.Tell(Dsl.Get(keyA, ReadLocal.Instance), probe3.Ref);
                        var counter4 = probe3.ExpectMsg <GetSuccess>().Get(keyA);
                        var value    = counter4.Value;
                        values.Add((int)value);
                        value.ShouldBe(10UL);
                        counter4.State.Count.ShouldBe(3);
                    });
                    values.ShouldBe(ImmutableHashSet.Create(10));
                });

                // after merging with others
                replicator3.Tell(Dsl.Get(keyA, new ReadAll(RemainingOrDefault)));
                var counter5 = ExpectMsg <GetSuccess>().Get(keyA);
                counter5.Value.ShouldBe(10UL);
                counter5.State.Count.ShouldBe(3);
            }, first);
            EnterBarrier("sys3-started");

            replicator.Tell(Dsl.Get(keyA, new ReadAll(RemainingOrDefault)));
            var counter6 = ExpectMsg <GetSuccess>().Get(keyA);

            counter6.Value.ShouldBe(10UL);
            counter6.State.Count.ShouldBe(3);

            EnterBarrier("after-1");
        }
Esempio n. 24
0
        public TestBase() : base(AkkaConfig.Config)
        {
            Func <Type> generateType = TestHelper.GetRandomTypeGenerator();

            // Create mocks
            SutCreatorMock                       = new Mock <ISutCreator>();
            TellWaiterMock                       = new Mock <ITellWaiter>();
            ChildWaiterMock                      = new Mock <IWaiter>();
            ExceptionWaiterMock                  = new Mock <IWaiter>();
            DependencyResolverAdderMock          = new Mock <IDependencyResolverAdder>();
            TestProbeDependencyResolverAdderMock = new Mock <ITestProbeDependencyResolverAdder>();
            ResolvedTestProbeStoreMock           = new Mock <IResolvedTestProbeStore>();
            TestProbeChildActorCreatorMock       = new Mock <ITestProbeChildActorCreator>();
            TestProbeCreatorMock                 = new Mock <ITestProbeCreator>();
            TestProbeHandlersMapperMock          = new Mock <ITestProbeChildHandlersMapper>();
            TestProbeChildActorMock              = new Mock <ITestProbeChildActor>();
            SutSupervisorStrategyGetterMock      = new Mock <ISutSupervisorStrategyGetter>();
            TestProbeParentActorCreatorMock      = new Mock <ITestProbeParentActorCreator>();
            TestProbeParentActorMock             = new Mock <ITestProbeParentActor>();
            DelayerMock = new Mock <IDelayer>();

            // Create objects passed into sut constructor
            SutCreator                       = SutCreatorMock.Object;
            TellWaiter                       = TellWaiterMock.Object;
            ChildWaiter                      = ChildWaiterMock.Object;
            ExceptionWaiter                  = ChildWaiterMock.Object;
            DependencyResolverAdder          = DependencyResolverAdderMock.Object;
            TestProbeDependencyResolverAdder = TestProbeDependencyResolverAdderMock.Object;
            TestProbeCreator                 = TestProbeCreatorMock.Object;
            ResolvedTestProbeStore           = ResolvedTestProbeStoreMock.Object;
            TestProbeChildActorCreator       = TestProbeChildActorCreatorMock.Object;
            TestProbeHandlersMapper          = TestProbeHandlersMapperMock.Object;
            SutSupervisorStrategyGetter      = SutSupervisorStrategyGetterMock.Object;
            TestProbeParentActorCreator      = TestProbeParentActorCreatorMock.Object;
            Delayer        = DelayerMock.Object;
            ParentHandlers = ImmutableDictionary <Type, Func <object, object> >
                             .Empty
                             .Add((generateType()), message => TestHelper.Generate <object>());

            ChildHandlers = ImmutableDictionary <(Type, Type), Func <object, object> >
                            .Empty
                            .Add((generateType(), generateType()), message => TestHelper.Generate <object>());

            Decider = exception => TestHelper.GenerateEnum <Directive>();
            Props   = Props.Create <DummyActor>();
            PropsWithSupervisorStrategy = Props
                                          .Create <DummyActor>()
                                          .WithSupervisorStrategy(new AllForOneStrategy(
                                                                      TestHelper.GenerateNumber(),
                                                                      TestHelper.GenerateNumber(),
                                                                      exception => TestHelper.Generate <Directive>()));
            ExpectedChildCount     = TestHelper.GenerateNumber();
            ExpectedExceptionCount = TestHelper.GenerateNumber();

            // Create objects passed into sut methods
            Message   = TestHelper.Generate <object>();
            ChildName = TestHelper.GenerateString();
            ChildNameWithoutSupervisor = TestHelper.GenerateString();
            Sender        = new Mock <IActorRef>().Object;
            DelayDuration = TestHelper.Generate <TimeSpan>();

            // Create objects returned by mocks
            MappedChildHandlers = ImmutableDictionary <Type, ImmutableDictionary <Type, Func <object, object> > >
                                  .Empty
                                  .Add(generateType(), ImmutableDictionary <Type, Func <object, object> >
                                       .Empty
                                       .Add(generateType(), mess => TestHelper.Generate <object>()));

            SutActor                   = ActorOfAsTestActorRef <DummyActor>();
            ResolvedType               = generateType();
            ResolvedTestProbe          = CreateTestProbe();
            ResolvedSupervisorStrategy = new AllForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());
            SutSupervisorStrategy = new OneForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());
            TestProbeParentActor                    = TestProbeParentActorMock.Object;
            TestProbeParentActorTestProbe           = CreateTestProbe();
            TestProbeParentActorRef                 = TestProbeParentActorTestProbe.Ref;
            TestProbeParentActorUnhandledExceptions = TestHelper.GenerateMany <Exception>(() => TestHelper.GenerateException());

            // Set up mocks
            TestProbeParentActorMock
            .SetupGet(actor => actor.Ref)
            .Returns(TestProbeParentActorRef);
            TestProbeParentActorMock
            .SetupGet(actor => actor.TestProbe)
            .Returns(TestProbeParentActorTestProbe);
            TestProbeParentActorMock
            .SetupGet(actor => actor.UnhandledExceptions)
            .Returns(TestProbeParentActorUnhandledExceptions);

            TestProbeParentActorCreatorMock
            .SetupSequence(creator => creator.Create(TestProbeCreator, ExceptionWaiter, this, Decider, ParentHandlers))
            .Returns(TestProbeParentActor)
            .Returns(Mock.Of <ITestProbeParentActor>());

            SutCreatorMock
            .Setup(creator => creator.Create <DummyActor>(
                       ChildWaiterMock.Object,
                       this,
                       Props,
                       ExpectedChildCount,
                       TestProbeParentActorRef))
            .Returns(() => SutActor);

            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedType(SutActor, ChildName))
            .Returns(() => ResolvedType);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedTestProbe(SutActor, ChildName))
            .Returns(() => ResolvedTestProbe);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildName))
            .Returns(() => ResolvedSupervisorStrategy);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildNameWithoutSupervisor))
            .Returns(() => null);

            TestProbeHandlersMapperMock
            .Setup(mapper => mapper.Map(ChildHandlers))
            .Returns(() => MappedChildHandlers);

            SutSupervisorStrategyGetterMock
            .Setup(getter => getter.Get(SutActor.UnderlyingActor))
            .Returns(() => SutSupervisorStrategy);
        }
Esempio n. 25
0
 public PublisherProbeSubscription(ISubscriber <T> subscriber, TestProbe publisherProbe)
 {
     Subscriber     = subscriber;
     PublisherProbe = publisherProbe;
 }
Esempio n. 26
0
 protected SnapshotStoreSpec(Config config = null, string actorSystemName = null, string testActorName = null)
     : base(FromConfig(config).WithFallback(Config), actorSystemName ?? "SnapshotStoreSpec", testActorName)
 {
     _senderProbe = CreateTestProbe();
 }
Esempio n. 27
0
 protected SnapshotStoreSpec(Config config = null, string actorSystemName = null, ITestOutputHelper output = null)
     : base(FromConfig(config).WithFallback(Config), actorSystemName ?? "SnapshotStoreSpec", output)
 {
     _senderProbe = CreateTestProbe();
 }
Esempio n. 28
0
        public TestBase() : base(AkkaConfig.Config)
        {
            Func <Type> generateType = TestUtils.RandomTypeGenerator();

            // Create mocks
            SutCreatorMock                       = new Mock <ISutCreator>();
            ChildTellerMock                      = new Mock <ITellChildWaiter>();
            ChildWaiterMock                      = new Mock <IChildWaiter>();
            DependencyResolverAdderMock          = new Mock <IDependencyResolverAdder>();
            TestProbeDependencyResolverAdderMock = new Mock <ITestProbeDependencyResolverAdder>();
            ResolvedTestProbeStoreMock           = new Mock <IResolvedTestProbeStore>();
            TestProbeActorCreatorMock            = new Mock <ITestProbeActorCreator>();
            TestProbeCreatorMock                 = new Mock <ITestProbeCreator>();
            TestProbeHandlersMapperMock          = new Mock <ITestProbeHandlersMapper>();
            TestProbeActorMock                   = new Mock <ITestProbeActor>();
            SutSupervisorStrategyGetterMock      = new Mock <ISutSupervisorStrategyGetter>();

            // Create objects passed into sut constructor
            SutCreator                       = SutCreatorMock.Object;
            ChildTeller                      = ChildTellerMock.Object;
            ChildWaiter                      = ChildWaiterMock.Object;
            DependencyResolverAdder          = DependencyResolverAdderMock.Object;
            TestProbeDependencyResolverAdder = TestProbeDependencyResolverAdderMock.Object;
            TestProbeCreator                 = TestProbeCreatorMock.Object;
            ResolvedTestProbeStore           = ResolvedTestProbeStoreMock.Object;
            TestProbeActorCreator            = TestProbeActorCreatorMock.Object;
            TestProbeHandlersMapper          = TestProbeHandlersMapperMock.Object;
            SutSupervisorStrategyGetter      = SutSupervisorStrategyGetterMock.Object;
            Handlers = ImmutableDictionary <(Type, Type), Func <object, object> >
                       .Empty
                       .Add((generateType(), generateType()), message => TestUtils.Create <object>());

            Props = Props.Create <DummyActor>();
            PropsWithSupervisorStrategy = Props
                                          .Create <DummyActor>()
                                          .WithSupervisorStrategy(new AllForOneStrategy(
                                                                      TestUtils.Create <int>(),
                                                                      TestUtils.Create <int>(),
                                                                      exception => TestUtils.Create <Directive>()));
            ExpectedChildCount = TestUtils.Create <int>();

            // Create objects passed into sut methods
            Message   = TestUtils.Create <object>();
            ChildName = TestUtils.Create <string>();
            ChildNameWithoutSupervisor = TestUtils.Create <string>();
            Sender = new Mock <IActorRef>().Object;

            // Create objects returned by mocks
            MappedHandlers = ImmutableDictionary <Type, ImmutableDictionary <Type, Func <object, object> > >
                             .Empty
                             .Add(generateType(), ImmutableDictionary <Type, Func <object, object> >
                                  .Empty
                                  .Add(generateType(), mess => TestUtils.Create <object>()));

            Supervisor                 = CreateTestProbe();
            SutActor                   = ActorOfAsTestActorRef <DummyActor>();
            ResolvedType               = generateType();
            ResolvedTestProbe          = CreateTestProbe();
            ResolvedSupervisorStrategy = new AllForOneStrategy(
                TestUtils.Create <int>(),
                TestUtils.Create <int>(),
                exception => TestUtils.Create <Directive>());
            SutSupervisorStrategy = new OneForOneStrategy(
                TestUtils.Create <int>(),
                TestUtils.Create <int>(),
                exception => TestUtils.Create <Directive>());

            // Set up mocks
            TestProbeCreatorMock
            .SetupSequence(creator => creator.Create(this))
            .Returns(Supervisor)
            .Returns(CreateTestProbe());

            SutCreatorMock
            .Setup(creator => creator.Create <DummyActor>(
                       ChildWaiterMock.Object,
                       this,
                       Props,
                       ExpectedChildCount,
                       Supervisor))
            .Returns(() => SutActor);

            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedType(SutActor, ChildName))
            .Returns(() => ResolvedType);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedTestProbe(SutActor, ChildName))
            .Returns(() => ResolvedTestProbe);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildName))
            .Returns(() => ResolvedSupervisorStrategy);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildNameWithoutSupervisor))
            .Returns(() => null);

            TestProbeHandlersMapperMock
            .Setup(mapper => mapper.Map(Handlers))
            .Returns(() => MappedHandlers);

            SutSupervisorStrategyGetterMock
            .Setup(getter => getter.Get(SutActor.UnderlyingActor))
            .Returns(() => SutSupervisorStrategy);
        }
Esempio n. 29
0
 public ServerConnection(TestKitBase testkit, IActorRef connectionActor)
 {
     _connectionActor = connectionActor;
     _connectionProbe = testkit.CreateTestProbe();
 }
Esempio n. 30
0
 public JournalProbe(ExtendedActorSystem system)
 {
     Probe = new TestProbe(system, new XunitAssertions());
     Ref   = Probe.Ref;
 }