Inheritance: Metric, IAllowsInteger, IAllowsSampleRate, IAllowsAggregate
コード例 #1
0
            public void does_not_send_metric_immediately()
            {
                var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var sender = new BatchSender();
                sender.StatsdUDP = _udp;
                sender.Send(metric);

                _udp.AssertWasNotCalled(x => x.Send(Arg<string>.Is.Anything));
            }
コード例 #2
0
 public void does_not_blow_up_if_udp_send_throws()
 {
     var udpStub = MockRepository.GenerateStub<IStatsdUDP>();
     udpStub.Stub(x => x.Send(Arg<string>.Is.Anything)).Throw(new Exception());
     var metric = new Counting() { Name = "testMetric", ValueAsInt = 1 };
     var sender = new BatchSender    ();
     sender.StatsdUDP = udpStub;
     sender.Send(metric);
     sender.Flush();
     Assert.Pass();
 }
コード例 #3
0
            public void sends_metric_on_flush()
            {
                var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var sender = new BatchSender();
                sender.StatsdUDP = _udp;
                sender.Send(metric);
                sender.Flush();

                IList<object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                Assert.That(argsPerCall.Count, Is.EqualTo(1));
                Assert.That(((string)argsPerCall[0][0]), Is.EqualTo(metric.Command));
            }
コード例 #4
0
            public void sends_multiple_metrics_at_once()
            {
                var metric1 = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var metric2 = new Timing() { Name = "testtimer", ValueAsInt = 10 };

                var sender = new BatchSender();
                sender.StatsdUDP = _udp;
                sender.Send(metric1);
                sender.Send(metric2);
                sender.Flush();

                IList<object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                Assert.That(argsPerCall.Count, Is.EqualTo(1));
                var packet = (string)argsPerCall[0][0];
                var lines = packet.Split('\n');
                Assert.That(lines.Length, Is.EqualTo(2));
                Assert.That(lines[0], Is.EqualTo(metric1.Command));
                Assert.That(lines[1], Is.EqualTo(metric2.Command));
            }
コード例 #5
0
            public void sends_after_delay()
            {
                var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                DateTime timeCalled = DateTime.MaxValue;
                var udpStub = MockRepository.GenerateStub<IStatsdUDP>();
                udpStub.Stub(x => x.Send(Arg<string>.Is.Anything))
                    .WhenCalled(m => timeCalled = DateTime.Now);

                var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 2000 });
                sender.StatsdUDP = udpStub;
                DateTime startTime = DateTime.Now;
                sender.Send(metric);
                Thread.Sleep(3000);

                IList<object[]> argsPerCall = udpStub.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                Assert.That(argsPerCall.Count, Is.EqualTo(1));
                Assert.That(((string)argsPerCall[0][0]), Is.EqualTo(metric.Command));

                var sendDelay = (timeCalled - startTime).TotalMilliseconds;
                Assert.That(sendDelay, Is.GreaterThanOrEqualTo(2000));
            }
コード例 #6
0
 public void does_not_blow_up_if_udp_send_throws()
 {
     var udpStub = MockRepository.GenerateStub<IStatsdUDP>();
     udpStub.Stub(x => x.Send(Arg<string>.Is.Anything)).Throw(new Exception());
     var metric = new Counting() { Name = "testMetric", ValueAsInt = 1 };
     var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 2000 });
     sender.StatsdUDP = udpStub;
     sender.Send(metric);
     Assert.Pass();
 }
コード例 #7
0
            public void does_not_exceed_max_packet_size()
            {
                var udpStub = MockRepository.GenerateStub<IStatsdUDP>();
                udpStub.Stub(x => x.MaxUDPPacketSize).Return(300);

                var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 1000 });
                sender.StatsdUDP = udpStub;

                for (var i = 0; i < 100; i ++)
                {
                    var metricName = (Guid.NewGuid()).ToString();
                    var metric = new Counting() { Name = metricName, ValueAsInt = 1 };
                    sender.Send(metric);
                }

                Thread.Sleep(3000);
                IList<object[]> argsPerCall = udpStub.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                for (var i = 0; i < argsPerCall.Count; i++)
                {
                    var packetSize = ((string)argsPerCall[i][0]).Length;
                    Assert.That(packetSize, Is.LessThanOrEqualTo(300));
                }
            }
コード例 #8
0
            public void does_not_block()
            {
                var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 2000 });
                sender.StatsdUDP = _udp;

                DateTime startTime = DateTime.Now;
                sender.Send(metric);
                DateTime endTime = DateTime.Now;

                var methodCallDelay = (endTime - startTime).TotalMilliseconds;
                Assert.That(methodCallDelay, Is.LessThan(10));
            }
コード例 #9
0
            public void bundles_multiple_metrics_into_one_packet()
            {
                var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 1000 });
                sender.StatsdUDP = _udp;
                var metricsToSend = 10;
                for (var i = 0; i < metricsToSend; i++)
                {
                    var metricName = (Guid.NewGuid()).ToString();
                    var metric = new Counting() { Name = metricName, ValueAsInt = 1 };
                    sender.Send(metric);
                }

                Thread.Sleep(3000);
                IList<object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                var packetsReceived = argsPerCall.Count;
                Assert.That(packetsReceived, Is.LessThan(metricsToSend));
            }
コード例 #10
0
            public void aggregates_counters()
            {
                var sender = new ThreadSafeConsumerProducerSender(new ThreadSafeConsumerProducerSender.Configuration() { MaxSendDelayMS = 1000 });
                sender.StatsdUDP = _udp;
                var metricsToSend = 10;
                for (var i = 0; i < metricsToSend; i++)
                {
                    var metric = new Counting() { Name = "testMetric", ValueAsInt = 1 };
                    sender.Send(metric);
                }

                Thread.Sleep(1500);
                IList<object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                Assert.That(argsPerCall.Count, Is.EqualTo(1));
                Assert.That(((string)argsPerCall[0][0]), Is.EqualTo("testMetric:" + metricsToSend.ToString() + "|c"));
            }
コード例 #11
0
            public void does_not_send_anything()
            {
                var metric = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var sender = new MockSender();
                sender.Send(metric);

                _udp.AssertWasNotCalled(x => x.Send(Arg<string>.Is.Anything));
            }
コード例 #12
0
            public void sends_multiple_metrics_individually()
            {
                var metric1 = new Counting() { Name = "testMetric", ValueAsInt = 5 };
                var metric2 = new Timing() { Name = "testtimer", ValueAsInt = 10 };

                var sender = new ImmediateSender();
                sender.StatsdUDP = _udp;
                sender.Send(metric1);
                sender.Send(metric2);

                IList<object[]> argsPerCall = _udp.GetArgumentsForCallsMadeOn(x => x.Send(Arg<string>.Is.Anything));
                Assert.That(argsPerCall.Count, Is.EqualTo(2));
                Assert.That(((string)argsPerCall[0][0]), Is.EqualTo(metric1.Command));
                Assert.That(((string)argsPerCall[1][0]), Is.EqualTo(metric2.Command));
            }