public void UpdatePerOperationSampler_ShouldUpdateParams_WhenSamplerIsAlreadyPerOp() { var perOpSampler = new PerOperationSampler(10, 0.5, 5, _mockLoggerFactory); _testingSampler = new RemoteControlledSampler( _serivceName, _mockSamplingManager, _mockLoggerFactory, _mockMetrics, perOpSampler, _mockSamplerFactory, _pollingIntervalMs, _mockPollTimer ); var strategies = new PerOperationSamplingStrategies { DefaultSamplingProbability = 0.5, DefaultLowerBoundTracesPerSecond = 10, PerOperationStrategies = new List <OperationSamplingStrategy>() }; _testingSampler.UpdatePerOperationSampler(strategies); _mockMetrics.Received(1).SamplerUpdated.Inc(Arg.Is <long>(d => d == 1)); }
public RemoteControlledSamplerTests() { _serivceName = "testService"; _mockSamplingManager = Substitute.For <ISamplingManager>(); _mockLoggerFactory = Substitute.For <ILoggerFactory>(); _mockSampler = Substitute.For <ISampler>(); _mockMetrics = Substitute.For <IMetrics>(); _pollingIntervalMs = 5000; _mockSamplerFactory = Substitute.For <ISamplerFactory>(); _mockLogger = Substitute.For <ILogger <RemoteControlledSampler> >(); _mockPollTimer = Substitute.For <Func <Action, int, CancellationToken, Task> >(); _mockLoggerFactory.CreateLogger <RemoteControlledSampler>().Returns(_mockLogger); _testingSampler = new RemoteControlledSampler( _serivceName, _mockSamplingManager, _mockLoggerFactory, _mockMetrics, _mockSampler, _mockSamplerFactory, _pollingIntervalMs, _mockPollTimer ); }
public void TestDefaultProbabilisticSampler() { _undertest = new RemoteControlledSampler.Builder(SERVICE_NAME) .WithSamplingManager(_samplingManager) .WithMetrics(_metrics) .Build(); Assert.Equal(new ProbabilisticSampler(0.001), _undertest.Sampler); }
public async void PollTimer_DelaysAndCallsUpdateFunc() { var updateFunc = Substitute.For <Action>(); var pollingIntervalMs = 1000; var cts = new CancellationTokenSource(); cts.CancelAfter(2900); await RemoteControlledSampler.PollTimer(updateFunc, pollingIntervalMs, cts.Token); updateFunc.Received(3)(); }
public RemoteControlledSamplerTests() { _loggerFactory = new NullLoggerFactory(); _samplingManager = Substitute.For <ISamplingManager>(); _initialSampler = Substitute.For <ISampler>(); _metrics = new MetricsImpl(new InMemoryMetricsFactory()); _undertest = new RemoteControlledSampler.Builder(SERVICE_NAME) .WithSamplingManager(_samplingManager) .WithInitialSampler(_initialSampler) .WithMetrics(_metrics) .Build(); }
public void Equals_ShouldBeTrue_WhenTheSamplerIsTheSame() { var equalSampler = new RemoteControlledSampler( _serivceName, _mockSamplingManager, _mockLoggerFactory, _mockMetrics, _mockSampler, _mockSamplerFactory, _pollingIntervalMs, _mockPollTimer ); Assert.True(_testingSampler.Equals(equalSampler)); }
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); }
public void Dispose_ShouldCancelToken() { var passedInPollingInt = 0; var passedInCancelToken = new CancellationToken(); _mockPollTimer(Arg.Any <Action>(), Arg.Do <int>(i => passedInPollingInt = i), Arg.Do <CancellationToken>(ct => passedInCancelToken = ct)); _testingSampler = new RemoteControlledSampler( _serivceName, _mockSamplingManager, _mockLoggerFactory, _mockMetrics, _mockSampler, _mockSamplerFactory, _pollingIntervalMs, _mockPollTimer ); _testingSampler.Dispose(); Assert.Equal(_pollingIntervalMs, passedInPollingInt); Assert.True(passedInCancelToken.IsCancellationRequested); }