public void TestSingleEventWithCompetingConsumers() { var ircSettings = new InterRoleCommunicationSettings() { UseCompetingConsumers = true, EventWaitTimeout = TimeSpan.FromSeconds(10) }; using (InterRoleCommunicationExtension irc1 = new InterRoleCommunicationExtension(topicEndpoint, ircSettings)) using (InterRoleCommunicationExtension irc2 = new InterRoleCommunicationExtension(topicEndpoint, ircSettings)) using (InterRoleCommunicationExtension irc3 = new InterRoleCommunicationExtension(topicEndpoint, ircSettings)) using (InterRoleCommunicationExtension irc4 = new InterRoleCommunicationExtension(topicEndpoint, ircSettings)) { var subscriber1 = new EventCountingSubscriber(); irc1.Subscribe(subscriber1); irc2.Subscribe(subscriber1); irc3.Subscribe(subscriber1); irc4.Subscribe(subscriber1); InterRoleCommunicationEvent ev = new InterRoleCommunicationEvent(new RoleGracefulRecycleEvent(typeof(TopicBasedInterRoleCommunicationTests).FullName)); irc1.Publish(ev); irc1.Publish(ev); irc1.Publish(ev); Thread.Sleep(irc4.Settings.EventWaitTimeout.Add(TimeSpan.FromSeconds(5))); Assert.AreEqual<int>(3, subscriber1.OnNextCount); } }
public void TestMultipleEvents() { using (InterRoleCommunicationExtension ircExtension = new InterRoleCommunicationExtension(topicEndpoint, new InterRoleCommunicationSettings() { EnableCarbonCopy = true })) { var subscriber1 = new EventCountingSubscriber(); ircExtension.Subscribe(subscriber1); int eventCount = 100; int waitAttemptCount = 0; for (int i = 0; i < eventCount; i++) { ircExtension.Publish(new InterRoleCommunicationEvent(new RoleConfigurationSectionRefreshEvent(String.Format("Message #{0}", i)))); } while (subscriber1.OnNextCount != eventCount) { Thread.Sleep(ircExtension.Settings.EventWaitTimeout.Add(TimeSpan.FromSeconds(5))); waitAttemptCount++; if (waitAttemptCount > 10) break; } Assert.AreEqual<int>(eventCount, subscriber1.OnNextCount); } }
public void TestSingleEvent() { using (InterRoleCommunicationExtension ircExtension = new InterRoleCommunicationExtension(topicEndpoint, new InterRoleCommunicationSettings() { EnableCarbonCopy = true })) { var subscriber1 = new EventCountingSubscriber(); ircExtension.Subscribe(subscriber1); InterRoleCommunicationEvent ev = new InterRoleCommunicationEvent(new RoleGracefulRecycleEvent(typeof(TopicBasedInterRoleCommunicationTests).FullName)); ircExtension.Publish(ev); Thread.Sleep(ircExtension.Settings.EventWaitTimeout.Add(TimeSpan.FromSeconds(5))); Assert.AreEqual<int>(1, subscriber1.OnNextCount); } }
public void TestSingleEventWithNetworkFaultSimulation() { try { using (InterRoleCommunicationExtension ircExtension = new InterRoleCommunicationExtension(topicEndpoint, new InterRoleCommunicationSettings() { EnableCarbonCopy = true, EnableAsyncPublish = false, EventWaitTimeout = TimeSpan.FromSeconds(3) })) { bool retryOccurred = false; ircExtension.Settings.RetryPolicy.RetryOccurred += (currentRetryCount, ex, delay) => { retryOccurred = true; NetworkUtility.EnableNetworkAdapter(); }; var subscriber1 = new EventCountingSubscriber(); ircExtension.Subscribe(subscriber1); NetworkUtility.DisableNetworkAdapter(); InterRoleCommunicationEvent ev = new InterRoleCommunicationEvent(new RoleGracefulRecycleEvent(typeof(TopicBasedInterRoleCommunicationTests).FullName)); ircExtension.Publish(ev); while (subscriber1.OnNextCount == 0) { Thread.Sleep(ircExtension.Settings.EventWaitTimeout.Add(TimeSpan.FromSeconds(5))); } Assert.IsTrue(retryOccurred, "A retry condition does not seem to have occurred."); Assert.AreEqual<int>(1, subscriber1.OnNextCount); } } finally { NetworkUtility.EnableNetworkAdapter(); } }