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());

            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));
        }
Exemple #2
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());
        }
Exemple #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());

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

            publisher.ProcessChannel();

            Assert.Equal(1, publisherAccess.ReadFrom <int>("count"));
        }
    public void TestBroadcastPooledByteBuffer()
    {
        var buffer1 = _pool.Acquire();
        var buffer2 = _pool.Acquire();
        var buffer3 = _pool.Acquire();

        var rawMessage1 = RawMessage.From(0, 0, Message1);

        rawMessage1.AsBuffer((MemoryStream)buffer1.AsStream());
        var rawMessage2 = RawMessage.From(0, 0, Message2);

        rawMessage2.AsBuffer((MemoryStream)buffer2.AsStream());
        var rawMessage3 = RawMessage.From(0, 0, Message3);

        rawMessage3.AsBuffer((MemoryStream)buffer3.AsStream());

        _outbound.Broadcast(buffer1);
        _outbound.Broadcast(buffer2);
        _outbound.Broadcast(buffer3);

        foreach (var channel in _channelProvider.AllOtherNodeChannels.Values)
        {
            var mock = (MockManagedOutboundChannel)channel;

            Assert.Equal(Message1, mock.Writes[0]);
            Assert.Equal(Message2, mock.Writes[1]);
            Assert.Equal(Message3, mock.Writes[2]);
        }
    }
    public void TestSendToPooledByteBuffer()
    {
        var buffer1 = _pool.Acquire();
        var buffer2 = _pool.Acquire();
        var buffer3 = _pool.Acquire();

        var rawMessage1 = RawMessage.From(0, 0, Message1);

        rawMessage1.AsBuffer((MemoryStream)buffer1.AsStream());
        var rawMessage2 = RawMessage.From(0, 0, Message2);

        rawMessage2.AsBuffer((MemoryStream)buffer2.AsStream());
        var rawMessage3 = RawMessage.From(0, 0, Message3);

        rawMessage3.AsBuffer((MemoryStream)buffer3.AsStream());

        var id3 = Id.Of(3);

        _outbound.SendTo(buffer1, id3);
        _outbound.SendTo(buffer2, id3);
        _outbound.SendTo(buffer3, id3);

        var mock = (MockManagedOutboundChannel)_channelProvider.ChannelFor(Id.Of(3));

        Assert.Equal(Message1, mock.Writes[0]);
        Assert.Equal(Message2, mock.Writes[1]);
        Assert.Equal(Message3, mock.Writes[2]);
    }
Exemple #6
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 #7
0
        public void ProbeChannel()
        {
            ProbeChannelCount.IncrementAndGet();

            var message = RawMessage.From(0, 0, MessagePrefix + ProbeChannelCount.Get());

            _consumer.Consume(message);
        }
        private void PublishService(string name)
        {
            var addresses = new List <Address>();

            foreach (var attribute in _attributesClient.AllOf(name))
            {
                addresses.Add(Vlingo.Wire.Node.Address.From(attribute.ToStringValue(), AddressType.Main));
            }
            _publisher.Send(RawMessage.From(0, 0, ServiceRegistered.As(Named(_serviceNamePrefix, name), addresses).ToString()));
        }
        public RawMessage BuildRawMessageBuffer(MemoryStream buffer, string message)
        {
            buffer.Clear();
            buffer.Write(Converters.TextToBytes(message));
            buffer.Flip();
            var rawMessage = RawMessage.From(1, 0, (int)buffer.Length);

            rawMessage.Put(buffer, false);

            return(rawMessage);
        }
Exemple #10
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);
        }
        public void TestInboundStreamInterest()
        {
            var inboundStreamInterest =
                TestWorld.ActorFor <IInboundStreamInterest>(
                    Definition.Has <ClusterSnapshotActor>(Definition.Parameters(_intializer, Application)));

            inboundStreamInterest.Actor.HandleInboundStreamMessage(AddressType.Op, _opMessage);
            Assert.Equal(0, Application.HandleApplicationMessageCheck.Get());

            var appMessage = RawMessage.From(1, 0, "app-test");

            inboundStreamInterest.Actor.HandleInboundStreamMessage(AddressType.App, appMessage);
            Assert.Equal(1, Application.HandleApplicationMessageCheck.Get());
        }
 private void UnregisterService(Name serviceName)
 {
     if (_directoryChannel != null)
     {
         var unregister = Model.Message.UnregisterService.As(serviceName);
         var unregisterServiceMessage = RawMessage.From(0, 0, unregister.ToString());
         var expected = unregisterServiceMessage.TotalLength;
         var actual   = _directoryChannel.Write(unregisterServiceMessage, _buffer);
         if (actual != expected)
         {
             Logger.Warn($"DIRECTORY CLIENT: Did not send full service unregister message: {unregisterServiceMessage.AsTextMessage()}. Actual - {actual}, Expected - {expected}");
         }
     }
 }
        private void UnpublishService(string name)
        {
            _publisher.Send(RawMessage.From(0, 0, ServiceUnregistered.As(Named(_unregisteredServiceNamePrefix, name)).ToString()));

            var unregisteredNotificationsCount = _attributesClient.Attribute <int>(name, _unregisteredCount);
            var count = unregisteredNotificationsCount.Value - 1;

            if (count - 1 <= 0)
            {
                _attributesClient.RemoveAll(name);
            }
            else
            {
                _attributesClient.Replace(name, _unregisteredCount, count);
            }
        }
Exemple #14
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"));
        }
    public void TestSendTo()
    {
        var rawMessage1 = RawMessage.From(0, 0, Message1);
        var rawMessage2 = RawMessage.From(0, 0, Message2);
        var rawMessage3 = RawMessage.From(0, 0, Message3);

        var id3 = Id.Of(3);

        _outbound.SendTo(rawMessage1, id3);
        _outbound.SendTo(rawMessage2, id3);
        _outbound.SendTo(rawMessage3, id3);

        var mock = (MockManagedOutboundChannel)_channelProvider.ChannelFor(Id.Of(3));

        Assert.Equal(Message1, mock.Writes[0]);
        Assert.Equal(Message2, mock.Writes[1]);
        Assert.Equal(Message3, mock.Writes[2]);
    }
    public void TestBroadcast()
    {
        var rawMessage1 = RawMessage.From(0, 0, Message1);
        var rawMessage2 = RawMessage.From(0, 0, Message2);
        var rawMessage3 = RawMessage.From(0, 0, Message3);

        _outbound.Broadcast(rawMessage1);
        _outbound.Broadcast(rawMessage2);
        _outbound.Broadcast(rawMessage3);

        foreach (var channel in _channelProvider.AllOtherNodeChannels.Values)
        {
            var mock = (MockManagedOutboundChannel)channel;

            Assert.Equal(Message1, mock.Writes[0]);
            Assert.Equal(Message2, mock.Writes[1]);
            Assert.Equal(Message3, mock.Writes[2]);
        }
    }
    public void TestBroadcastToSelectNodes()
    {
        var rawMessage1 = RawMessage.From(0, 0, Message1);
        var rawMessage2 = RawMessage.From(0, 0, Message2);
        var rawMessage3 = RawMessage.From(0, 0, Message3);

        var selectNodes = new List <Node> {
            Config.NodeMatching(Id.Of(3))
        };

        _outbound.Broadcast(selectNodes, rawMessage1);
        _outbound.Broadcast(selectNodes, rawMessage2);
        _outbound.Broadcast(selectNodes, rawMessage3);

        var mock = (MockManagedOutboundChannel)_channelProvider.ChannelFor(Id.Of(3));

        Assert.Equal(Message1, mock.Writes[0]);
        Assert.Equal(Message2, mock.Writes[1]);
        Assert.Equal(Message3, mock.Writes[2]);
    }
        public void TestChannelWriter()
        {
            var consumer     = new MockChannelReaderConsumer("consume");
            var consumeCount = 0;
            var accessSafely = AccessSafely.Immediately()
                               .WritingWith <int>("consume", (value) => consumeCount += value)
                               .ReadingWith("consume", () => consumeCount);

            consumer.UntilConsume = accessSafely;

            _channelReader.OpenFor(consumer);

            var buffer = new MemoryStream(1024);

            buffer.SetLength(1024);

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

            _channelWriter.Write(rawMessage1, buffer);

            ProbeUntilConsumed(() => accessSafely.ReadFrom <int>("consume") < 1, _channelReader);

            Assert.Equal(1, consumer.UntilConsume.ReadFrom <int>("consume"));
            Assert.Equal(message1, consumer.Messages.First());

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

            _channelWriter.Write(rawMessage2, buffer);

            ProbeUntilConsumed(() => accessSafely.ReadFrom <int>("consume") < 2, _channelReader);

            Assert.Equal(2, consumer.UntilConsume.ReadFrom <int>("consume"));
            Assert.Equal(message2, consumer.Messages.Last());
        }
        //====================================
        // DirectoryClient
        //====================================

        public void Register(ServiceRegistrationInfo info)
        {
            var converted = Model.Message.RegisterService.As(Name.Of(info.Name), Location.ToAddresses(info.Locations));

            _registerService = RawMessage.From(0, 0, converted.ToString());
        }