public void StatsBufferize()
        {
            var handler       = new BufferBuilderHandlerMock();
            var bufferBuilder = new BufferBuilder(handler, 30, "\n");
            var serializers   = new Serializers
            {
                EventSerializer = new EventSerializer(new SerializerHelper(null)),
            };
            var statsRouter = new StatsRouter(serializers, bufferBuilder, null);

            using (var statsBufferize = new StatsBufferize(statsRouter, 10, null, TimeSpan.Zero))
            {
                var pool  = new Pool <Stats>(p => new Stats(p), 1);
                var stats = new Stats(pool)
                {
                    Kind = StatsKind.Event
                };
                stats.Event.Text  = "test";
                stats.Event.Title = "title";

                statsBufferize.Send(stats);
                while (handler.Buffer == null)
                {
                    Task.Delay(TimeSpan.FromMilliseconds(1)).Wait();
                }

                // Sent because buffer is full.
                Assert.AreEqual("_e{5,4}:title|test", Encoding.UTF8.GetString(handler.Buffer));
            }
        }
Exemplo n.º 2
0
 public StatsdData(
     MetricsSender metricsSender,
     StatsBufferize statsBufferize,
     ITransport transport,
     Telemetry telemetry)
 {
     MetricsSender   = metricsSender;
     Telemetry       = telemetry;
     _statsBufferize = statsBufferize;
     _transport      = transport;
 }
Exemplo n.º 3
0
 internal MetricsSender(
     StatsBufferize statsBufferize,
     IRandomGenerator randomGenerator,
     IStopWatchFactory stopwatchFactory,
     Telemetry optionalTelemetry,
     bool truncateIfTooLong,
     int poolMaxAllocation)
 {
     _stopwatchFactory  = stopwatchFactory;
     _statsBufferize    = statsBufferize;
     _randomGenerator   = randomGenerator;
     _optionalTelemetry = optionalTelemetry;
     _truncateIfTooLong = truncateIfTooLong;
     _pool = new Pool <Stats>(pool => new Stats(pool), poolMaxAllocation);
 }
Exemplo n.º 4
0
 internal MetricsSender(
     StatsBufferize statsBufferize,
     IRandomGenerator randomGenerator,
     IStopWatchFactory stopwatchFactory,
     Serializers serializers,
     Telemetry optionalTelemetry,
     bool truncateIfTooLong)
 {
     _stopwatchFactory  = stopwatchFactory;
     _statsBufferize    = statsBufferize;
     _randomGenerator   = randomGenerator;
     _optionalTelemetry = optionalTelemetry;
     _serializers       = serializers;
     _truncateIfTooLong = truncateIfTooLong;
 }
Exemplo n.º 5
0
        public void Dispose()
        {
            // _statsBufferize and _telemetry must be disposed before _statsSender to make
            // sure _statsSender does not received data when it is already disposed.

            Telemetry?.Dispose();
            Telemetry = null;

            _statsBufferize?.Dispose();
            _statsBufferize = null;

            _transport?.Dispose();
            _transport = null;

            MetricsSender = null;
        }
        public void StatsBufferize()
        {
            var handler       = new BufferBuilderHandlerMock();
            var bufferBuilder = new BufferBuilder(handler, 3, "\n");

            using (var statsBufferize = new StatsBufferize(new Telemetry(), bufferBuilder, 10, null, TimeSpan.Zero))
            {
                statsBufferize.Send("1");
                while (handler.Buffer == null)
                {
                    Task.Delay(TimeSpan.FromMilliseconds(1)).Wait();
                }

                // Sent because buffer is full.
                Assert.AreEqual("1", Encoding.UTF8.GetString(handler.Buffer));
            }
        }
        public async Task StatsBufferize()
        {
            var handler        = new BufferBuilderHandlerMock();
            var bufferBuilder  = new BufferBuilder(handler, 3, "\n");
            var timeout        = TimeSpan.FromMilliseconds(300);
            var statsBufferize = new StatsBufferize(bufferBuilder, 10, null, timeout);

            statsBufferize.Send("123");
            statsBufferize.Send("4");
            await Task.Delay(timeout.Multiply(0.5));

            // Sent because buffer is full.
            Assert.AreEqual(Encoding.UTF8.GetBytes("123"), handler.Buffer);

            // Sent because we wait more than the timeout.
            await Task.Delay(timeout.Multiply(2));

            Assert.AreEqual(Encoding.UTF8.GetBytes("4"), handler.Buffer);
        }
Exemplo n.º 8
0
        public void StatsBufferize()
        {
            var handler       = new BufferBuilderHandlerMock();
            var bufferBuilder = new BufferBuilder(handler, 3, "\n");

            using (var statsBufferize = new StatsBufferize(bufferBuilder, 10, null, TimeSpan.Zero))
            {
                var serializedMetric = new SerializedMetric(new Pool <SerializedMetric>(p => new SerializedMetric(p), 10));
                serializedMetric.Builder.Append("1");

                statsBufferize.Send(serializedMetric);
                while (handler.Buffer == null)
                {
                    Task.Delay(TimeSpan.FromMilliseconds(1)).Wait();
                }

                // Sent because buffer is full.
                Assert.AreEqual("1", Encoding.UTF8.GetString(handler.Buffer));
            }
        }