Exemple #1
0
        public void TestPublisherChannelReader()
        {
            var publisherConsumer = new MockChannelReaderConsumer();
            var publisherAccess   = publisherConsumer.AfterCompleting(1);

            var publisher = new MulticastPublisherReader(
                "test-publisher",
                new Group("237.37.37.2", 37381),
                37389,
                1024,
                publisherConsumer,
                ConsoleLogger.TestInstance());

            var socketWriter = new SocketChannelWriter(
                Address.From(
                    Host.Of("localhost"),
                    37389,
                    AddressType.Main),
                ConsoleLogger.TestInstance());

            socketWriter.Write(RawMessage.From(1, 1, "test-response"), new MemoryStream());

            publisher.ProcessChannel();

            Assert.Equal(1, publisherAccess.ReadFrom <int>("count"));
        }
Exemple #2
0
        public void TestPublisherChannelReader()
        {
            var publisherCount = 0;
            var accessSafely   = AccessSafely.AfterCompleting(1)
                                 .WritingWith <int>("publisherCount", (value) => publisherCount += value)
                                 .ReadingWith("publisherCount", () => publisherCount);

            var publisherConsumer = new MockChannelReaderConsumer("publisherCount");

            publisherConsumer.UntilConsume = accessSafely;

            var publisher = new MulticastPublisherReader(
                "test-publisher",
                new Group("237.37.37.2", 37381),
                37389,
                1024,
                publisherConsumer,
                ConsoleLogger.TestInstance());

            var socketWriter = new SocketChannelWriter(
                Address.From(
                    Host.Of("localhost"),
                    37389,
                    AddressType.Main),
                ConsoleLogger.TestInstance());

            socketWriter.Write(RawMessage.From(1, 1, "test-response"), new MemoryStream());

            publisher.ProcessChannel();

            Assert.Equal(1, publisherCount);
        }
Exemple #3
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);
        }
Exemple #4
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));
        }
        //=========================================
        // 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;
            }
        }