@Test public void create_forNewContext_noPermitAvailable() { when(ratelimiter.tryAcquire()).thenReturn(false); TraceOptionsFactory traceOptionsFactory = new RateLimitingTraceOptionsFactory(ratelimiter, true); TraceOptions traceOptions = traceOptionsFactory.create(); assertThat(traceOptions.getTraceEnabled()).isFalse(); assertThat(traceOptions.getStackTraceEnabled()).isTrue(); }
@Override public TraceOptions create() { boolean traceEnabled = rateLimiter.tryAcquire(); return new TraceOptions() .overrideTraceEnabled(traceEnabled) .overrideStackTraceEnabled(stackTraceEnabled); }
RateLimitingTraceOptionsFactory implements TraceOptionsFactory { @Override public TraceOptions create() { boolean traceEnabled = rateLimiter.tryAcquire(); return new TraceOptions() .overrideTraceEnabled(traceEnabled) .overrideStackTraceEnabled(stackTraceEnabled); } }
RateLimitingTraceOptionsFactory implements TraceOptionsFactory { @Override public TraceOptions create() { boolean traceEnabled = rateLimiter.tryAcquire(); return new TraceOptions() .overrideTraceEnabled(traceEnabled) .overrideStackTraceEnabled(stackTraceEnabled); } RateLimitingTraceOptionsFactory(double samplingRate, boolean stackTraceEnabled); @VisibleForTesting  RateLimitingTraceOptionsFactory(RateLimiter rateLimiter, boolean stackTraceEnabled); }
RateLimitingTraceOptionsFactory implements TraceOptionsFactory { @Override public TraceOptions create() { boolean traceEnabled = rateLimiter.tryAcquire(); return new TraceOptions() .overrideTraceEnabled(traceEnabled) .overrideStackTraceEnabled(stackTraceEnabled); } RateLimitingTraceOptionsFactory(double samplingRate, boolean stackTraceEnabled); @VisibleForTesting  RateLimitingTraceOptionsFactory(RateLimiter rateLimiter, boolean stackTraceEnabled); @Override TraceOptions create(); @Override TraceOptions create(TraceOptions traceOptions); }
RateLimitingTraceOptionsFactory implements TraceOptionsFactory { @Override public TraceOptions create() { boolean traceEnabled = rateLimiter.tryAcquire(); return new TraceOptions() .overrideTraceEnabled(traceEnabled) .overrideStackTraceEnabled(stackTraceEnabled); } RateLimitingTraceOptionsFactory(double samplingRate, boolean stackTraceEnabled); @VisibleForTesting  RateLimitingTraceOptionsFactory(RateLimiter rateLimiter, boolean stackTraceEnabled); @Override TraceOptions create(); @Override TraceOptions create(TraceOptions traceOptions);  }