Пример #1
0
        public AsyncTestDeDuplicatingActor(DeDuplicatingReceiverSettings settings, string persistenceId) : base(settings)
        {
            PersistenceId = persistenceId ?? Uri.EscapeUriString(Self.Path.ToStringWithoutAddress());

            CommandAsync <TestDeDuplicatingActor.ConfirmableMsg>(async c =>
            {
                _log.Info("async Received {0}", c);
                await Task.Delay(10);
                ReceivedMessages.Add(c.Msg);
                ConfirmAndReply(c);
                _log.Info("await Confirmed {0}", c);
            });

            Command <string>(str => str.Equals("crash"), str => { Crash(); });

            Command <string>(str => str.Equals("canConfirm"), str => { Sender.Tell(IsCurrentMessageConfirmable); });

            CommandAsync <string>(async str =>
            {
                _log.Info("async Received {0}", str);
                await Task.Delay(10);
                if (IsCurrentMessageConfirmable)
                {
                    ReceivedMessages.Add(str);
                    ConfirmAndReply(str);
                }
                _log.Info("await Processed {0}", str);
            });
        }
        public void DefaultDeDuplicatingReceiverSettings_should_be_as_Expected()
        {
            var setting = new DeDuplicatingReceiverSettings();

            setting.PruneInterval.Should().Be(TimeSpan.FromMinutes(30));
            setting.BufferSizePerSender.Should().Be(1000);
            setting.TakeSnapshotEveryNMessages.Should().Be(100);
            setting.ReceiverType.Should().Be(ReceiveOrdering.AnyOrder);
        }
        public void DeDuplicatingReceiverSettings_should_reject_illegal_PruneIntervals(TimeSpan pruneInterval,
                                                                                       bool shouldThrow)
        {
            Action createSettings = () =>
            {
                var settings = new DeDuplicatingReceiverSettings(ReceiveOrdering.AnyOrder, pruneInterval, 1000, 100);
            };

            if (shouldThrow)
            {
                createSettings.Should().Throw <ArgumentOutOfRangeException>();
            }
            else
            {
                createSettings.Should().NotThrow();
            }
        }
        public void DeDuplicatingReceiverSettings_should_reject_illegal_BufferSizeValues(int bufferSize,
                                                                                         bool shouldThrow)
        {
            Action createSettings = () =>
            {
                var settings = new DeDuplicatingReceiverSettings(ReceiveOrdering.AnyOrder, TimeSpan.FromMinutes(30),
                                                                 bufferSize, 100);
            };

            if (shouldThrow)
            {
                createSettings.Should().Throw <ArgumentOutOfRangeException>();
            }
            else
            {
                createSettings.Should().NotThrow();
            }
        }
        public TestDeDuplicatingActor(DeDuplicatingReceiverSettings settings, string persistenceId) : base(settings)
        {
            PersistenceId = persistenceId ?? Uri.EscapeUriString(Self.Path.ToStringWithoutAddress());

            Command <ConfirmableMsg>(c =>
            {
                CounterValue++;
                ConfirmAndReply(c);
            });

            Command <string>(str => str.Equals("getCounter"), str => { Sender.Tell(CounterValue); });

            Command <string>(str =>
            {
                if (IsCurrentMessageConfirmable)
                {
                    CounterValue++;
                    ConfirmAndReply(str);
                }
            });
        }
        public TestDeDuplicatingActor(DeDuplicatingReceiverSettings settings, string persistenceId) : base(settings)
        {
            PersistenceId = persistenceId ?? Uri.EscapeUriString(Self.Path.ToStringWithoutAddress());

            Command <ConfirmableMsg>(c =>
            {
                ReceivedMessages.Add(c.Msg);
                ConfirmAndReply(c);
            });

            Command <string>(str => str.Equals("crash"), str => { Crash(); });

            Command <string>(str => str.Equals("canConfirm"), str => { Sender.Tell(IsCurrentMessageConfirmable); });

            Command <string>(str =>
            {
                if (IsCurrentMessageConfirmable)
                {
                    ReceivedMessages.Add(str);
                    ConfirmAndReply(str);
                }
            });
        }