Search in sources :

Example 21 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulsePingSenderTests method endpointIsFormattedCorrectlyWhenUsingConnectionString.

@Test
void endpointIsFormattedCorrectlyWhenUsingConnectionString() throws URISyntaxException {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setConnectionString("InstrumentationKey=testing-123");
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(null, telemetryClient, null, null, null);
    String quickPulseEndpoint = quickPulsePingSender.getQuickPulseEndpoint();
    String endpointUrl = quickPulsePingSender.getQuickPulsePingUri(quickPulseEndpoint);
    URI uri = new URI(endpointUrl);
    assertThat(uri).isNotNull();
    assertThat(endpointUrl).endsWith("/ping?ikey=testing-123");
    assertThat(endpointUrl).isEqualTo("https://rt.services.visualstudio.com/QuickPulseService.svc/ping?ikey=testing-123");
}
Also used : TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 22 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulsePingSenderTests method endpointIsFormattedCorrectlyWhenUsingInstrumentationKey.

@Test
void endpointIsFormattedCorrectlyWhenUsingInstrumentationKey() throws URISyntaxException {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("A-test-instrumentation-key");
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(null, telemetryClient, null, null, null);
    String quickPulseEndpoint = quickPulsePingSender.getQuickPulseEndpoint();
    String endpointUrl = quickPulsePingSender.getQuickPulsePingUri(quickPulseEndpoint);
    URI uri = new URI(endpointUrl);
    assertThat(uri).isNotNull();
    assertThat(endpointUrl).endsWith(// from resources/ApplicationInsights.xml
    "/ping?ikey=A-test-instrumentation-key");
    assertThat(endpointUrl).isEqualTo("https://rt.services.visualstudio.com/QuickPulseService.svc/ping?ikey=A-test-instrumentation-key");
}
Also used : TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 23 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulseDataCollectorTests method emptyCountsAndDurationsAfterEnable.

@Test
void emptyCountsAndDurationsAfterEnable() {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
    QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
    FinalCounters counters = QuickPulseDataCollector.INSTANCE.peek();
    assertCountersReset(counters);
}
Also used : FinalCounters(com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 24 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulseDataCollectorTests method exceptionTelemetryIsCounted.

@Test
void exceptionTelemetryIsCounted() {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
    QuickPulseDataCollector.INSTANCE.setQuickPulseStatus(QuickPulseStatus.QP_IS_ON);
    QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
    TelemetryItem telemetry = createExceptionTelemetry(new Exception());
    telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
    QuickPulseDataCollector.INSTANCE.add(telemetry);
    FinalCounters counters = QuickPulseDataCollector.INSTANCE.peek();
    assertThat(counters.exceptions).isEqualTo(1);
    telemetry = createExceptionTelemetry(new Exception());
    telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
    QuickPulseDataCollector.INSTANCE.add(telemetry);
    counters = QuickPulseDataCollector.INSTANCE.getAndRestart();
    assertThat(counters.exceptions).isEqualTo(2);
    assertCountersReset(QuickPulseDataCollector.INSTANCE.peek());
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) FinalCounters(com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 25 with TelemetryClient

use of com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient in project ApplicationInsights-Java by microsoft.

the class QuickPulseDataCollectorTests method nullCountersAfterDisable.

@Test
void nullCountersAfterDisable() {
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
    QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
    QuickPulseDataCollector.INSTANCE.disable();
    assertThat(QuickPulseDataCollector.INSTANCE.peek()).isNull();
}
Also used : TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Aggregations

TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)28 Test (org.junit.jupiter.api.Test)21 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)7 Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)6 URI (java.net.URI)5 FinalCounters (com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters)4 RpConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration)3 Date (java.util.Date)3 HttpHeaders (com.azure.core.http.HttpHeaders)2 HttpPipeline (com.azure.core.http.HttpPipeline)2 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)2 MockHttpResponse (com.microsoft.applicationinsights.agent.internal.MockHttpResponse)2 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)2 AiLegacyHeaderSpanProcessor (com.microsoft.applicationinsights.agent.internal.legacyheaders.AiLegacyHeaderSpanProcessor)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Mono (reactor.core.publisher.Mono)2 HttpRequest (com.azure.core.http.HttpRequest)1