Beispiel #1
0
        public void TestAppInboundChannel()
        {
            var consumer     = new MockChannelReaderConsumer();
            var accessSafely = consumer.AfterCompleting(2);

            _appReader.OpenFor(consumer);

            var buffer = new MemoryStream(1024);

            buffer.SetLength(1024);

            var message1    = AppMessage + 1;
            var rawMessage1 = RawMessage.From(0, 0, message1);

            _appChannel.Write(rawMessage1.AsStream(buffer));

            ProbeUntilConsumed(() => accessSafely.ReadFromNow <int>("count") < 1, _appReader);

            Assert.Equal(1, accessSafely.ReadFromNow <int>("count"));
            Assert.Equal(message1, consumer.Messages.First());

            var message2    = AppMessage + 2;
            var rawMessage2 = RawMessage.From(0, 0, message2);

            _appChannel.Write(rawMessage2.AsStream(buffer));

            ProbeUntilConsumed(() => accessSafely.ReadFrom <int>("count") < 2, _appReader);

            Assert.Equal(2, accessSafely.ReadFrom <int>("count"));
            Assert.Equal(message2, consumer.Messages.Last());
        }
Beispiel #2
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"));
        }
Beispiel #3
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());

            Func <int> write = () => socketWriter.Write(RawMessage.From(1, 1, "test-response"), new MemoryStream());

            ProbeUntilConsumed(() => publisherAccess.ReadFromNow <int>("count") < 1, publisher, write, 10);

            Assert.Equal(1, publisherAccess.ReadFromExpecting("count", 1, 10_000));
        }
Beispiel #4
0
        public void TestPublisherChannelReaderWithMultipleClients()
        {
            var publisherConsumer = new MockChannelReaderConsumer();
            var publisherAccess   = publisherConsumer.AfterCompleting(4);

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

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

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

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

            Func <int> write1 = () => client1.Write(RawMessage.From(1, 1, "test-response1"), new MemoryStream());
            Func <int> write2 = () => client2.Write(RawMessage.From(1, 1, "test-response2"), new MemoryStream());
            Func <int> write3 = () => client3.Write(RawMessage.From(1, 1, "test-response3"), new MemoryStream());

            Func <int> writes = () =>
            {
                write1();
                write2();
                write3();
                return(write1());
            };

            ProbeUntilConsumed(() => publisherAccess.ReadFromNow <int>("count") < 4, publisher, writes, 10);

            Assert.True(publisherAccess.ReadFrom <int>("count") >= 4);
        }
Beispiel #5
0
        public void TestPublisherChannelReaderWithMultipleClients()
        {
            var publisherConsumer = new MockChannelReaderConsumer();
            var publisherAccess   = publisherConsumer.AfterCompleting(4);

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

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

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

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

            client1.Write(RawMessage.From(1, 1, "test-response1"), new MemoryStream());
            client2.Write(RawMessage.From(1, 1, "test-response2"), new MemoryStream());
            client3.Write(RawMessage.From(1, 1, "test-response3"), new MemoryStream());
            client1.Write(RawMessage.From(1, 1, "test-response1"), new MemoryStream());

            publisher.ProbeChannel();
            publisher.ProbeChannel();
            publisher.ProbeChannel();
            publisher.ProbeChannel();

            Assert.Equal(4, publisherAccess.ReadFrom <int>("count"));
        }
Beispiel #6
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));
        }