Search in sources :

Example 11 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class TransportManagerTest method validTraceMetric_nullInstallationsDuringInitButValidValueLater_getLogged.

@Test
public void validTraceMetric_nullInstallationsDuringInitButValidValueLater_getLogged() {
    // Null Installations during initialization
    mockInstallationsGetId(null);
    initializeTransport(true);
    fakeExecutorService.runAll();
    // Valid FID later
    mockInstallationsGetId(FAKE_FIREBASE_INSTALLATIONS_ID);
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getTraceMetric()).isEqualTo(validTrace);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 12 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class TransportManagerTest method logGauges_fewGaugesAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap.

@Test
public void logGauges_fewGaugesAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Traces (any one of PerfMetric event other than GaugeMetric) such that they
    // are capped
    // only 50 TraceMetric events are allowed to cache
    int maxTracesCacheSize = 50;
    int totalTraceEvents = maxTracesCacheSize + 10;
    for (int i = 0; i < totalTraceEvents; i++) {
        testTransportManager.log(createValidTraceMetric().toBuilder().setName("Trace - " + (i + 1)).build());
        fakeExecutorService.runAll();
        assertThat(getLastLoggedEvent(never())).isNull();
    }
    // 3. Even though we recorded "totalTraceEvents", events up-to "maxTracesCacheSize" are only
    // queued
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxTracesCacheSize);
    // 4. Log few Gauges such that they are under the max cap
    // less than max cache for GaugeMetric events
    int totalGaugeEvents = 20;
    GaugeMetric[] validGauges = new GaugeMetric[totalGaugeEvents];
    for (int i = 0; i < totalGaugeEvents; i++) {
        validGauges[i] = createValidGaugeMetric().toBuilder().setSessionId("Session - " + (i + 1)).build();
        testTransportManager.log(validGauges[i], ApplicationProcessState.FOREGROUND);
        fakeExecutorService.runAll();
        assertThat(getLastLoggedEvent(never())).isNull();
    }
    // 5. All Gauges are queued even after Traces are capped
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxTracesCacheSize + totalGaugeEvents);
    // 6. Initialize Transport
    initializeTransport(true);
    // 7. Consume all queued Traces
    for (int i = 0; i < maxTracesCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
    }
    // 8. Consume all queued Gauges and validate them
    for (int i = 0; i < totalGaugeEvents; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidGauge = getLastLoggedEvent(times(1));
        assertThat(loggedValidGauge.getGaugeMetric()).isEqualTo(validGauges[i]);
        validateApplicationInfo(loggedValidGauge, ApplicationProcessState.FOREGROUND);
    }
    // 9. Queue is all consumed
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
    // 10. No pending events
    clearLastLoggedEvents();
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 13 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class TransportManagerTest method validTraceMetric_unknownApplicationProcessState_getLogged.

@Test
public void validTraceMetric_unknownApplicationProcessState_getLogged() {
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getTraceMetric()).isEqualTo(validTrace);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 14 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FirebasePerfTraceValidatorTest method testInvalidCounterSubtrace.

@Test
public void testInvalidCounterSubtrace() {
    TraceMetric.Builder trace = createValidTraceMetric();
    TraceMetric subtrace = createValidTraceMetric().putCounters("", 10).build();
    trace.addSubtraces(subtrace);
    assertThat(new FirebasePerfTraceValidator(trace.build()).isValidPerfMetric()).isFalse();
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 15 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FirebasePerfTraceValidatorTest method testNullDuration.

@Test
public void testNullDuration() {
    TraceMetric trace = createValidTraceMetric().clearDurationUs().build();
    assertThat(new FirebasePerfTraceValidator(trace).isValidPerfMetric()).isFalse();
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 TraceMetric (com.google.firebase.perf.v1.TraceMetric)43 PerfMetric (com.google.firebase.perf.v1.PerfMetric)11 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)7 Trace (com.google.firebase.perf.metrics.Trace)2 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)2 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2 Fragment (androidx.fragment.app.Fragment)1 AppStateMonitor (com.google.firebase.perf.application.AppStateMonitor)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1