Exemplo n.º 1
0
        public void Should_not_throw_if_someone_else_dispose_zookeeper_client_after_start()
        {
            var disposedClient = GetZooKeeperClient();

            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            CreateEnvironmentNode(replica.Environment);

            using (var beacon = new ServiceBeacon(disposedClient, replica, null, Log))
            {
                ReplicaRegistered(replica).Should().BeFalse();

                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);
                ReplicaRegistered(replica).Should().BeTrue();

                disposedClient.Dispose();

                beacon.Stop();
            }
        }
Exemplo n.º 2
0
        public void Start_should_run_iterations_loop()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            var calls  = 0;
            var client = Substitute.For <IZooKeeperClient>();

            client.OnConnectionStateChanged.Returns(new CachingObservable <ConnectionState>(ConnectionState.Connected));
            client.ExistsAsync(Arg.Any <ExistsRequest>())
            .Returns(
                c =>
            {
                Log.Info($"{c.Args()[0]}");
                Interlocked.Increment(ref calls);
                return(Task.FromResult(ExistsResult.Successful("", new NodeStat(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))));
            });
            client.DeleteAsync(Arg.Any <DeleteRequest>()).Returns(Task.FromResult(DeleteResult.Successful("")));

            var settings = new ServiceBeaconSettings
            {
                IterationPeriod = 200.Milliseconds(),
                MinimumTimeBetweenIterations = 0.Milliseconds()
            };

            using (var beacon = new ServiceBeacon(client, replica, settings, Log))
            {
                beacon.Start();

                Thread.Sleep((4 * 200).Milliseconds());

                beacon.Stop();
            }

            // One call for environment, one for node.
            calls.Should().BeInRange(2 * 2, 2 * 10);
        }
Exemplo n.º 3
0
        private void SetUpServices(IAppBuilder appBuilder, Container container)
        {
            var log             = container.GetInstance <ILog>();
            var serviceSettings = container.GetInstance <IServiceSettings>();

            ProcessPriorityHelper.SetMemoryPriority(ProcessMemoryPriority.Normal, log);
            ProcessPriorityHelper.SetProcessPriorityClass(ProcessPriorityClass.Normal, log);
            ThreadPoolUtility.SetUp(log, serviceSettings.GetThreadMultiplier());

            var serviceBeacon = new ServiceBeacon(log, serviceSettings.GetPort());

            serviceBeacon.Start();

            var metricsWorker = container.GetInstance <MetricsWorker>();

            metricsWorker.Start();

            appBuilder.OnDisposing(
                () =>
            {
                serviceBeacon.Stop();
                metricsWorker.Stop();
            });
        }