首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当测试从测试参与者发送的混乱时,akkaNet测试工具包会发出问题

当测试从测试参与者发送的混乱时,akkaNet测试工具包会发出问题
EN

Stack Overflow用户
提问于 2016-02-12 16:29:20
回答 2查看 644关注 0票数 1

我试着测试被测试的演员发送的消息,但是得到超时异常和一个死信信息。由于我使用的是ninject创建的模拟方法,它总是与探测参与者引用一起重放。我是不是漏掉了什么?

AutoApply.UnitTests.SomethingProcessorActors.SomethingProcessorActorTests.SomethingProcessorActorWhenMergeDataAndGetsNoProfilesLogsThat() in Assert.Fail failed. Failed: Timeout 00:00:03 while waiting for a message of type System.Type at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope(Nullable`1 timeout, Action`2 assert, String hint, Boolean shouldLog) at Akka.TestKit.TestKitBase.InternalExpectMsgEnvelope(Nullable`1 timeout, Action`1 msgAssert, Action`1 senderAssert, String hint) at Akka.TestKit.TestKitBase.InternalExpectMsg(Nullable`1 timeout, Action`1 msgAssert, String hint) at Akka.TestKit.TestKitBase.ExpectMsg(T message, Nullable`1 timeout, String hint) at SomethingProcessorActorTests.cs:第58行 来自akka的WARNINGThread 0009 DeadLetter ://test/temp/d 到akka://test/user/testProbe: INFOThread 0011消息GetOneSomethingAndRemoveFromList ://test/temp/d到akka://test/user/testProbe没有传递。遇到1封死信。调试跟踪:设置探测引用: akka://test/user/testProbe GetDataActorPath for:SomethingsDataActor GetDataActorPath =>akka://test/user/testProbe GetDataActorPath for:SomethingCollectorActor GetDataActorPath =>akka://test/user/testProbe

代码语言:javascript
运行
复制
    [TestClass]
    public class SomethingProcessorActorTests : TestKit
    {
        /// <summary>The factory helper</summary>
        private IMockingExtension factoryHelper;

        private TestProbe probeActorRef;

        /// <summary>Configurations this instance.</summary>
        [TestInitialize]
        public void Config()
        {

            this.probeActorRef = this.CreateTestProbe("testProbe");
            this.factoryHelper = new MockingFactoryHelper();
            this.factoryHelper.SetProbe(this.probeActorRef.TestActor);
        }

        /// <summary>Somethings the processor actor when merge data and gets no profiles logs that.</summary>
        [TestMethod]
        public void SomethingProcessorActorWhenMergeDataAndGetsNoProfilesLogsThat()
        {
            // arrange
            var actor =
                this.Sys.ActorOf(
                    Props.Create(() => new SomethingProcessorActor(this.factoryHelper as IActorPathAndFactory)),
                    "SomethingActor");

            // act
            actor.Tell(new SomethingProcessorActor.ProcessSomethings());

            // assert
            this.probeActorRef.ExpectMsgFrom<SomethingsDataActor.GetOneSomethingAndRemoveFromList>(actor, new TimeSpan(0, 0, 0, 5));

        }
    }
    =======================
 public partial class SomethingProcessorActor : ReceiveActor
{
    /// <summary>The helper</summary>
    private readonly IActorPathAndFactory helper;

    /// <summary>The log</summary>
    private readonly ILoggingAdapter log = Context.GetLogger();

    /// <summary>The vote execution profile</summary>
    private List<SomethingProcessingObject> voteExecutionProfile = new List<SomethingProcessingObject>();

    /// <summary>
    /// Initializes a new instance of the <see cref="SomethingProcessorActor"/> class.
    /// </summary>
    /// <param name="helper">
    /// The helper.
    /// </param>
    public SomethingProcessorActor(IActorPathAndFactory helper)
    {
        this.helper = helper;
        this.Receive<ProcessSomethings>(
            x =>
                {
                    this.log.Debug("Received: ProcessSomethings");
                    this.BecomeStacked(this.Working);
                    this.RetriveSomethingAndPushForProcessing();
                });
    }



    /// <summary>Supervisors strategy.</summary>
    /// <returns>Supervisors strategy for that actor</returns>
    protected override SupervisorStrategy SupervisorStrategy()
    {
        return new AllForOneStrategy(10, 3000, Decider.From(x => Directive.Stop));
    }



    /// <summary>
    /// The merge data.
    /// </summary>
    private void RetriveSomethingAndPushForProcessing()
    {
     this.log.Debug($"Processing Somethings...");
        var SomethingActor1 = this.helper.GetActorPath(ActorsEnum.SomethingsDataActor);
        var SomethingActor2 =  this.helper.GetActorPath(ActorsEnum.SomethingCollectorActor);
        var something = (SomethingDto)SomethingActor1.Ask(new SomethingsDataActor.GetOneSomethingAndRemoveFromList()).Result;

        while (Something.SomethingId>0)
        {
            this.log.Debug($"Sending data to SomethingCollector with Something id: {Something.SomethingId}");
            SomethingActor2.Tell(new SomethingCollectorActor.ProcessSomethingDto(Something));
            Something = (SomethingDto)SomethingActor1.Ask(new SomethingsDataActor.GetOneSomethingAndRemoveFromList()).Result;
        }

        this.log.Debug("Sending data to SomethingCollector -- ALL SENT");
        this.UnbecomeStacked();
    }

The mock objects just send probe actor as per every request

    public ActorSelection GetActorPath(ActorsEnum actorsEnum)
            {
                Debug.WriteLine("GetDataActorPath for:" + actorsEnum);
                Debug.WriteLine("GetDataActorPath =>" + this.probeRef.Path);

                return this.Sys.ActorSelection(this.probeRef.Path);
            }

            public void SetProbe(IActorRef actorRef)
            {
                Debug.WriteLine("Setting probe reference: " + actorRef.Path);
                this.probeRef = actorRef;
            }

点火概述

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-12 17:41:11

好吧,那么有几件事。

首先:您期待的是类型为:SomethingsDataActor.GetOneSomethingAndRemoveFromList的消息。但是,看起来您并没有实际将此消息传递给一个由test探头表示的actorref。但是很难确定,因为你只粘贴了一半的代码。

第二:

  • 在演员内部使用ask被认为是一种反模式,可以通过使用更多的对话式的交流方式来避免。
  • 使用actor.ask().Result更糟糕,因为如果您不小心的话,它会导致死锁。(当数据库参与者由于网络中断而崩溃时会发生什么情况?可能永远不会发送任何响应,默认的问询超时是无限的)

“询问”应该只用于与演员系统之外的演员交流。

票数 1
EN

Stack Overflow用户

发布于 2016-02-15 15:52:38

问题是模仿类继承了TestClass,

决定要有“演员制度参考”

代码语言:javascript
运行
复制
 return this.Sys.ActorSelection(this.probeRef.Ref.Path);

但应该是:

代码语言:javascript
运行
复制
return this.probeRef.ActorSelection(this.probeRef.Ref.Path);

这个继承正在创建第二个独立的演员系统……

谢谢你的帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35367570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档