use of com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters in project ApplicationInsights-Java by microsoft.
the class QuickPulseDataCollectorTests method dependencyTelemetryIsCounted_DurationIsSum.
@Test
void dependencyTelemetryIsCounted_DurationIsSum() {
TelemetryClient telemetryClient = TelemetryClient.createForTest();
telemetryClient.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.setQuickPulseStatus(QuickPulseStatus.QP_IS_ON);
QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
// add a success and peek.
final long duration = 112233L;
TelemetryItem telemetry = createRemoteDependencyTelemetry("dep-test", "dep-test-cmd", duration, true);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
FinalCounters counters = QuickPulseDataCollector.INSTANCE.peek();
assertThat(counters.rdds).isEqualTo(1);
assertThat(counters.unsuccessfulRdds).isEqualTo(0);
assertThat(counters.rddsDuration).isEqualTo(duration);
// add another success and peek.
final long duration2 = 334455L;
telemetry = createRemoteDependencyTelemetry("dep-test-2", "dep-test-cmd-2", duration2, true);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
counters = QuickPulseDataCollector.INSTANCE.peek();
assertThat(counters.rdds).isEqualTo(2);
assertThat(counters.unsuccessfulRdds).isEqualTo(0);
double total = duration + duration2;
assertThat(counters.rddsDuration).isEqualTo(total);
// add a failure and get/reset.
final long duration3 = 123456L;
telemetry = createRemoteDependencyTelemetry("dep-test-3", "dep-test-cmd-3", duration3, false);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
counters = QuickPulseDataCollector.INSTANCE.getAndRestart();
assertThat(counters.rdds).isEqualTo(3);
assertThat(counters.unsuccessfulRdds).isEqualTo(1);
total += duration3;
assertThat(counters.rddsDuration).isEqualTo(total);
assertCountersReset(QuickPulseDataCollector.INSTANCE.peek());
}
use of com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters in project ApplicationInsights-Java by microsoft.
the class QuickPulseDataCollectorTests method requestTelemetryIsCounted_DurationIsSum.
@Test
void requestTelemetryIsCounted_DurationIsSum() {
TelemetryClient telemetryClient = TelemetryClient.createForTest();
telemetryClient.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.setQuickPulseStatus(QuickPulseStatus.QP_IS_ON);
QuickPulseDataCollector.INSTANCE.enable(telemetryClient);
// add a success and peek
final long duration = 112233L;
TelemetryItem telemetry = createRequestTelemetry("request-test", new Date(), duration, "200", true);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
FinalCounters counters = QuickPulseDataCollector.INSTANCE.peek();
assertThat(counters.requests).isEqualTo(1);
assertThat(counters.unsuccessfulRequests).isEqualTo(0);
assertThat(counters.requestsDuration).isEqualTo(duration);
// add another success and peek
final long duration2 = 65421L;
telemetry = createRequestTelemetry("request-test-2", new Date(), duration2, "200", true);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
counters = QuickPulseDataCollector.INSTANCE.peek();
double total = duration + duration2;
assertThat(counters.requests).isEqualTo(2);
assertThat(counters.unsuccessfulRequests).isEqualTo(0);
assertThat(counters.requestsDuration).isEqualTo(total);
// add a failure and get/reset
final long duration3 = 9988L;
telemetry = createRequestTelemetry("request-test-3", new Date(), duration3, "400", false);
telemetry.setInstrumentationKey(FAKE_INSTRUMENTATION_KEY);
QuickPulseDataCollector.INSTANCE.add(telemetry);
counters = QuickPulseDataCollector.INSTANCE.getAndRestart();
total += duration3;
assertThat(counters.requests).isEqualTo(3);
assertThat(counters.unsuccessfulRequests).isEqualTo(1);
assertThat(counters.requestsDuration).isEqualTo(total);
assertCountersReset(QuickPulseDataCollector.INSTANCE.peek());
}
use of com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters 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);
}
use of com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters 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());
}
Aggregations