RemoteControlledSampler implements Sampler { @Override public void close() { pollTimer.cancel(); } private  RemoteControlledSampler(Builder builder); @Override SamplingStatus sample(String operation, long id); @Override boolean equals(Object sampler); @Override void close(); static final String TYPE; }
@Test public void testUpdateFailureKeepsTimerRunning() throws InterruptedException { undertest.close(); CountDownLatch latch = new CountDownLatch(3); SamplingManager failingManager = serviceName -> { latch.countDown(); throw new RuntimeException("test update failure"); }; undertest = new RemoteControlledSampler.Builder(SERVICE_NAME) .withSamplingManager(failingManager) .withInitialSampler(initialSampler) .withMetrics(metrics) .withPollingInterval(1) .build(); assertTrue(latch.await(1, TimeUnit.SECONDS)); }
@Test public void testDefaultProbabilisticSampler() { undertest.close(); undertest = new RemoteControlledSampler.Builder(SERVICE_NAME) .withSamplingManager(samplingManager) .withInitialSampler(null) .withMetrics(metrics) .build(); assertEquals(new ProbabilisticSampler(0.001), undertest.getSampler()); }