Esempio n. 1
0
        public void TestNotifyOnSendDispatch()
        {
            var mailboxSize = 64;
            var testResults = new TestResults(mailboxSize);

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

            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);
                var localMessage = new LocalMessage <ICountTaker>(actor, consumer, "take(int)");

                // notify if in back off
                mailbox.Send(localMessage);

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

            Assert.Equal(mailboxSize, testResults.GetHighest());
        }
Esempio n. 2
0
        public void TestClose()
        {
            var dispatcher = new ManyToOneConcurrentArrayQueueDispatcher(MailboxSize, 2, 4, 10);

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

            actor.Until = Until(MailboxSize);
            for (var i = 1; i <= MailboxSize; ++i)
            {
                var countParam = i;
                Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam);
                var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)");
                mailbox.Send(message);
            }

            actor.Until.Completes();
            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);
                var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)");
                mailbox.Send(message);
            }

            Assert.Equal(MailboxSize, actor.Highest.Get());
        }
Esempio n. 3
0
        public void TestBasicDispatch()
        {
            var testResult = new TestResults(MailboxSize);
            var dispatcher = new ManyToOneConcurrentArrayQueueDispatcher(MailboxSize, 2, false, 4, 10);

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

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

            Assert.Equal(MailboxSize, testResult.GetHighest());
        }