コード例 #1
0
        public void Test1(int cutoffSec, int elemntPerSec)
        {
            var throttleWork = Sys.ActorOf(Props.Create(() => new ThrottleWork(elemntPerSec, timeSec)));

            // 밸브에게 작업자 지정 ( 밸브는 초당 스트림을 모아서 방출한다 )
            // 작업자는 방류된 스트림을 기본적으로 쌓아두고, 초당 지정된 개수만 처리한다.
            throttleActor.Tell(new SetTarget(throttleWork));

            // 소비자지정 : 소비자는 몇개가 초당 처리되던 상관없이, 완료된 작업만 제공받는다.
            throttleWork.Tell(new SetTarget(probe));

            Within(TimeSpan.FromSeconds(cutoffSec), () =>
            {
                // 50개 처리완료는 10초이내에 끝나야함...
                for (int i = 0; i < 50; i++)
                {
                    string seq = (i + 1).ToString();
                    throttleActor.Tell(new Queue(new DelayMsg()
                    {
                        Delay   = 0,
                        Seq     = seq,
                        Message = $"초당:{elemntPerSec} 테스트-{seq}",
                        State   = DelayMsgState.Reserved
                    }));
                }

                DelayMsg lastMessage = null;
                for (int i = 0; i < 50; i++)
                {
                    lastMessage = probe.ExpectMsg <DelayMsg>();
                }
                //마지막 메시지의 Seq는 50이여야함
                Assert.Equal("50", lastMessage.Seq);
            });
        }
コード例 #2
0
        public string CashgateAsk(string value)
        {
            var delayMsg = new DelayMsg
            {
                Delay   = 0,
                Message = value
            };
            var result = cashPassActor.Ask <string>(delayMsg).Result;

            return(result);
        }
コード例 #3
0
 public void Cashgate(string value, int count, int delay)
 {
     for (int i = 0; i < count; i++)
     {
         var delayMsg = new DelayMsg
         {
             Seq     = Guid.NewGuid().ToString(),
             Delay   = delay,
             Message = value
         };
         cashPassActor.Tell(delayMsg);
     }
 }
コード例 #4
0
 public void ThrottleTell(string value, int count)
 {
     for (int i = 0; i < count; i++)
     {
         var delayMsg = new DelayMsg
         {
             Seq     = Guid.NewGuid().ToString(),
             Delay   = 1,
             Message = $"{value} -Seq:{i}",
             State   = DelayMsgState.Reserved,
         };
         throttleActor.Tell(new Queue(delayMsg));
     }
 }
コード例 #5
0
 public void Cluster(string value, int count, int delay)
 {
     for (int i = 0; i < count; i++)
     {
         var delayMsg = new DelayMsg
         {
             Seq     = Guid.NewGuid().ToString(),
             Delay   = delay,
             Message = value,
             State   = DelayMsgState.Reserved
         };
         singleToneActor.Tell(delayMsg);
         clusterRoundbin1.Tell(delayMsg);
     }
 }
コード例 #6
0
        public void Highpassgate(string value, int count, int delay)
        {
            for (int i = 0; i < count; i++)
            {
                var delayMsg = new DelayMsg
                {
                    Seq     = Guid.NewGuid().ToString(),
                    Delay   = delay,
                    Message = value,
                    State   = DelayMsgState.Reserved,
                };

                singleToneActor.Tell(delayMsg);
                highPassActor.Tell(delayMsg);
            }
        }
コード例 #7
0
ファイル: ActorBaseTest.cs プロジェクト: psmon/AkkaForNetCore
        public void Test2(int delay, int cutoff)
        {
            var cashGate = Sys.ActorOf(Props.Create(() => new CashGateActor()));

            // sets a maximum allowable time for entire block to finish
            Within(TimeSpan.FromMilliseconds(cutoff), () =>
            {
                var msg = new DelayMsg()
                {
                    Delay   = delay,
                    Message = "정산해주세요"
                };
                cashGate.Tell(msg);
                ExpectMsg("정산완료 통과하세요");
            });
        }
コード例 #8
0
        public HighPassGateActor()
        {
            id = Guid.NewGuid().ToString();
            logger.Info($"Create HigPassGateActor:{id}");
            msgCnt            = 0;
            random            = new Random();
            MatrixSingleActor = AkkaLoad.ActorSelect("SingleToneActor");

            ReceiveAsync <DelayMsg>(async msg =>
            {
                if (MonitorMode)
                {
                    Context.IncrementMessagesReceived();
                }

                msgCnt++;

                int auto_delay = msg.Delay == 0 ? random.Next(1, 100) : msg.Delay;
                await Task.Delay(auto_delay);

                var completeMsg = new DelayMsg()
                {
                    State   = DelayMsgState.Completed,
                    Message = msg.Message,
                    Seq     = msg.Seq
                };

                MatrixSingleActor.Tell(completeMsg);

                if (MonitorMode)
                {
                    Context.IncrementCounter("akka.custom.received1");
                }

                logger.Info($"Msg:{msg.Message} Count:{msgCnt} Delay:{auto_delay}");
            });
        }