Exemplo n.º 1
0
        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 DirectoryClientActor(
     IServiceDiscoveryInterest interest,
     Group directoryPublisherGroup,
     int maxMessageSize,
     long processingInterval,
     int processingTimeout)
 {
     _interest   = interest;
     _buffer     = new MemoryStream(maxMessageSize);
     _subscriber = new MulticastSubscriber(
         DirectoryClientFactory.ClientName,
         directoryPublisherGroup,
         maxMessageSize,
         processingTimeout,
         Logger);
     _subscriber.OpenFor(SelfAs <IChannelReaderConsumer>());
     _cancellable = Stage.Scheduler.Schedule(
         SelfAs <IScheduled <object?> >(), null, TimeSpan.FromMilliseconds(1000L), TimeSpan.FromMilliseconds(processingInterval));
 }
Exemplo n.º 3
0
        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));
        }