예제 #1
0
        public void TestClose()
        {
            const int mailboxSize = 64;
            var       testResults = new TestResults(mailboxSize);
            var       dispatcher  = new RingBufferDispatcher(mailboxSize, 2, false, 4);

            dispatcher.Start();
            var mailbox = dispatcher.Mailbox;
            var actor   = new CountTakerActor(testResults);

            for (var count = 1; count <= mailboxSize; ++count)
            {
                var countParam = count;
                Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam);
                mailbox.Send(actor, consumer, null, "Take(int)");
            }


            Assert.Equal(mailboxSize, testResults.GetHighest());
            dispatcher.Close();

            const int neverReceived = mailboxSize * 2;

            for (var count = mailboxSize + 1; count <= neverReceived; ++count)
            {
                var countParam = count;
                Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam);
                mailbox.Send(actor, consumer, null, "Take(int)");
            }

            Until(0).Completes();

            Assert.Equal(mailboxSize, testResults.GetHighest());
        }
예제 #2
0
        public void TestNotifyOnSendDispatch()
        {
            var mailboxSize = 64;
            var testResults = new TestResults(mailboxSize);

            var dispatcher = new RingBufferDispatcher(mailboxSize, 1000, true, 4);

            dispatcher.Start();

            var mailbox = dispatcher.Mailbox;

            var actor = new CountTakerActor(testResults);

            for (var count = 1; count <= mailboxSize; ++count)
            {
                var countParam = count;
                Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam);

                // notify if in back off
                mailbox.Send(actor, consumer, null, "take(int)");

                // every third message give time for dispatcher to back off
                if (count % 3 == 0)
                {
                    Thread.Sleep(50);
                }
            }

            Assert.Equal(mailboxSize, testResults.GetHighest());
        }
        public void TestThroughput()
        {
            Init(ThroughputMailboxSize);

            var testResults = new TestResults(ThroughputMailboxSize);
            var countTaker  = World.ActorFor <ICountTaker>(
                Definition.Has <ThroughputCountTakerActor>(
                    Definition.Parameters(testResults), "testRingMailbox", "countTaker-2"));

            testResults.SetMaximum(ThroughputWarmUpCount);

            for (var count = 1; count <= ThroughputWarmUpCount; ++count)
            {
                countTaker.Take(count);
            }

            while (testResults.GetHighest() < ThroughputWarmUpCount)
            {
            }

            testResults.SetHighest(0);
            testResults.SetMaximum(ThroughputMaxCount);

            var startTime = DateTime.UtcNow;

            for (int count = 1; count <= ThroughputMaxCount; ++count)
            {
                countTaker.Take(count);
            }

            while (testResults.GetHighest() < ThroughputMaxCount)
            {
            }

            var timeSpent = DateTime.UtcNow - startTime;

            Console.WriteLine("Ms: " + timeSpent.TotalMilliseconds + " FOR " + ThroughputMaxCount + " MESSAGES IS " + (ThroughputMaxCount / timeSpent.TotalSeconds) + " PER SECOND");

            Assert.Equal(ThroughputMaxCount, testResults.GetHighest());
        }
        public void TestBasicDispatch()
        {
            Init(MailboxSize);
            var testResults = new TestResults(MaxCount);
            var countTaker  = World.ActorFor <ICountTaker>(
                Definition.Has <CountTakerActor>(
                    Definition.Parameters(testResults), "testRingMailbox", "countTaker-1"));

            testResults.SetMaximum(MaxCount);

            for (var count = 1; count <= MaxCount; ++count)
            {
                countTaker.Take(count);
            }

            Assert.Equal(MaxCount, testResults.GetHighest());
        }
예제 #5
0
        public void TestBasicDispatch()
        {
            const int mailboxSize = 64;
            var       testResults = new TestResults(mailboxSize);
            var       dispatcher  = new RingBufferDispatcher(mailboxSize, 2, false, 4);

            dispatcher.Start();
            var mailbox = dispatcher.Mailbox;
            var actor   = new CountTakerActor(testResults);

            for (var count = 1; count <= mailboxSize; ++count)
            {
                var countParam = count;
                Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam);
                mailbox.Send(actor, consumer, null, "Take(int)");
            }

            Assert.Equal(mailboxSize, testResults.GetHighest());
        }