public void addCheck(Check check) throws IOException { final LinkedHashMap<String, Check> newValue = new LinkedHashMap<String, Check>(getChecks()); newValue.put(check.getId(), check); checks.update(newValue, SimpleSource.NAME); }
@Test public void testValidationFailedPerTypeOption() throws Exception { assertThatThrownBy(() -> tracingPlugin.getRateLimitSpansPerMinutePercentPerTypeOption() .update(singletonMap("jdbc", 10.0), SimpleSource.NAME)) .isInstanceOf(IllegalArgumentException.class); assertThat(tracingPlugin.getRateLimitSpansPerMinutePercentPerTypeOption().getValue()).isEqualTo(emptyMap()); }
@Test public void testChangeListener() throws Exception { AtomicBoolean changeListenerInvoked = new AtomicBoolean(false); exampleConfiguration.getOptionalExample() .addChangeListener((configurationOption, oldValue, newValue) -> changeListenerInvoked.set(true)); // saves a value into a specific configuration source exampleConfiguration.getOptionalExample().update(Optional.of("foo"), SimpleSource.NAME); assertThat(changeListenerInvoked).isTrue(); }
@Test public void testValidationFailed() throws Exception { assertThatThrownBy(() -> tracingPlugin.getDefaultRateLimitSpansPercentOption() .update(10.0, SimpleSource.NAME)) .isInstanceOf(IllegalArgumentException.class); assertThat(tracingPlugin.getDefaultRateLimitSpansPercentOption().getValue()).isEqualTo(1.0); }
@Test public void testReportSpanGenericType() throws Exception { when(spanContext.getOperationType()).thenReturn("jdbc"); tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0d, SimpleSource.NAME); tracingPlugin.getRateLimitSpansPerMinutePercentPerTypeOption().update(singletonMap("http", 1d), SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testSample51Percent() throws Exception { tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0.51, SimpleSource.NAME); int reports = 0; for (int i = 0; i < 100; i++) { final PreExecutionInterceptorContext context = new PreExecutionInterceptorContext(spanContext); interceptor.interceptReport(context); if (context.isReport()) { reports++; } } assertThat(reports).isEqualTo(51); }
@Test public void testReportSpanType() throws Exception { interceptor = new ProbabilisticSamplingPreExecutionInterceptor() { @Override protected boolean isRoot(SpanWrapper span) { return false; } }; interceptor.init(configuration); when(spanContext.getOperationType()).thenReturn("http"); tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0d, SimpleSource.NAME); tracingPlugin.getRateLimitSpansPerMinutePercentPerTypeOption().update(singletonMap("http", 1d), SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); }
@Test public void testUpdate() throws IOException { assertNull(testUpdate.getValue()); testUpdate.update("updated!", "Test Configuration Source"); assertEquals("updated!", testUpdate.getValue()); }
@Test public void testAlwaysReportSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPercentOption().update(1.0, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); }
@Test public void dontMakeSamplingDecisionsForNonRootTraces() throws Exception { interceptor = new ProbabilisticSamplingPreExecutionInterceptor() { @Override protected boolean isRoot(SpanWrapper span) { return false; } }; interceptor.init(configuration); tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); }
@Test public void makeSamplingDecisionsForRootTraces() throws Exception { interceptor = new RateLimitingPreExecutionInterceptor() { @Override protected boolean isRoot(SpanWrapper span) { return true; } }; interceptor.init(configuration); tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void dontMakeSamplingDecisionsForNonRootTraces() throws Exception { interceptor = new RateLimitingPreExecutionInterceptor() { @Override protected boolean isRoot(SpanWrapper span) { return false; } }; interceptor.init(configuration); tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); }
@Test public void makeSamplingDecisionsForRootTraces() throws Exception { interceptor = new ProbabilisticSamplingPreExecutionInterceptor() { @Override protected boolean isRoot(SpanWrapper span) { return true; } }; interceptor.init(configuration); tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); } }
@Test public void testNeverReportSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testRateExceededThenNotExceededSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(60.0, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testRateNotExceededThenExceededSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPerMinuteOption().update(60d, SimpleSource.NAME); interceptor.interceptReport(context); assertTrue(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test public void testNeverReportSpan() throws Exception { tracingPlugin.getDefaultRateLimitSpansPercentOption().update(0d, SimpleSource.NAME); interceptor.interceptReport(context); assertFalse(context.isReport()); interceptor.interceptReport(context); assertFalse(context.isReport()); }
@Test void testSamplingNone() throws IOException { config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); Transaction transaction = tracerImpl.startTransaction().withType("request"); try (Scope scope = transaction.activateInScope()) { transaction.setUser("1", "jon.doe@example.com", "jondoe"); Span span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } transaction.end(); } // we do report non-sampled transactions (without the context) assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(0); assertThat(reporter.getFirstTransaction().getContext().getUser().getEmail()).isNull(); assertThat(reporter.getFirstTransaction().getType()).isEqualTo("request"); }