コード例 #1
0
        public void TestUpdateToProbabilisticSampler()
        {
            double samplingRate = 0.55;
            SamplingStrategyResponse probabilisticResponse = new SamplingStrategyResponse(
                new ProbabilisticSamplingStrategy(samplingRate), null, null);

            _samplingManager.GetSamplingStrategyAsync(SERVICE_NAME).Returns(probabilisticResponse);

            _undertest.UpdateSampler();

            Assert.Equal(new ProbabilisticSampler(samplingRate), _undertest.Sampler);
        }
コード例 #2
0
        public void UpdateSampler_ShouldCatchAndIndicateException()
        {
            _mockSamplingManager.GetSamplingStrategy(Arg.Is <string>(sn => sn == _serivceName)).Throws(new Exception());

            _testingSampler.UpdateSampler();

            _mockSamplingManager.Received(1).GetSamplingStrategy(Arg.Is <string>(sn => sn == _serivceName));
            _mockMetrics.Received(1).SamplerQueryFailure.Inc(Arg.Is <long>(delta => delta == 1));
            _mockMetrics.Received(0).SamplerRetrieved.Inc(Arg.Any <long>());
        }
コード例 #3
0
        public async Task TestUpdatePerOperationSamplerUpdatesExistingPerOperationSampler()
        {
            OperationSamplingParameters parameters          = new OperationSamplingParameters(1, 1, new List <PerOperationSamplingParameters>());
            PerOperationSampler         perOperationSampler = Substitute.ForPartsOf <PerOperationSampler>(10, parameters, NullLoggerFactory.Instance);

            _samplingManager.GetSamplingStrategyAsync(SERVICE_NAME)
            .Returns(new SamplingStrategyResponse(null, null, parameters));

            _undertest = new RemoteControlledSampler.Builder(SERVICE_NAME)
                         .WithSamplingManager(_samplingManager)
                         .WithInitialSampler(perOperationSampler)
                         .WithMetrics(_metrics)
                         .Build();

            _undertest.UpdateSampler();
            await Task.Delay(20);

            //updateSampler is hit once automatically because of the pollTimer
            perOperationSampler.Received(2).Update(parameters);
        }