Example #1
0
 public void Setup()
 {
     socketFactory  = new Mock <ISocketFactory>();
     scaleOutSocket = new Mock <ISocket>();
     socketFactory.Setup(m => m.CreateRouterSocket()).Returns(scaleOutSocket.Object);
     logger = new Mock <ILogger>();
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     localNodeEndpoint             = new SocketEndpoint("tcp://127.0.0.1:8080", Guid.NewGuid().ToByteArray());
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(localNodeEndpoint);
     clusterServices = new Mock <IClusterServices>();
     serviceMessageHandlerRegistry = new Mock <IServiceMessageHandlerRegistry>();
     serviceMessageHandlerRegistry.Setup(m => m.GetMessageHandler(It.IsAny <MessageIdentifier>())).Returns((IServiceMessageHandler)null);
     perfCounterManager = new Mock <IPerformanceCounterManager <KinoPerformanceCounters> >();
     perfCounter        = new Mock <IPerformanceCounter>();
     perfCounterManager.Setup(m => m.GetCounter(It.IsAny <KinoPerformanceCounters>())).Returns(perfCounter.Object);
     securityProvider            = new Mock <ISecurityProvider>();
     localRouterSocket           = new Mock <ILocalSocket <IMessage> >();
     localRouterSocketWaitHandle = new ManualResetEventSlim(false);
     localRouterSocket.Setup(m => m.CanReceive()).Returns(localRouterSocketWaitHandle.WaitHandle);
     internalRegistrationsReceiver           = new Mock <ILocalReceivingSocket <InternalRouteRegistration> >();
     internalRegistrationsReceiverWaitHandle = new ManualResetEventSlim(false);
     internalRegistrationsReceiver.Setup(m => m.CanReceive()).Returns(internalRegistrationsReceiverWaitHandle.WaitHandle);
     internalRegistrationHandler = new Mock <IInternalMessageRouteRegistrationHandler>();
     clusterHealthMonitor        = new Mock <IClusterHealthMonitor>();
     clusterServices.Setup(m => m.GetClusterHealthMonitor()).Returns(clusterHealthMonitor.Object);
     clusterMonitor = new Mock <IClusterMonitor>();
     clusterServices.Setup(m => m.GetClusterMonitor()).Returns(clusterMonitor.Object);
     internalRoutingTable = new Mock <IInternalRoutingTable>();
     externalRoutingTable = new Mock <IExternalRoutingTable>();
     messageRouter        = CreateMessageRouter();
 }
Example #2
0
 public RouteDiscoveryTests()
 {
     autoDiscoverySender           = new Mock <IAutoDiscoverySender>();
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutAddress = new SocketEndpoint("tcp://127.0.0.1:9090");
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     config = new ClusterMembershipConfiguration
     {
         RouteDiscovery = new RouteDiscoveryConfiguration
         {
             ClusterAutoDiscoveryStartDelay = TimeSpan.FromSeconds(1),
             ClusterAutoDiscoveryStartDelayMaxMultiplier = 2,
             MaxAutoDiscoverySenderQueueLength           = 100,
             MissingRoutesDiscoverySendingPeriod         = TimeSpan.FromSeconds(5),
             MaxMissingRouteDiscoveryRequestQueueLength  = 100,
             MissingRoutesDiscoveryRequestsPerSend       = 10
         }
     };
     securityProvider = new Mock <ISecurityProvider>();
     domain           = Guid.NewGuid().ToString();
     securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
     logger         = new Mock <ILogger>();
     routeDiscovery = new RouteDiscovery(autoDiscoverySender.Object,
                                         scaleOutConfigurationProvider.Object,
                                         config,
                                         securityProvider.Object,
                                         logger.Object);
 }
Example #3
0
 public void Setup()
 {
     securityProvider = new Mock <ISecurityProvider>();
     domain           = Guid.NewGuid().ToString();
     securityProvider.Setup(m => m.GetAllowedDomains()).Returns(new[] { domain });
     securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
     logger          = new Mock <ILogger>();
     routeDiscovery  = new Mock <IRouteDiscovery>();
     scaleOutAddress = new SocketEndpoint(new Uri("tcp://127.0.0.1:5000"), Guid.NewGuid().ToByteArray());
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     autoDiscoverySender           = new Mock <IAutoDiscoverySender>();
     autoDiscoveryListener         = new Mock <IAutoDiscoveryListener>();
     heartBeatSenderConfigProvider = new Mock <IHeartBeatSenderConfigurationProvider>();
     heartBeatUri = new Uri("tcp://127.0.0.1:890");
     heartBeatSenderConfigProvider.Setup(m => m.GetHeartBeatAddress()).Returns(heartBeatUri);
     heartBeatInterval = TimeSpan.FromSeconds(5);
     heartBeatSenderConfigProvider.Setup(m => m.GetHeartBeatInterval()).Returns(heartBeatInterval);
     clusterMonitor = new ClusterMonitor(scaleOutConfigurationProvider.Object,
                                         autoDiscoverySender.Object,
                                         autoDiscoveryListener.Object,
                                         heartBeatSenderConfigProvider.Object,
                                         routeDiscovery.Object,
                                         securityProvider.Object,
                                         logger.Object);
 }
Example #4
0
        public void DeleteClusterMember(SocketEndpoint node)
        {
            ClusterMemberMeta meta;
            clusterMembers.TryRemove(node, out meta);

            logger.Debug($"Dead route removed Uri:{node.Uri.AbsoluteUri} " +
                             $"Socket:{node.Identity.GetString()}");
        }
Example #5
0
 public void AddClusterMember(SocketEndpoint node)
 {
     if (clusterMembers.TryAdd(node, new ClusterMemberMeta {LastKnownPong = DateTime.UtcNow}))
     {
         logger.Debug($"New node added " +
                      $"Uri:{node.Uri.AbsoluteUri} " +
                      $"Socket:{node.Identity.GetString()}");
     }
 }
 public void SetActiveScaleOutAddress(SocketEndpoint activeAddress)
 {
     if (scaleOutConfig.AddressRange.Contains(activeAddress))
     {
         scaleOutAddressSource.SetResult(activeAddress);
     }
     else
     {
         throw new Exception($"SocketEndpoint {activeAddress.Uri.ToSocketAddress()} is not configured!");
     }
 }
Example #7
0
        public bool KeepAlive(SocketEndpoint node)
        {
            ClusterMemberMeta meta;
            var updated = clusterMembers.TryGetValue(node, out meta);
            if (updated)
            {
                meta.LastKnownPong = DateTime.UtcNow;
            }

            return updated;
        }
        public void TestAddClusterMember()
        {
            var config = new ClusterMembership(membershipConfiguration, logger);
            var localhost = "tcp://127.0.0.1:40";
            var ep1 = new SocketEndpoint(new Uri(localhost), Guid.NewGuid().ToByteArray());
            var ep2 = new SocketEndpoint(new Uri(localhost), Guid.NewGuid().ToByteArray());
            config.AddClusterMember(ep1);
            config.AddClusterMember(ep2);

            CollectionAssert.Contains(config.GetClusterMembers(), ep1);
            CollectionAssert.Contains(config.GetClusterMembers(), ep2);
        }
Example #9
0
 public void Setup()
 {
     autoDiscoverySender           = new Mock <IAutoDiscoverySender>();
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutAddress = new SocketEndpoint("tcp://127.0.0.1:9090");
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     config           = new ClusterMembershipConfiguration();
     securityProvider = new Mock <ISecurityProvider>();
     domain           = Guid.NewGuid().ToString();
     securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
     logger         = new Mock <ILogger>();
     routeDiscovery = new RouteDiscovery(autoDiscoverySender.Object,
                                         scaleOutConfigurationProvider.Object,
                                         config,
                                         securityProvider.Object,
                                         logger.Object);
 }
        public void TestNodeConsideredDead_IfLastKnownPongWasLongerThanPongSilenceBeforeRouteDeletionAgo()
        {
            var config = new ClusterMembership(membershipConfiguration, logger);
            var localhost = "tcp://127.0.0.1:40";
            var ep1 = new SocketEndpoint(new Uri(localhost), Guid.NewGuid().ToByteArray());
            var ep2 = new SocketEndpoint(new Uri(localhost), Guid.NewGuid().ToByteArray());
            config.AddClusterMember(ep1);
            config.AddClusterMember(ep2);

            var pingTime = DateTime.UtcNow;
            var pingDelay = TimeSpan.FromSeconds(3);
            Thread.Sleep(membershipConfiguration.PongSilenceBeforeRouteDeletion + pingDelay);

            config.KeepAlive(ep1);
            
            CollectionAssert.Contains(config.GetDeadMembers(pingTime, pingInterval), ep2);
            CollectionAssert.DoesNotContain(config.GetDeadMembers(pingTime, pingInterval), ep1);
        }
Example #11
0
 public void Setup()
 {
     callbackHandlerStack = new Mock <ICallbackHandlerStack>();
     logger = new Mock <ILogger>().Object;
     messageHubSocketFactory = new MessageHubSocketFactory();
     socketFactory           = new Mock <ISocketFactory>();
     socketFactory.Setup(m => m.CreateDealerSocket()).Returns(messageHubSocketFactory.CreateSocket);
     securityProvider = new Mock <ISecurityProvider>();
     securityProvider.Setup(m => m.DomainIsAllowed(It.IsAny <string>())).Returns(true);
     routerSocket       = new Mock <ILocalSocket <IMessage> >();
     registrationSocket = new Mock <ILocalSendingSocket <InternalRouteRegistration> >();
     localSocketFactory = new Mock <ILocalSocketFactory>();
     receivingSocket    = new Mock <ILocalSocket <IMessage> >();
     localSocketFactory.Setup(m => m.Create <IMessage>()).Returns(receivingSocket.Object);
     scaleOutAddress = new SocketEndpoint(new Uri("tcp://127.0.0.1:5000"), Guid.NewGuid().ToByteArray());
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     messageHub = CreateMessageHub();
 }
 public void Setup()
 {
     socketFactory = new Mock <ISocketFactory>();
     socket        = new Mock <ISocket>();
     socketFactory.Setup(m => m.CreatePublisherSocket()).Returns(socket.Object);
     config = new Mock <IHeartBeatSenderConfigurationManager>();
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutAddress = new SocketEndpoint("tcp://127.0.0.1:8080");
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     heartBeatInterval = TimeSpan.FromMilliseconds(800);
     config.Setup(m => m.GetHeartBeatInterval()).Returns(heartBeatInterval);
     heartBeatAddresses = new[] { new Uri("tcp://127.0.0.1:9090"), new Uri("tcp://127.0.0.2:9090") };
     config.Setup(m => m.GetHeartBeatAddressRange()).Returns(heartBeatAddresses);
     config.Setup(m => m.GetHeartBeatAddress()).Returns(heartBeatAddresses.First());
     logger          = new Mock <ILogger>();
     heartBeatSender = new HeartBeatSender(socketFactory.Object,
                                           config.Object,
                                           scaleOutConfigurationProvider.Object,
                                           logger.Object);
 }
Example #13
0
        public AutoDiscoveryListenerTests()
        {
            rendezvousCluster   = new Mock <IRendezvousCluster>();
            rendezvousEndpoints = new[]
            {
                new RendezvousEndpoint("tcp://*:8080", "tcp://*:9090"),
                new RendezvousEndpoint("tcp://*:8081", "tcp://*:9091")
            };
            currentRendezvousIndex = 0;
            rendezvousCluster.Setup(m => m.GetCurrentRendezvousServer()).Returns(GetCurrentRendezvous());
            rendezvousCluster.Setup(m => m.RotateRendezvousServers()).Callback(SetNextRendezvous);
            rendezvousCluster.Setup(m => m.Reconfigure(It.IsAny <IEnumerable <RendezvousEndpoint> >()))
            .Callback <IEnumerable <RendezvousEndpoint> >(SetNewRendezvous);
            socketFactory      = new Mock <ISocketFactory>();
            subscriptionSocket = new Mock <ISocket>();
            socketFactory.Setup(m => m.CreateSubscriberSocket()).Returns(subscriptionSocket.Object);
            scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
            scaleOutAddress = new SocketEndpoint("tcp://*:7878", Guid.NewGuid().ToByteArray());
            scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
            membershipConfiguration = new ClusterMembershipConfiguration
            {
                HeartBeatSilenceBeforeRendezvousFailover = TimeSpan.FromSeconds(1)
            };
            performanceCounterManager = new Mock <IPerformanceCounterManager <KinoPerformanceCounters> >();
            var perfCounter = new Mock <IPerformanceCounter>();

            performanceCounterManager.Setup(m => m.GetCounter(It.IsAny <KinoPerformanceCounters>())).Returns(perfCounter.Object);
            localRouterSocket     = new Mock <ILocalSocket <IMessage> >();
            logger                = new Mock <ILogger>();
            restartRequestHandler = new Mock <Action>();
            gateway               = new Barrier(1);
            autoDiscoveryListener = new AutoDiscoveryListener(rendezvousCluster.Object,
                                                              socketFactory.Object,
                                                              scaleOutConfigurationProvider.Object,
                                                              membershipConfiguration,
                                                              performanceCounterManager.Object,
                                                              localRouterSocket.Object,
                                                              logger.Object);
        }
Example #14
0
 public ClusterMonitorTests()
 {
     securityProvider = new Mock <ISecurityProvider>();
     domain           = Guid.NewGuid().ToString();
     securityProvider.Setup(m => m.GetAllowedDomains()).Returns(new[] { domain });
     securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
     logger          = new Mock <ILogger>();
     routeDiscovery  = new Mock <IRouteDiscovery>();
     scaleOutAddress = new SocketEndpoint(new Uri("tcp://127.0.0.1:5000"), Guid.NewGuid().ToByteArray());
     scaleOutConfigurationProvider = new Mock <IScaleOutConfigurationProvider>();
     scaleOutConfigurationProvider.Setup(m => m.GetScaleOutAddress()).Returns(scaleOutAddress);
     autoDiscoverySender           = new Mock <IAutoDiscoverySender>();
     autoDiscoveryListener         = new Mock <IAutoDiscoveryListener>();
     heartBeatSenderConfigProvider = new Mock <IHeartBeatSenderConfigurationProvider>();
     heartBeatUri = new Uri("tcp://127.0.0.1:890");
     heartBeatSenderConfigProvider.Setup(m => m.GetHeartBeatAddress()).Returns(heartBeatUri);
     heartBeatInterval = TimeSpan.FromSeconds(5);
     heartBeatSenderConfigProvider.Setup(m => m.GetHeartBeatInterval()).Returns(heartBeatInterval);
     config = new ClusterMembershipConfiguration
     {
         RouteDiscovery = new RouteDiscoveryConfiguration
         {
             ClusterAutoDiscoveryStartDelay = TimeSpan.FromSeconds(1),
             ClusterAutoDiscoveryPeriod     = TimeSpan.FromSeconds(2),
             ClusterAutoDiscoveryStartDelayMaxMultiplier = 2,
             MaxAutoDiscoverySenderQueueLength           = 100
         }
     };
     clusterMonitor = new ClusterMonitor(scaleOutConfigurationProvider.Object,
                                         autoDiscoverySender.Object,
                                         autoDiscoveryListener.Object,
                                         heartBeatSenderConfigProvider.Object,
                                         routeDiscovery.Object,
                                         securityProvider.Object,
                                         config,
                                         logger.Object);
 }
Example #15
0
 private void AddClusterMember(IMessage message)
 {
     var registration = message.GetPayload<RegisterExternalMessageRouteMessage>();
     var clusterMember = new SocketEndpoint(new Uri(registration.Uri), registration.SocketIdentity);
     clusterMembership.AddClusterMember(clusterMember);
 }
 public NullScaleOutConfigurationManager()
 {
     localEndpoint = new SocketEndpoint(new Uri("tcp://localhost"), IdentityExtensions.Empty);
 }
 public void SetActiveScaleOutAddress(SocketEndpoint activeAddress)
 {
 }
Example #18
0
 public IncomingMessage(SocketEndpoint endpoint, byte[] data, int size)
 {
     Endpoint = endpoint;
     Data     = data;
     Size     = size;
 }
 public SocketEndpoint GetScaleOutAddress()
 => scaleOutAddress ?? (scaleOutAddress = scaleOutAddressSource.Task.Result);
Example #20
0
 public MessageRouterSocketFactory(SocketEndpoint scaleOutAddress)
 {
     this.scaleOutAddress = scaleOutAddress;
     sockets           = new ConcurrentBag <MockSocket>();
     socketWaitTimeout = TimeSpan.FromSeconds(5);
 }
Example #21
0
 internal void PushRouterAddress(SocketEndpoint scaleOutAddress)
 => routing.Add(scaleOutAddress);