def test_parse_sampling_strategy(): # probabilistic resp = sampling_manager.SamplingStrategyResponse( strategyType=sampling_manager.SamplingStrategyType.PROBABILISTIC) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.probabilisticSampling = \ sampling_manager.ProbabilisticSamplingStrategy(samplingRate=2) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.probabilisticSampling = \ sampling_manager.ProbabilisticSamplingStrategy(samplingRate=0.5) s, e = thrift.parse_sampling_strategy(response=resp) assert isinstance(s, ProbabilisticSampler) and e is None # rate limiting resp = sampling_manager.SamplingStrategyResponse( strategyType=sampling_manager.SamplingStrategyType.RATE_LIMITING) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.rateLimitingSampling = \ sampling_manager.RateLimitingSamplingStrategy(maxTracesPerSecond=-1) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.rateLimitingSampling = \ sampling_manager.RateLimitingSamplingStrategy(maxTracesPerSecond=1) s, e = thrift.parse_sampling_strategy(response=resp) assert isinstance(s, RateLimitingSampler) and e is None # wrong strategy type resp.strategyType = 'x' s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None
def test_parse_sampling_strategy(): # probabilistic resp = sampling_manager.SamplingStrategyResponse( strategyType=sampling_manager.SamplingStrategyType.PROBABILISTIC) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.probabilisticSampling = \ sampling_manager.ProbabilisticSamplingStrategy(samplingRate=2) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.probabilisticSampling = \ sampling_manager.ProbabilisticSamplingStrategy(samplingRate=0.5) s, e = thrift.parse_sampling_strategy(response=resp) assert isinstance(s, ProbabilisticSampler) and e is None # rate limiting resp = sampling_manager.SamplingStrategyResponse( strategyType=sampling_manager.SamplingStrategyType.RATE_LIMITING) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.rateLimitingSampling = \ sampling_manager.RateLimitingSamplingStrategy(maxTracesPerSecond=-1) s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None resp.rateLimitingSampling = \ sampling_manager.RateLimitingSamplingStrategy(maxTracesPerSecond=1) s, e = thrift.parse_sampling_strategy(response=resp) assert isinstance(s, RateLimitingSampler) and e is None # wrong strategy type resp.strategyType = 'x' s, e = thrift.parse_sampling_strategy(response=resp) assert s is None and e is not None