public void TestRegisterMessageHandlers_AddsActorIdentifier()
        {
            var internalRoutingTable = new InternalRoutingTable();

            var router = new MessageRouter(socketFactory.Object,
                                           internalRoutingTable,
                                           new ExternalRoutingTable(logger),
                                           routerConfiguration,
                                           clusterMonitor.Object,
                                           messageTracer.Object,
                                           logger);
            try
            {
                StartMessageRouter(router);

                var messageIdentity = Guid.NewGuid().ToByteArray();
                var version = Guid.NewGuid().ToByteArray();
                var socketIdentity = Guid.NewGuid().ToByteArray();
                var message = Message.Create(new RegisterInternalMessageRouteMessage
                                             {
                                                 SocketIdentity = socketIdentity,
                                                 MessageContracts = new[]
                                                                    {
                                                                        new MessageContract
                                                                        {
                                                                            Identity = messageIdentity,
                                                                            Version = version
                                                                        }
                                                                    }
                                             },
                                             RegisterInternalMessageRouteMessage.MessageIdentity);
                messageRouterSocketFactory.GetRouterSocket().DeliverMessage(message);

                Thread.Sleep(AsyncOpCompletionDelay);

                var identifier = internalRoutingTable.FindRoute(new MessageIdentifier(version, messageIdentity));

                Assert.IsNotNull(identifier);
                Assert.IsTrue(identifier.Equals(new SocketIdentifier(socketIdentity)));
                CollectionAssert.AreEqual(socketIdentity, identifier.Identity);
            }
            finally
            {
                router.Stop();
            }
        }
Beispiel #2
0
        public void Build()
        {
            AssertDependencyResolverSet();

            var configurationProvider             = new ConfigurationProvider(resolver.Resolve <KinoConfiguration>());
            var scaleOutSocketConfiguration       = configurationProvider.GetScaleOutConfiguration();
            var clusterMembershipConfiguration    = configurationProvider.GetClusterMembershipConfiguration();
            var clusterHealthMonitorConfiguration = configurationProvider.GetClusterHealthMonitorConfiguration();
            var heartBeatSenderConfiguration      = configurationProvider.GetHeartBeatSenderConfiguration();
            var socketConfiguration = configurationProvider.GetSocketConfiguration();
            var rendezvousEndpoints = configurationProvider.GetRendezvousEndpointsConfiguration();
            var socketFactory       = new SocketFactory(socketConfiguration);
            var logger = resolver.Resolve <ILogger>();
            var roundRobinDestinationList  = new RoundRobinDestinationList(logger);
            var internalRoutingTable       = new InternalRoutingTable(roundRobinDestinationList);
            var externalRoutingTable       = new ExternalRoutingTable(roundRobinDestinationList, logger);
            var localSocketFactory         = new LocalSocketFactory();
            var routerLocalSocket          = new LocalSocket <IMessage>();
            var internalRegistrationSocket = new LocalSocket <InternalRouteRegistration>();

#if NET47
            var instanceNameResolver      = resolver.Resolve <IInstanceNameResolver>() ?? new InstanceNameResolver();
            var performanceCounterManager = new PerformanceCounterManager <KinoPerformanceCounters>(instanceNameResolver,
                                                                                                    logger);
#else
            var performanceCounterManager = default(IPerformanceCounterManager <KinoPerformanceCounters>);
#endif

            var hashCodeProvider = resolver.Resolve <Func <HMAC> >() ?? (() => HMAC.Create("HMACMD5"));

            var securityProvider = resolver.Resolve <ISecurityProvider>()
                                   ?? new SecurityProvider(hashCodeProvider,
                                                           resolver.Resolve <IDomainScopeResolver>(),
                                                           resolver.Resolve <IDomainPrivateKeyProvider>());
            var heartBeatSenderConfigurationManager = new HeartBeatSenderConfigurationManager(heartBeatSenderConfiguration);
            var configurationStorage = resolver.Resolve <IConfigurationStorage <RendezvousClusterConfiguration> >()
                                       ?? new RendezvousClusterConfigurationReadonlyStorage(rendezvousEndpoints);
            var rendezvousCluster = new RendezvousCluster(configurationStorage);

            var scaleoutConfigurationProvider = new ServiceLocator <ScaleOutConfigurationManager,
                                                                    NullScaleOutConfigurationManager,
                                                                    IScaleOutConfigurationManager>(clusterMembershipConfiguration,
                                                                                                   new ScaleOutConfigurationManager(scaleOutSocketConfiguration),
                                                                                                   new NullScaleOutConfigurationManager())
                                                .GetService();
            var connectedPeerRegistry = new ConnectedPeerRegistry(clusterHealthMonitorConfiguration);
            var clusterHealthMonitor  = new ServiceLocator <ClusterHealthMonitor,
                                                            NullClusterHealthMonitor,
                                                            IClusterHealthMonitor>(clusterMembershipConfiguration,
                                                                                   new ClusterHealthMonitor(socketFactory,
                                                                                                            localSocketFactory,
                                                                                                            securityProvider,
                                                                                                            routerLocalSocket,
                                                                                                            connectedPeerRegistry,
                                                                                                            clusterHealthMonitorConfiguration,
                                                                                                            logger),
                                                                                   new NullClusterHealthMonitor())
                                        .GetService();

            var heartBeatSender = new ServiceLocator <HeartBeatSender,
                                                      NullHeartBeatSender,
                                                      IHeartBeatSender>(clusterMembershipConfiguration,
                                                                        new HeartBeatSender(socketFactory,
                                                                                            heartBeatSenderConfigurationManager,
                                                                                            scaleoutConfigurationProvider,
                                                                                            logger),
                                                                        new NullHeartBeatSender())
                                  .GetService();
            var scaleOutListener = new ServiceLocator <ScaleOutListener,
                                                       NullScaleOutListener,
                                                       IScaleOutListener>(clusterMembershipConfiguration,
                                                                          new ScaleOutListener(socketFactory,
                                                                                               routerLocalSocket,
                                                                                               scaleoutConfigurationProvider,
                                                                                               securityProvider,
                                                                                               performanceCounterManager,
                                                                                               logger),
                                                                          new NullScaleOutListener())
                                   .GetService();
            var autoDiscoverSender = new AutoDiscoverySender(rendezvousCluster,
                                                             socketFactory,
                                                             clusterMembershipConfiguration,
                                                             performanceCounterManager,
                                                             logger);
            var autoDiscoveryListener = new AutoDiscoveryListener(rendezvousCluster,
                                                                  socketFactory,
                                                                  scaleoutConfigurationProvider,
                                                                  clusterMembershipConfiguration,
                                                                  performanceCounterManager,
                                                                  routerLocalSocket,
                                                                  logger);
            var routeDiscovery = new RouteDiscovery(autoDiscoverSender,
                                                    scaleoutConfigurationProvider,
                                                    clusterMembershipConfiguration,
                                                    securityProvider,
                                                    logger);
            var clusterMonitor = new ServiceLocator <ClusterMonitor,
                                                     NullClusterMonitor,
                                                     IClusterMonitor>(clusterMembershipConfiguration,
                                                                      new ClusterMonitor(scaleoutConfigurationProvider,
                                                                                         autoDiscoverSender,
                                                                                         autoDiscoveryListener,
                                                                                         heartBeatSenderConfigurationManager,
                                                                                         routeDiscovery,
                                                                                         securityProvider,
                                                                                         clusterMembershipConfiguration,
                                                                                         logger),
                                                                      new NullClusterMonitor())
                                 .GetService();
            var clusterServices = new ClusterServices(clusterMonitor,
                                                      scaleOutListener,
                                                      heartBeatSender,
                                                      clusterHealthMonitor);
            var nodeRoutesRegistrar = new NodeRoutesRegistrar(clusterServices,
                                                              internalRoutingTable,
                                                              securityProvider);
            var internalMessageRouteRegistrationHandler = new InternalMessageRouteRegistrationHandler(clusterMonitor,
                                                                                                      internalRoutingTable,
                                                                                                      securityProvider);
            var serviceMessageHandlers = new IServiceMessageHandler[]
            {
                new ClusterMessageRoutesRequestHandler(securityProvider,
                                                       nodeRoutesRegistrar),
                new PingHandler(),
                new ExternalMessageRouteRegistrationHandler(externalRoutingTable,
                                                            securityProvider,
                                                            clusterHealthMonitor,
                                                            logger),
                new MessageRouteDiscoveryHandler(clusterMonitor,
                                                 internalRoutingTable,
                                                 securityProvider,
                                                 logger),
                new MessageRouteUnregistrationHandler(clusterHealthMonitor,
                                                      externalRoutingTable,
                                                      securityProvider,
                                                      logger),
                new NodeMessageRoutesRequestHandler(securityProvider,
                                                    nodeRoutesRegistrar),
                new NodeUnregistrationHandler(clusterHealthMonitor,
                                              externalRoutingTable,
                                              securityProvider),
                new UnreachableNodeUnregistrationHandler(clusterHealthMonitor,
                                                         externalRoutingTable)
            };
            var serviceMessageHandlerRegistry = new ServiceMessageHandlerRegistry(serviceMessageHandlers);
            messageRouter = new MessageRouter(socketFactory,
                                              internalRoutingTable,
                                              externalRoutingTable,
                                              scaleoutConfigurationProvider,
                                              clusterServices,
                                              serviceMessageHandlerRegistry,
                                              performanceCounterManager,
                                              securityProvider,
                                              routerLocalSocket,
                                              internalRegistrationSocket,
                                              internalMessageRouteRegistrationHandler,
                                              roundRobinDestinationList,
                                              logger);
            var actorHostFactory = new ActorHostFactory(securityProvider,
                                                        routerLocalSocket,
                                                        internalRegistrationSocket,
                                                        localSocketFactory,
                                                        logger);
            var callbackHandlerStack = new CallbackHandlerStack();
            createMessageHub = (keepLocal) => new MessageHub(callbackHandlerStack,
                                                             routerLocalSocket,
                                                             internalRegistrationSocket,
                                                             localSocketFactory,
                                                             scaleoutConfigurationProvider,
                                                             securityProvider,
                                                             logger,
                                                             keepLocal);
            var messageHub = createMessageHub(false);
            getMessageHub    = () => messageHub;
            actorHostManager = new ActorHostManager(actorHostFactory, logger);

            internalActorHostManager = new ActorHostManager(actorHostFactory, logger);
            var internalActor = new MessageRoutesActor(externalRoutingTable, internalRoutingTable);
            internalActorHostManager.AssignActor(internalActor);
            //
            isBuilt = true;
        }
        private void Build()
        {
            var socketFactory       = new SocketFactory();
            var perfCountersManager = CreatePerfCountersManager();
            var localSocketFactory  = new LocalSocketFactory();
            var routerLocalSocket   = localSocketFactory.Create <IMessage>();

            var internalRoutingTable         = new InternalRoutingTable();
            var externalRoutingTable         = new ExternalRoutingTable(logger);
            var scaleOutConfigurationManager = new ScaleOutConfigurationManager(configurationProvider.GetRouterConfiguration(),
                                                                                configurationProvider.GetScaleOutConfiguration());

            var rendezvousConfigurationStorage = new RendezvousClusterConfigurationReadonlyStorage(configurationProvider.GetRendezvousEndpointsConfiguration());
            var rendezvousCluster = new RendezvousCluster(rendezvousConfigurationStorage);
            var securityProider   = new SecurityProvider(() => HMAC.Create("HMACMD5"),
                                                         domainScopeResolver,
                                                         domainPrivateKeyProvider);
            var autoDiscoverSender = new AutoDiscoverySender(rendezvousCluster,
                                                             scaleOutConfigurationManager,
                                                             socketFactory,
                                                             perfCountersManager,
                                                             securityProider,
                                                             logger);
            var autoDiscoverListener = new AutoDiscoveryListener(rendezvousCluster,
                                                                 socketFactory,
                                                                 scaleOutConfigurationManager,
                                                                 autoDiscoverSender,
                                                                 configurationProvider.GetClusterMembershipConfiguration(),
                                                                 perfCountersManager,
                                                                 securityProider,
                                                                 routerLocalSocket,
                                                                 logger);
            var routeDiscovery = new RouteDiscovery(autoDiscoverSender,
                                                    scaleOutConfigurationManager,
                                                    configurationProvider.GetClusterMembershipConfiguration(),
                                                    securityProider,
                                                    logger);
            var heartBeatSenderConfigurationManager = new HeartBeatSenderConfigurationManager(configurationProvider.GetHeartBeatSenderConfiguration());
            var clusterConnectivity = new ClusterConnectivity(configurationProvider.GetClusterMembershipConfiguration(),
                                                              scaleOutConfigurationManager,
                                                              autoDiscoverSender,
                                                              autoDiscoverListener,
                                                              routeDiscovery,
                                                              socketFactory,
                                                              routerLocalSocket,
                                                              scaleOutConfigurationManager,
                                                              securityProider,
                                                              perfCountersManager,
                                                              logger,
                                                              heartBeatSenderConfigurationManager,
                                                              localSocketFactory,
                                                              configurationProvider.GetClusterHealthMonitorConfiguration());
            var internalRegistrationsSocket  = localSocketFactory.Create <InternalRouteRegistration>();
            var internalRegistrationsHandler = new InternalMessageRouteRegistrationHandler(clusterConnectivity,
                                                                                           internalRoutingTable,
                                                                                           securityProider,
                                                                                           logger);

            messageRouter = new MessageRouter(socketFactory,
                                              internalRoutingTable,
                                              externalRoutingTable,
                                              scaleOutConfigurationManager,
                                              clusterConnectivity,
                                              CreateServiceMessageHandlers(clusterConnectivity,
                                                                           externalRoutingTable,
                                                                           internalRoutingTable,
                                                                           securityProider),
                                              perfCountersManager,
                                              securityProider,
                                              routerLocalSocket,
                                              internalRegistrationsSocket,
                                              internalRegistrationsHandler,
                                              logger);

            actorHostManager = new ActorHostManager(securityProider,
                                                    perfCountersManager,
                                                    routerLocalSocket,
                                                    internalRegistrationsSocket,
                                                    localSocketFactory,
                                                    logger);
            var callbackHandlerStack = new CallbackHandlerStack();

            messageHub = new MessageHub(callbackHandlerStack,
                                        perfCountersManager,
                                        routerLocalSocket,
                                        internalRegistrationsSocket,
                                        localSocketFactory,
                                        logger,
                                        false);
        }
        public void TestIfMessageRouterCanHandleMessage_SelfRegisterIsCalled()
        {
            var internalRoutingTable = new InternalRoutingTable();
            var router = new MessageRouter(socketFactory.Object,
                                           internalRoutingTable,
                                           new ExternalRoutingTable(logger),
                                           routerConfiguration,
                                           clusterMonitor.Object,
                                           messageTracer.Object,
                                           logger);
            try
            {
                StartMessageRouter(router);

                var messageIdentifier = new MessageIdentifier(Message.CurrentVersion, SimpleMessage.MessageIdentity);
                internalRoutingTable.AddMessageRoute(messageIdentifier, SocketIdentifier.Create());
                var message = Message.Create(new DiscoverMessageRouteMessage
                                             {
                                                 MessageContract = new MessageContract
                                                                   {
                                                                       Version = messageIdentifier.Version,
                                                                       Identity = messageIdentifier.Identity
                                                                   }
                                             },
                                             DiscoverMessageRouteMessage.MessageIdentity);
                messageRouterSocketFactory.GetRouterSocket().DeliverMessage(message);

                Thread.Sleep(AsyncOp);

                Assert.IsTrue(internalRoutingTable.CanRouteMessage(messageIdentifier));
                clusterMonitor.Verify(m => m.RegisterSelf(It.Is<IEnumerable<MessageIdentifier>>(ids => ids.First().Equals(messageIdentifier))), Times.Once());
            }
            finally
            {
                router.Stop();
            }
        }
Beispiel #5
0
 public void Setup()
 {
     internalRoutingTable = new InternalRoutingTable();
 }