public void TestClose() { var testResults = new TestResults(); const int mailboxSize = 64; var dispatcher = new RingBufferDispatcher(mailboxSize, 2, 4); dispatcher.Start(); var mailbox = dispatcher.Mailbox; var actor = new CountTakerActor(testResults); testResults.Until = Until(mailboxSize); for (var count = 1; count <= mailboxSize; ++count) { var countParam = count; Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam); mailbox.Send(actor, consumer, null, "Take(int)"); } testResults.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); mailbox.Send(actor, consumer, null, "Take(int)"); } Until(0).Completes(); Assert.Equal(mailboxSize, testResults.Highest.Get()); }
public void TestExecute() { var testResults = new TestResults(); testResults.Log.Set(true); var mailbox = new TestMailbox(testResults); var actor = new CountTakerActor(testResults); testResults.Until = Until(Total); for (var count = 0; count < Total; ++count) { var countParam = count; Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam); var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)"); mailbox.Send(message); dispatcher.Execute(mailbox); } testResults.Until.Completes(); for (var idx = 0; idx < testResults.Counts.Count; ++idx) { Assert.Contains(idx, testResults.Counts); } }
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 TestClose() { var testResults = new TestResults(3, false); var mailbox = new TestMailbox(testResults, World.DefaultLogger); var actor = new CountTakerActor(testResults, World.DefaultLogger); for (var count = 0; count < 3; ++count) { var countParam = count; Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam); var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)"); mailbox.Send(message); dispatcher.Execute(mailbox); } dispatcher.Close(); Action <ICountTaker> consumer2 = consumerActor => consumerActor.Take(10); var message2 = new LocalMessage <ICountTaker>(actor, consumer2, "Take(int)"); mailbox.Send(message2); dispatcher.Execute(mailbox); var counts = testResults.GetCounts(); Assert.Equal(3, counts.Count); for (var idx = 0; idx < counts.Count; ++idx) { Assert.Contains(idx, counts); } }
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()); }
public void TestMailboxSendReceive() { var testResults = new TestResults(Total); var actor = new CountTakerActor(testResults); for (var i = 0; i < Total; ++i) { var countParam = i; Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam); var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)"); mailbox.Send(message); } for (var i = 0; i < Total; ++i) { Assert.Equal(i, actor.TestResults.GetCounts(i)); } }
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()); }
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()); }
public void TestSuspendedDelivery() { const string Paused = "paused#"; const string Exceptional = "exceptional#"; var dispatcher = new ExecutorDispatcher(1, 1.0f); var mailbox = new ConcurrentQueueMailbox(dispatcher, 1); var testResults = new TestResults(); var actor = new CountTakerActor(testResults); mailbox.SuspendExceptFor(Paused, typeof(CountTakerActor)); mailbox.SuspendExceptFor(Exceptional, typeof(CountTakerActor)); mailbox.Resume(Exceptional); mailbox.Resume(Paused); Assert.False(mailbox.IsSuspended); }
public void TestOverflowDispatch() { var testResults = new TestResults(); const int mailboxSize = 64; const int overflowSize = mailboxSize * 2; var dispatcher = new RingBufferDispatcher(mailboxSize, 2, 4); var mailbox = dispatcher.Mailbox; var actor = new CountTakerActor(testResults); testResults.Until = Until(overflowSize); for (var count = 1; count <= overflowSize; ++count) { var countParam = count; Action <ICountTaker> consumer = consumerActor => consumerActor.Take(countParam); var message = new LocalMessage <ICountTaker>(actor, consumer, "Take(int)"); mailbox.Send(message); } dispatcher.Start(); testResults.Until.Completes(); Assert.Equal(overflowSize, testResults.Highest.Get()); }