private void addsErrorTagOnException(String path) throws Exception { Span span = reportsSpanOnException(path); assertThat(span.tags()) .containsKey("error"); } }
@Test public void addsErrorTagOnTransportException() throws Exception { Span span = checkReportsSpanOnTransportException(); assertThat(span.tags()) .containsKey("error"); }
@SuppressWarnings("unchecked") public static Map<String, Object> getMap(Map response, String key) { assertThat(response).containsKey(key).isInstanceOf(Map.class); return (Map<String, Object>) response.get(key); }
@Test public void testContainsKey() { assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsKey("1"); assertThat(new UnionMap<>(of("1", "a"), of("2", "b"))).containsKey("2"); }
public PomAssert hasBom(String groupId, String artifactId, String version) { String id = generateBomId(groupId, artifactId); assertThat(this.boms).containsKey(id); BillOfMaterials bom = this.boms.get(id); assertThat(bom.getVersion()).isEqualTo(version); return this; }
@Test public void testB3HeaderContextPropagation() throws Exception { HttpRequest httpRequest = new MockClientHttpRequest(HttpMethod.GET, new URI("http://example.com/foo?bar=baz")); new SpringRestTemplateContextPropagatingInterceptor(tracingPlugin) .intercept(httpRequest, null, mock(ClientHttpRequestExecution.class)); assertThat(httpRequest.getHeaders()).containsKey(B3HeaderFormat.SPAN_ID_NAME); assertThat(httpRequest.getHeaders()).containsKey(B3HeaderFormat.TRACE_ID_NAME); assertThat(mockTracer.finishedSpans()).hasSize(1); assertThat(mockTracer.finishedSpans().get(0).operationName()).isEqualTo("GET http://example.com/foo"); }
@Test public void testMonitorRequestsThrowingException() throws Exception { assertThatThrownBy(() -> testClass.monitorThrowException()).isInstanceOf(NullPointerException.class); assertThat(NullPointerException.class.getName()).isEqualTo(tags.get("exception.class")); final Map<MetricName,Timer> timers = metricRegistry.getTimers(); assertThat(timers).containsKey(name("response_time").operationName("TracedTransformerTest$TestClass#monitorThrowException").operationType("method_invocation").build()); }
@Test public void testMonitorRequests() throws Exception { testClass.monitorMe(1); final SpanContextInformation spanContext = spanCapturingReporter.get(); // either parameters.arg0 or parameters.s assertThat("1").isEqualTo(getTagsStartingWith(tags, SpanUtils.PARAMETERS_PREFIX).iterator().next()); assertThat("TracedTransformerTest$TestClass#monitorMe").isEqualTo(spanContext.getOperationName()); assertThat(1).isEqualTo(spanContext.getCallTree().getChildren().size()); final String signature = spanContext.getCallTree().getChildren().get(0).getSignature(); assertThat(signature).contains("org.stagemonitor.tracing.TracedTransformerTest$TestClass.monitorMe"); final Map<MetricName,Timer> timers = metricRegistry.getTimers(); assertThat(timers).containsKey(name("response_time").operationName("TracedTransformerTest$TestClass#monitorMe").operationType("method_invocation").build()); }
@Test public void monitorGetConnectionUsernamePassword() throws Exception { try { dataSource.getConnection("sa", "").close(); } catch (SQLFeatureNotSupportedException | UnsupportedOperationException e) { // ignore return; } requestMonitor .monitor(new MonitoredMethodRequest(configuration, "monitorGetConnectionUsernamePassword()", () -> { dataSource.getConnection("sa", "").close(); })); final Map<MetricName, Timer> timers = metric2Registry.getTimers(); assertThat(timers).containsKey(name("get_jdbc_connection").tag("url", "SA@jdbc:hsqldb:mem:test").build()); }
@Test public void a_root_object_can_be_evaluated() { Map<String, Object> result = compile("$").evaluate(DOC, DOC, CONF).getValue(); assertThat(result) .containsKey("store") .hasSize(1); }
@Test public void testClassLevelAnnotationClass() throws Exception { testClassLevelAnnotationClass.monitorMe("1"); testClassLevelAnnotationClass.dontMonitorMe(); final SpanContextInformation spanContext = spanCapturingReporter.get(); // either parameters.arg0 or parameters.s assertThat("1").isEqualTo(getTagsStartingWith(tags, SpanUtils.PARAMETERS_PREFIX).iterator().next()); assertThat("TracedTransformerTest$TestClassLevelAnnotationClass#monitorMe").isEqualTo(spanContext.getOperationName()); assertThat(1).isEqualTo(spanContext.getCallTree().getChildren().size()); final String signature = spanContext.getCallTree().getChildren().get(0).getSignature(); assertThat(signature).contains("org.stagemonitor.tracing.TracedTransformerTest$TestClassLevelAnnotationClass.monitorMe"); final Map<MetricName, Timer> timers = metricRegistry.getTimers(); assertThat(timers).containsKey(name("response_time").operationName("TracedTransformerTest$TestClassLevelAnnotationClass#monitorMe").operationType("method_invocation").build()); }
@Test public void monitorGetConnection() throws Exception { requestMonitor .monitor(new MonitoredMethodRequest(configuration, "monitorGetConnectionUsernamePassword()", () -> { dataSource.getConnection().close(); })); final Map<MetricName, Timer> timers = metric2Registry.getTimers(); assertThat(timers).containsKey(name("get_jdbc_connection").tag("url", "SA@jdbc:hsqldb:mem:test").build()); }
@Test public void testMonitorAsyncMethods() throws Exception { testClass.asyncMethod(); final SpanContextInformation spanContext = spanCapturingReporter.get(); assertThat("TracedTransformerTest$TestClass#asyncMethod").isEqualTo(spanContext.getOperationName()); assertThat(1).isEqualTo(spanContext.getCallTree().getChildren().size()); final String signature = spanContext.getCallTree().getChildren().get(0).getSignature(); assertThat(signature).contains("org.stagemonitor.tracing.TracedTransformerTest$TestClass.asyncMethod"); final Map<MetricName,Timer> timers = metricRegistry.getTimers(); assertThat(timers).containsKey(name("response_time").operationName("TracedTransformerTest$TestClass#asyncMethod").operationType("method_invocation").build()); }
@Test public void testMonitorRequestsAnnonymousInnerClass() throws Exception { testClass.monitorAnnonymousInnerClass(); final SpanContextInformation spanContext = spanCapturingReporter.get(); assertThat("TracedTransformerTest$TestClass$1#run").isEqualTo(spanContext.getOperationName()); assertThat(1).isEqualTo(spanContext.getCallTree().getChildren().size()); final String signature = spanContext.getCallTree().getChildren().get(0).getSignature(); assertThat(signature).contains("org.stagemonitor.tracing.TracedTransformerTest$TestClass$1.run"); final Map<MetricName,Timer> timers = metricRegistry.getTimers(); assertThat(timers).containsKey(name("response_time").operationName("TracedTransformerTest$TestClass$1#run").operationType("method_invocation").build()); }
@Test public void testDoubleForwarding() throws Exception { testObject.monitored1(); assertThat(mockTracer.finishedSpans()).hasSize(3); Assert.assertEquals("monitored1()", mockTracer.finishedSpans().get(2).operationName()); assertEquals(tags.toString(), "1", tags.get(SpanUtils.PARAMETERS_PREFIX + "arg0")); assertEquals(tags.toString(), "test", tags.get(SpanUtils.PARAMETERS_PREFIX + "arg1")); assertThat(registry.getTimers()).containsKey(name("response_time").operationName("monitored1()").operationType("method_invocation").build()); assertThat(registry.getTimers()).containsKey(name("response_time").operationName("monitored2()").operationType("method_invocation").build()); assertThat(registry.getTimers()).containsKey(name("response_time").operationName("monitored3()").operationType("method_invocation").build()); assertThat(registry.getTimers()).doesNotContainKey(name("response_time").operationName("notMonitored()").operationType("method_invocation").build()); }
@Test public void testRequestMonitorNonMvcRequestDoMonitor() throws Exception { when(servletPlugin.isMonitorOnlySpringMvcRequests()).thenReturn(false); final MonitoredHttpRequest monitoredRequest = createMonitoredHttpRequest(nonMvcRequest); SpanContextInformation spanContext = requestMonitor.monitor(monitoredRequest); assertEquals("GET *.js", spanContext.getOperationName()); assertEquals("GET *.js", spanContext.getOperationName()); assertThat(registry.getTimers()).doesNotContainKey(getResponseTimeMetricName(spanContext.getOperationName(), "http")); assertThat(registry.getTimers()).containsKey(getResponseTimeMetricName("All", "http")); verify(monitoredRequest, times(1)).getRequestName(); assertThat(tags.get(Tags.SAMPLING_PRIORITY.getKey())).isNotEqualTo(0); }
@Test public void testTriggersResponseTimeIncident() throws Exception { final String checkId = "void org.stagemonitor.alerting.annotation.SlaCheckCreatingClassPathScannerTest$SlaTestClass.monitorSla().responseTime"; assertThat(checks).containsKey(checkId); try { new SlaTestClass().monitorSla(); } catch (Exception e) { // ignore } assertThat(Stagemonitor.getMetric2Registry().getTimers()).containsKey(name("response_time").operationName("Monitor Sla").operationType("method_invocation").build()); alertingPlugin.getThresholdMonitoringReporter().report(); final Incident incident = alertingPlugin.getIncidentRepository() .getIncidentByCheckId(checkId); assertThat(incident).isNotNull(); }
@Test public void testTriggersErrorRateIncident() throws Exception { final String checkId = "void org.stagemonitor.alerting.annotation.SlaCheckCreatingClassPathScannerTest$SlaTestClass.monitorSla().errors"; assertThat(checks).containsKey(checkId); try { new SlaTestClass().monitorSla(); } catch (Exception e) { // ignore } assertThat(Stagemonitor.getMetric2Registry().getMeters()).containsKey(name("error_rate").operationName("Monitor Sla").operationType("method_invocation").build()); alertingPlugin.getThresholdMonitoringReporter().report(); final Incident incident = alertingPlugin.getIncidentRepository() .getIncidentByCheckId(checkId); assertThat(incident).isNotNull(); } }
@Test public void testRequestMonitorMvcRequest() throws Exception { when(servletPlugin.isMonitorOnlySpringMvcRequests()).thenReturn(false); MonitoredHttpRequest monitoredRequest = createMonitoredHttpRequest(mvcRequest); final SpanContextInformation spanContext = requestMonitor.monitor(monitoredRequest); assertEquals("Test Get Request Name", spanContext.getOperationName()); assertEquals(1, registry.timer(getResponseTimeMetricName(spanContext.getOperationName(), "http")).getCount()); assertEquals("Test Get Request Name", spanContext.getOperationName()); assertEquals("/test/requestName", tags.get(Tags.HTTP_URL.getKey())); assertEquals("GET", tags.get("method")); assertThat(registry.getTimers()).containsKey(name("response_time").operationName("Test Get Request Name").operationType("http").build()); }
@Test public void testNormalForwarding() throws Exception { testObject.monitored3(); assertThat(registry.getTimers()).doesNotContainKey(name("response_time").operationName("monitored1()").operationType("method_invocation").build()); assertThat(registry.getTimers()).doesNotContainKey(name("response_time").operationName("monitored2()").operationType("method_invocation").build()); assertThat(registry.getTimers()).containsKey(name("response_time").operationName("monitored3()").operationType("method_invocation").build()); assertThat(registry.getTimers()).doesNotContainKey(name("response_time").operationName("notMonitored()").operationType("method_invocation").build()); }