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));
            }
        }
        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);
        }
Ejemplo n.º 4
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));
            }
        }
 public void Init()
 {
     _handler       = new BufferBuilderHandlerMock();
     _bufferBuilder = new BufferBuilder(_handler, 12, "\n");
 }