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); }
public void Build() { var logger = resolver.Resolve <ILogger>(); var applicationConfig = resolver.Resolve <LeaseProviderServiceConfiguration>(); var socketFactory = new SocketFactory(resolver.Resolve <SocketConfiguration>()); var synodConfigProvider = new SynodConfigurationProvider(applicationConfig.LeaseProvider.Synod); #if NET47 var instanceNameResolver = resolver.Resolve <IInstanceNameResolver>() ?? new InstanceNameResolver(); var performanceCounterManager = new PerformanceCounterManager <KinoPerformanceCounters>(instanceNameResolver, logger); #else var performanceCounterManager = default(IPerformanceCounterManager <KinoPerformanceCounters>); #endif var intercomMessageHub = new IntercomMessageHub(socketFactory, synodConfigProvider, performanceCounterManager, logger); var ballotGenerator = new BallotGenerator(applicationConfig.LeaseProvider.Lease); kino = new kino(resolver); messageHub = kino.GetMessageHub(); leaseProvider = new LeaseProvider(intercomMessageHub, ballotGenerator, synodConfigProvider, applicationConfig.LeaseProvider.Lease, applicationConfig.LeaseProvider, messageHub, logger); var serializer = new ProtobufMessageSerializer(); kino.AssignActor(new LeaseProviderActor(leaseProvider, serializer, applicationConfig.LeaseProvider, logger)); kino.AssignActor(new InstanceDiscoveryActor(leaseProvider, applicationConfig.LeaseProvider)); kino.AssignActor(new InstanceBuilderActor(leaseProvider, applicationConfig.LeaseProvider)); kino.AssignActor(new ExceptionHandlerActor(logger)); }
public void WhenHeartBeatMessageArrives_LastKnownHeartBeatIsUpdated() { synodConfigProvider.Setup(m => m.MissingHeartBeatsBeforeReconnect).Returns(1); messageHub = new IntercomMessageHub(socketFactory.Object, synodConfigProvider.Object, perfCounterManager.Object, logger.Object); var messageCount = 1; var deadNode = messageHub.GetClusterHealthInfo().First(); var message = Message.Create(new HeartBeatMessage { NodeUri = deadNode.NodeUri.ToSocketAddress() }); subscriberSocket.Setup(m => m.ReceiveMessage(It.IsAny <CancellationToken>())).Returns(() => messageCount-- > 0 ? message : null); synodConfigProvider.Object .HeartBeatInterval .MultiplyBy(synodConfigProvider.Object.MissingHeartBeatsBeforeReconnect + 1) .Sleep(); var timeout = synodConfigProvider.Object .HeartBeatInterval .DivideBy(2); // Assert.False(deadNode.IsHealthy()); messageHub.Start(timeout); timeout.Sleep(); messageHub.Stop(); // Assert.True(deadNode.IsHealthy()); }
internal static RoundBasedRegisterTestSetup CreateRoundBasedRegister(IEnumerable <string> synod, string localNodeUri) { var appConfig = new RendezvousServiceConfiguration { Synod = new SynodConfiguration { Members = synod, LocalNode = localNodeUri, HeartBeatInterval = TimeSpan.FromSeconds(5), IntercomEndpoint = $"inproc://{Guid.NewGuid()}", MissingHeartBeatsBeforeReconnect = 4 }, Lease = new LeaseConfiguration { ClockDrift = TimeSpan.FromMilliseconds(10), MessageRoundtrip = TimeSpan.FromMilliseconds(100), NodeResponseTimeout = TimeSpan.FromMilliseconds(1000), MaxLeaseTimeSpan = TimeSpan.FromSeconds(3) } }; var socketConfig = new SocketConfiguration { ReceivingHighWatermark = 1000, SendingHighWatermark = 1000, Linger = TimeSpan.Zero }; var logger = new Mock <ILogger>(); var performanceCounterManager = new Mock <IPerformanceCounterManager <KinoPerformanceCounters> >(); var synodConfigProvider = new SynodConfigurationProvider(appConfig.Synod); var intercomMessageHub = new IntercomMessageHub(new SocketFactory(socketConfig), synodConfigProvider, performanceCounterManager.Object, logger.Object); var ballotGenerator = new BallotGenerator(appConfig.Lease); var roundBasedRegister = new RoundBasedRegister(intercomMessageHub, ballotGenerator, synodConfigProvider, appConfig.Lease, logger.Object); logger.Verify(m => m.Error(It.IsAny <object>()), Times.Never); return(new RoundBasedRegisterTestSetup(ballotGenerator, synodConfigProvider.LocalNode, roundBasedRegister)); }
private IRendezvousService Build() { var logger = resolver.Resolve <ILogger>(); var applicationConfig = resolver.Resolve <RendezvousServiceConfiguration>(); var socketFactory = new SocketFactory(applicationConfig.Socket); var synodConfigProvider = new SynodConfigurationProvider(applicationConfig.Synod); #if NET47 var instanceNameResolver = resolver.Resolve <IInstanceNameResolver>() ?? new InstanceNameResolver(); var performanceCounterManager = new PerformanceCounterManager <KinoPerformanceCounters>(instanceNameResolver, logger); #else var performanceCounterManager = default(IPerformanceCounterManager <KinoPerformanceCounters>); #endif var intercomMessageHub = new IntercomMessageHub(socketFactory, synodConfigProvider, performanceCounterManager, logger); var ballotGenerator = new BallotGenerator(applicationConfig.Lease); var roundBasedRegister = new RoundBasedRegister(intercomMessageHub, ballotGenerator, synodConfigProvider, applicationConfig.Lease, logger); var leaseProvider = new LeaseProvider(roundBasedRegister, ballotGenerator, applicationConfig.Lease, synodConfigProvider, logger); var serializer = new ProtobufMessageSerializer(); var configProvider = new RendezvousConfigurationProvider(applicationConfig.Rendezvous); var service = new RendezvousService(leaseProvider, synodConfigProvider, socketFactory, serializer, configProvider, performanceCounterManager, logger); return(service); }
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); }
internal static RoundBasedRegisterTestSetup CreateRoundBasedRegister(IEnumerable <string> synod, string localNodeUri) { var appConfig = new RendezvousServiceConfiguration { Synod = new SynodConfiguration { Members = synod, LocalNode = localNodeUri }, Lease = new LeaseConfiguration { ClockDrift = TimeSpan.FromMilliseconds(10), MessageRoundtrip = TimeSpan.FromMilliseconds(100), NodeResponseTimeout = TimeSpan.FromMilliseconds(1000), MaxLeaseTimeSpan = TimeSpan.FromSeconds(3) } }; var socketConfig = new SocketConfiguration { ReceivingHighWatermark = 1000, SendingHighWatermark = 1000, Linger = TimeSpan.Zero }; var synodConfig = new global::kino.Consensus.Configuration.SynodConfiguration(new SynodConfigurationProvider(appConfig.Synod)); var logger = new Mock <ILogger>(); var performanceCounterManager = new Mock <IPerformanceCounterManager <KinoPerformanceCounters> >(); var intercomMessageHub = new IntercomMessageHub(new SocketFactory(socketConfig), synodConfig, performanceCounterManager.Object, logger.Object); var ballotGenerator = new BallotGenerator(appConfig.Lease); var roundBasedRegister = new RoundBasedRegister(intercomMessageHub, ballotGenerator, synodConfig, appConfig.Lease, logger.Object); return(new RoundBasedRegisterTestSetup(ballotGenerator, synodConfig.LocalNode, roundBasedRegister, appConfig.Lease.MaxLeaseTimeSpan)); }