public void TestMulticastPublishSubscribe() { var publisherCount = 0; var subscriberCount = 0; var accessSafely = AccessSafely.Immediately() .WritingWith <int>("publisherCount", (value) => publisherCount += value) .ReadingWith("publisherCount", () => publisherCount) .WritingWith <int>("subscriberCount", (value) => subscriberCount += value) .ReadingWith("subscriberCount", () => subscriberCount); var publisherConsumer = new MockChannelReaderConsumer("publisherCount"); publisherConsumer.UntilConsume = accessSafely; var publisher = new MulticastPublisherReader( "test-publisher", new Group("237.37.37.1", 37771), 37779, 1024, publisherConsumer, ConsoleLogger.TestInstance()); var subscriber = new MulticastSubscriber( "test-subscriber", new Group("237.37.37.1", 37771), 1024, 10, ConsoleLogger.TestInstance()); var subscriberConsumer = new MockChannelReaderConsumer("subscriberCount"); subscriberConsumer.UntilConsume = accessSafely; subscriber.OpenFor(subscriberConsumer); for (int idx = 0; idx < 10; ++idx) { publisher.SendAvailability(); } publisher.ProcessChannel(); for (int i = 0; i < 2; ++i) { subscriber.ProbeChannel(); } subscriberConsumer.UntilConsume.ReadFromExpecting("subscriberCount", 10); Assert.Equal(0, publisherCount); Assert.Equal(10, subscriberCount); }
public void TestMulticastPublishSubscribe() { var publisherConsumer = new MockChannelReaderConsumer(); var publisherAccess = publisherConsumer.AfterCompleting(0); var publisher = new MulticastPublisherReader( "test-publisher", new Group("237.37.37.2", 37771), 37379, 1024, publisherConsumer, ConsoleLogger.TestInstance()); var subscriber = new MulticastSubscriber( "test-subscriber", new Group("237.37.37.2", 37771), 1024, 10, ConsoleLogger.TestInstance()); var subscriberConsumer = new MockChannelReaderConsumer(); var subscriberAccess = subscriberConsumer.AfterCompleting(10); subscriber.OpenFor(subscriberConsumer); for (var idx = 0; idx < 10; ++idx) { publisher.SendAvailability(); } publisher.ProcessChannel(); for (var i = 0; i < 2; ++i) { subscriber.ProbeChannel(); } Assert.Equal(0, publisherAccess.ReadFrom <int>("count")); Assert.Equal(10, subscriberAccess.ReadFromExpecting("count", 10, 10_000)); }
//========================================= // Scheduled //========================================= public void IntervalSignal(IScheduled <IntervalType> scheduled, IntervalType data) { if (_stopped) { return; } if (!_leader) { return; } switch (data) { case IntervalType.Processing: _publisher.ProcessChannel(); break; case IntervalType.Publishing: _publisher.SendAvailability(); PublishAllServices(); break; } }