### Question:
RateLimitingSampler implements Sampler { @Override public SamplingResult shouldSample( SpanContext parentContext, String traceId, String name, Kind spanKind, ReadableAttributes attributes, List<SpanData.Link> parentLinks) { if (parentContext.isSampled()) { return Samplers.alwaysOn() .shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); } if (parentLinks != null) { for (SpanData.Link parentLink : parentLinks) { if (parentLink.getContext().isSampled()) { return Samplers.alwaysOn() .shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); } } } return this.rateLimiter.checkCredit(1.0) ? onSamplingResult : offSamplingResult; } RateLimitingSampler(int maxTracesPerSecond); @Override SamplingResult shouldSample(
      SpanContext parentContext,
      String traceId,
      String name,
      Kind spanKind,
      ReadableAttributes attributes,
      List<SpanData.Link> parentLinks); @Override String getDescription(); @Override String toString();  }### Answer:
@Test void alwaysSampleSampledContext() { RateLimitingSampler sampler = new RateLimitingSampler(1); assertThat( sampler .shouldSample( sampledSpanContext, traceId, SPAN_NAME, SPAN_KIND, Attributes.empty(), Collections.emptyList()) .getDecision()) .isEqualTo(Decision.RECORD_AND_SAMPLE); assertThat( sampler .shouldSample( sampledSpanContext, traceId, SPAN_NAME, SPAN_KIND, Attributes.empty(), Collections.emptyList()) .getDecision()) .isEqualTo(Decision.RECORD_AND_SAMPLE); }
@Test void sampleOneTrace() { RateLimitingSampler sampler = new RateLimitingSampler(1); SamplingResult samplingResult = sampler.shouldSample( notSampledSpanContext, traceId, SPAN_NAME, SPAN_KIND, Attributes.empty(), Collections.emptyList()); assertThat(samplingResult.getDecision()).isEqualTo(Decision.RECORD_AND_SAMPLE); assertThat( sampler .shouldSample( notSampledSpanContext, traceId, SPAN_NAME, SPAN_KIND, Attributes.empty(), Collections.emptyList()) .getDecision()) .isEqualTo(Decision.DROP); assertEquals(2, samplingResult.getAttributes().size()); assertEquals(1d, samplingResult.getAttributes().get(RateLimitingSampler.SAMPLER_PARAM)); assertEquals( RateLimitingSampler.TYPE, samplingResult.getAttributes().get(RateLimitingSampler.SAMPLER_TYPE)); }