Ejemplo n.º 1
0
        public void NormalConstructor_HostAndPort_Ok()
        {
            var settings = new GraphiteSettings("localhost", 80);

            Assert.That(settings.Host, Is.EqualTo("localhost"));
            Assert.That(settings.HttpApiPort, Is.EqualTo(80));
        }
Ejemplo n.º 2
0
        public static async Task UdpWriteAsync(
            this List <GraphitePayload> batches,
            GraphiteSettings graphiteSettings,
            HttpPolicy httpPolicy,
            ILogger <GraphiteClient> logger,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            await CreateClient(graphiteSettings, httpPolicy);

            var currentBatch = 1;

            foreach (var batch in batches)
            {
                var text = batch.Format(graphiteSettings.MetricNameFormatter);

                logger.LogDebug(text);

                var datagram = Encoding.UTF8.GetBytes(text);

                await _client.Client.SendAsync(new ArraySegment <byte>(datagram), SocketFlags.None);

                logger.LogTrace($"Successful batch {currentBatch} / {batches.Count} write to Graphite (UDP)");

                currentBatch++;
            }
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            _settings = new GraphiteSettings()
            {
                Host            = "192.0.2.0",
                HttpApiPort     = 10,
                BatchSize       = 500,
                ThrowExceptions = true
            };
            _log           = new FakeLog();
            _configuration = new FakeConfiguration();
            _environment   = new FakeEnvironment(PlatformFamily.Windows)
            {
                WorkingDirectory = new DirectoryPath(Environment.CurrentDirectory)
            };
            _fileSystem = new FakeFileSystem(_environment);
            _globber    = new Globber(_fileSystem, _environment);

            var mockArguments = new Mock <ICakeArguments>();

            mockArguments.Setup(x => x.GetArgument(It.IsAny <string>())).Returns(string.Empty);
            mockArguments.Setup(x => x.HasArgument(It.IsAny <string>())).Returns(false);
            _arguments = mockArguments.Object;

            _toolLocator   = new ToolLocator(_environment, new ToolRepository(_environment), new ToolResolutionStrategy(_fileSystem, _environment, _globber, _configuration));
            _processRunner = new ProcessRunner(_fileSystem, _environment, _log, _toolLocator, _configuration);

            var mockDataService = new Mock <ICakeDataService>();

            mockDataService.Setup(x => x.Add(It.IsAny <string>()));
            _dataService = mockDataService.Object;

            _context = new CakeContext(_fileSystem, _environment, _globber, _log, _arguments, _processRunner, new WindowsRegistry(), _toolLocator, _dataService, _configuration);
        }
Ejemplo n.º 4
0
        public void NormalConstructor_HostPortAndSsl_Ok()
        {
            var settings = new GraphiteSettings("localhost", 80, false);

            Assert.That(settings.Host, Is.EqualTo("localhost"));
            Assert.That(settings.HttpApiPort, Is.EqualTo(80));
            Assert.That(settings.UseSsl, Is.EqualTo(false));
        }
        public void base_address_cannot_be_null()
        {
            Action action = () =>
            {
                var settings = new GraphiteSettings((Uri)null);
            };

            action.ShouldThrow <ArgumentNullException>();
        }
Ejemplo n.º 6
0
        public void NormalConstructor_HostPortSslBatchSizeAndThrowExceptions_Ok()
        {
            var settings = new GraphiteSettings("localhost", 80, false, 123, true);

            Assert.That(settings.Host, Is.EqualTo("localhost"));
            Assert.That(settings.HttpApiPort, Is.EqualTo(80));
            Assert.That(settings.UseSsl, Is.EqualTo(false));
            Assert.That(settings.BatchSize, Is.EqualTo(123));
            Assert.That(settings.ThrowExceptions, Is.EqualTo(true));
        }
        private static async Task <TcpClient> CreateClient(
            GraphiteSettings graphiteSettings,
            HttpPolicy httpPolicy)
        {
            var client = new TcpClient {
                SendTimeout = httpPolicy.Timeout.Milliseconds
            };
            await client.ConnectAsync(graphiteSettings.BaseAddress.Host, graphiteSettings.BaseAddress.Port);

            return(client);
        }
Ejemplo n.º 8
0
 public void Setup()
 {
     _settings = new GraphiteSettings()
     {
         Host            = "192.0.2.0",
         HttpApiPort     = 10,
         BatchSize       = 500,
         ThrowExceptions = true
     };
     _log = new FakeLog();
 }
Ejemplo n.º 9
0
        private static async Task CreateClient(
            GraphiteSettings graphiteSettings,
            HttpPolicy httpPolicy)
        {
            if (_client == null)
            {
                _client = new UdpClient {
                    Client = { SendTimeout = httpPolicy.Timeout.Milliseconds }
                };
            }

            await _client.Client.ConnectAsync(graphiteSettings.BaseAddress.Host, graphiteSettings.BaseAddress.Port);
        }
        public static async Task TcpWriteAsync(
            this List <GraphitePayload> batches,
            GraphiteSettings graphiteSettings,
            HttpPolicy httpPolicy,
            ILogger <GraphiteClient> logger,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var client = await CreateClient(graphiteSettings, httpPolicy))
            {
                using (var stream = client.GetStream())
                {
                    using (var writer = new StreamWriter(stream)
                    {
                        NewLine = "\n"
                    })
                    {
                        var currentBatch = 1;

                        foreach (var batch in batches)
                        {
                            var text = batch.Format(graphiteSettings.MetricNameFormatter);

                            logger.LogDebug(text);

                            await writer.WriteLineAsync(text);

                            logger.LogTrace($"Successful batch {currentBatch} / {batches.Count} write to Graphite (TCP)");

                            currentBatch++;
                        }

                        await writer.FlushAsync();
                    }

                    await stream.FlushAsync(cancellationToken);
                }
            }
        }
Ejemplo n.º 11
0
        public void NormalConstructor_OnlyHost_Ok()
        {
            var settings = new GraphiteSettings("localhost");

            Assert.That(settings.Host, Is.EqualTo("localhost"));
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="GraphiteReporterSettings" /> class.
 /// </summary>
 public GraphiteReporterSettings()
 {
     GraphiteSettings = new GraphiteSettings();
     HttpPolicy       = new HttpPolicy();
     ReportInterval   = TimeSpan.FromSeconds(5);
 }
        public void can_determine_protocol(string address, Protocol expected)
        {
            var settings = new GraphiteSettings(new Uri(address));

            settings.Protocol.Should().Be(expected);
        }