CountSampler extends Sampler { @Override public boolean next() { return (count++ % frequency) == 0; } CountSampler(HTraceConfiguration conf); @Override boolean next(); final static String SAMPLER_FREQUENCY_CONF_KEY; }
@Test public void testNext() { CountSampler half = new CountSampler(HTraceConfiguration. fromKeyValuePairs("sampler.frequency", "2")); CountSampler hundred = new CountSampler(HTraceConfiguration. fromKeyValuePairs("sampler.frequency", "100")); int halfCount = 0; int hundredCount = 0; for (int i = 0; i < 200; i++) { if (half.next()) halfCount++; if (hundred.next()) hundredCount++; } Assert.assertEquals(2, hundredCount); Assert.assertEquals(100, halfCount); }