public SynodConfigurationProvider(SynodConfiguration config)
 {
     LocalNode = new Node(config.LocalNode.ParseAddress(), ReceiverIdentifier.CreateIdentity());
     synod     = config.Members
                 .Select(uri => new DynamicUri(uri))
                 .ToList();
     HeartBeatInterval = config.HeartBeatInterval;
     MissingHeartBeatsBeforeReconnect = config.MissingHeartBeatsBeforeReconnect;
     IntercomEndpoint = new Uri(config.IntercomEndpoint);
 }
        public ScaleOutSocketConfiguration GetScaleOutConfiguration()
        {
            var uris             = appConfig.ScaleOutAddressUri.GetAddressRange();
            var socketIdentifier = ReceiverIdentifier.CreateIdentity();

            return(new ScaleOutSocketConfiguration
            {
                ScaleOutReceiveMessageQueueLength = Math.Max(appConfig.ScaleOutReceiveMessageQueueLength, 10000),
                AddressRange = uris.Select(uri => new SocketEndpoint(uri, socketIdentifier))
                               .ToList()
            });
        }
Beispiel #3
0
        public void IfSynodConsistsOfOneNode_NoHeartBeatingStarted()
        {
            var localNode = new Node("tcp://127.0.0.1:800", ReceiverIdentifier.CreateIdentity());

            synodConfigProvider.Setup(m => m.Synod).Returns(1.Produce(i => new DynamicUri(localNode.Uri.AbsoluteUri)));
            synodConfigProvider.Setup(m => m.LocalNode).Returns(localNode);

            messageHub = new IntercomMessageHub(socketFactory.Object,
                                                synodConfigProvider.Object,
                                                perfCounterManager.Object,
                                                logger.Object);
            //
            messageHub.Start(TimeSpan.FromSeconds(3));
            synodConfigProvider.Object.HeartBeatInterval.MultiplyBy(2).Sleep();
            messageHub.Stop();
            //
            Assert.Equal(1, synodConfigProvider.Object.Synod.Count());
            publisherSocket.Verify(m => m.SendMessage(It.IsAny <IMessage>()), Times.Never);
        }
        public void GetAllRoutes_ReturnsAllRegisteredMessageHubs()
        {
            var health = new Health();
            var nodes  = new[]
            {
                new Node("tcp://127.0.0.1:8080", ReceiverIdentifier.CreateIdentity()),
                new Node("tcp://192.168.0.1:9191", ReceiverIdentifier.CreateIdentity())
            };

            var registrations = nodes.SelectMany(n => MessageHubs().Select(mh => (Node: n, MessageHub: mh)))
                                .Select(reg => new ExternalRouteRegistration
            {
                Health = health,
                Peer   = reg.Node,
                Route  = new MessageRoute {
                    Receiver = reg.MessageHub
                }
            })
                                .ToList();

            registrations.ForEach(reg => externalRoutingTable.AddMessageRoute(reg));
            //
            var routes = externalRoutingTable.GetAllRoutes();

            //
            Assert.Equal(nodes.Count(), routes.Count());
            nodes.Select(n => n.Uri).Should().BeEquivalentTo(routes.Select(r => r.Node.Uri));
            nodes.Select(n => n.SocketIdentity).Should().BeEquivalentTo(routes.Select(r => r.Node.SocketIdentity));

            AssertNodesMessageHubsAreSame(nodes.First());
            AssertNodesMessageHubsAreSame(nodes.Second());

            IEnumerable <ReceiverIdentifier> MessageHubs()
            => Randomizer.Int32(2, 8)
            .Produce(ReceiverIdentities.CreateForMessageHub);

            void AssertNodesMessageHubsAreSame(Node node)
            => registrations.Where(r => r.Peer.Equals(node))
            .Select(r => r.Route.Receiver)
            .Should()
            .BeEquivalentTo(routes.Where(r => r.Node.Equals(node)).SelectMany(r => r.MessageHubs).Select(mh => mh.MessageHub));
        }
        public void GetAllRoutes_ReturnsAllRegisteredMessageRoutes()
        {
            var health = new Health();
            var nodes  = new[]
            {
                new Node("tcp://127.0.0.1:8080", ReceiverIdentifier.CreateIdentity()),
                new Node("tcp://192.168.0.1:9191", ReceiverIdentifier.CreateIdentity())
            };

            var messages = new[]
            {
                MessageIdentifier.Create <SimpleMessage>(),
                MessageIdentifier.Create <SimpleMessage>(ReceiverIdentifier.CreateIdentity()),
                MessageIdentifier.Create <AsyncExceptionMessage>(),
                MessageIdentifier.Create <AsyncMessage>(ReceiverIdentifier.CreateIdentity())
            };

            var registrations = nodes.SelectMany(n => messages.Select(m => (Node: n, Message: m)))
                                .SelectMany(nm => Actors().Select(a => (Node: nm.Node, Message: nm.Message, Actor: a)))
                                .Select(reg => new ExternalRouteRegistration
            {
                Health = health,
                Peer   = reg.Node,
                Route  = new MessageRoute {
                    Receiver = reg.Actor, Message = reg.Message
                }
            })
                                .ToList();

            registrations.ForEach(reg => externalRoutingTable.AddMessageRoute(reg));
            //
            var routes = externalRoutingTable.GetAllRoutes();

            //
            Assert.Equal(nodes.Count(), routes.Count());
            nodes.Select(n => n.Uri).Should().BeEquivalentTo(routes.Select(r => r.Node.Uri));
            nodes.Select(n => n.SocketIdentity).Should().BeEquivalentTo(routes.Select(r => r.Node.SocketIdentity));

            AssertMessageRoutesAreSame(nodes.First());
            AssertMessageRoutesAreSame(nodes.Second());

            void AssertMessageRoutesAreSame(Node node)
            {
                var messageRoutes = registrations.Where(r => r.Peer.Equals(node))
                                    .GroupBy(r => r.Route.Message, r => r.Route.Receiver);

                messageRoutes.Select(mr => mr.Key)
                .Should()
                .BeEquivalentTo(routes.Where(r => r.Node.Equals(node)).SelectMany(r => r.MessageRoutes).Select(mr => mr.Message));
                foreach (var messageIdentifier in messageRoutes.Select(mr => mr.Key))
                {
                    messageRoutes.Where(mr => mr.Key == messageIdentifier)
                    .SelectMany(mr => mr)
                    .Should()
                    .BeEquivalentTo(routes.Where(r => r.Node.Equals(node))
                                    .SelectMany(r => r.MessageRoutes)
                                    .Where(mr => mr.Message == messageIdentifier)
                                    .SelectMany(mr => mr.Actors)
                                    .Select(a => new ReceiverIdentifier(a.Identity)));
                }
            }

            IEnumerable <ReceiverIdentifier> Actors()
            => Randomizer.Int32(1, 8)
            .Produce(ReceiverIdentities.CreateForActor)
            .ToList();
        }
Beispiel #6
0
 public SynodConfiguration(ISynodConfigurationProvider configProvider)
 {
     LocalNode = new Node(configProvider.LocalNode, ReceiverIdentifier.CreateIdentity());
     synod     = new HashSet <Uri>(configProvider.Synod);
 }
Beispiel #7
0
        public IntercomMessageHubTests()
        {
            socketFactory   = new Mock <ISocketFactory>();
            publisherSocket = new Mock <ISocket>();
            socketFactory.Setup(m => m.CreatePublisherSocket()).Returns(publisherSocket.Object);
            subscriberSocket = new Mock <ISocket>();
            socketFactory.Setup(m => m.CreateSubscriberSocket()).Returns(subscriberSocket.Object);

            synodConfigProvider = new Mock <ISynodConfigurationProvider>();
            var synod = 3.Produce(i => new DynamicUri($"tcp://127.0.0.1:800{i}"));

            synodConfigProvider.Setup(m => m.Synod).Returns(synod);
            synodConfigProvider.Setup(m => m.HeartBeatInterval).Returns(TimeSpan.FromSeconds(2));
            synodConfigProvider.Setup(m => m.MissingHeartBeatsBeforeReconnect).Returns(2);
            synodConfigProvider.Setup(m => m.LocalNode).Returns(new Node(synod.First().Uri, ReceiverIdentifier.CreateIdentity()));
            synodConfigProvider.Setup(m => m.IntercomEndpoint).Returns(new Uri("inproc://health"));

            perfCounterManager = new Mock <IPerformanceCounterManager <KinoPerformanceCounters> >();
            perfCounter        = new Mock <IPerformanceCounter>();
            perfCounterManager.Setup(m => m.GetCounter(It.IsAny <KinoPerformanceCounters>())).Returns(perfCounter.Object);
            logger = new Mock <ILogger>();

            messageHub = new IntercomMessageHub(socketFactory.Object,
                                                synodConfigProvider.Object,
                                                perfCounterManager.Object,
                                                logger.Object);
        }