HttpSamplingManager implements SamplingManager { SamplingStrategyResponse parseJson(String json) { try { return gson.fromJson(json, SamplingStrategyResponse.class); } catch (JsonSyntaxException e) { throw new SamplingStrategyErrorException("Cannot deserialize json", e); } } HttpSamplingManager();  HttpSamplingManager(String hostPort); @Override SamplingStrategyResponse getSamplingStrategy(String serviceName); static final String DEFAULT_HOST_PORT; }
@Test public void testParseProbabilisticSampling() throws Exception { SamplingStrategyResponse response = undertest.parseJson(readFixture("probabilistic_sampling.json")); assertEquals(new ProbabilisticSamplingStrategy(0.01), response.getProbabilisticSampling()); assertNull(response.getRateLimitingSampling()); }
@Test public void testParseRateLimitingSampling() throws Exception { SamplingStrategyResponse response = undertest.parseJson(readFixture("ratelimiting_sampling.json")); assertEquals(new RateLimitingSamplingStrategy(2.1), response.getRateLimitingSampling()); assertNull(response.getProbabilisticSampling()); }
@Test (expected = SamplingStrategyErrorException.class) public void testParseInvalidJson() throws Exception { undertest.parseJson("invalid json"); }
@Test public void testParsePerOperationSampling() throws Exception { SamplingStrategyResponse response = undertest.parseJson(readFixture("per_operation_sampling.json")); OperationSamplingParameters actual = response.getOperationSampling(); assertEquals(0.001, actual.getDefaultSamplingProbability(), 0.0001); assertEquals(0.001666, actual.getDefaultLowerBoundTracesPerSecond(),0.0001); List<PerOperationSamplingParameters> actualPerOperationStrategies = actual.getPerOperationStrategies(); assertEquals(2, actualPerOperationStrategies.size()); assertEquals( new PerOperationSamplingParameters("GET:/search", new ProbabilisticSamplingStrategy(1.0)), actualPerOperationStrategies.get(0)); assertEquals( new PerOperationSamplingParameters("PUT:/pacifique", new ProbabilisticSamplingStrategy(0.8258308134813166)), actualPerOperationStrategies.get(1)); }