DeclarativeSampler implements SamplerFunction<M> { @Deprecated public SamplingFlags sample(@Nullable M method) { if (method == null) return SamplingFlags.EMPTY; return SamplingFlags.Builder.build(trySample(method)); } DeclarativeSampler(); static DeclarativeSampler<M> createWithProbability(
    ProbabilityOfMethod<M> probabilityOfMethod); static DeclarativeSampler<M> createWithRate(RateOfMethod<M> rateOfMethod); @Override @Nullable Boolean trySample(@Nullable M method); static DeclarativeSampler<M> create(RateForMethod<M> rateForMethod); @Deprecated Sampler toSampler(M method); @Deprecated Sampler toSampler(M method, Sampler fallback); @Deprecated SamplingFlags sample(@Nullable M method);  }
@Test public void acceptsFallback() { assertThat(declarativeSampler.sample(traced(1.0f, 0, false))) .isEqualTo(SamplingFlags.EMPTY); }
@Test public void samplerLoadsLazy() { assertThat(declarativeSampler.methodToSamplers) .isEmpty(); declarativeSampler.sample(traced(1.0f, 0, true)); assertThat(declarativeSampler.methodToSamplers) .hasSize(1); declarativeSampler.sample(traced(0.0f, 0, true)); assertThat(declarativeSampler.methodToSamplers) .hasSize(2); }
@Test public void cardinalityIsPerAnnotationNotInvocation() { Traced traced = traced(1.0f, 0, true); declarativeSampler.sample(traced); declarativeSampler.sample(traced); declarativeSampler.sample(traced); assertThat(declarativeSampler.methodToSamplers) .hasSize(1); }