Search in sources :

Example 6 with TraceMetric

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

the class TransportManagerTest method logPerfMetric_dispatchedToFlgOnly.

// endregion
// region Flg Destination
@Test
public void logPerfMetric_dispatchedToFlgOnly() {
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace, ApplicationProcessState.FOREGROUND);
    fakeExecutorService.runAll();
    verify(mockFlgTransport, times(1)).log(any());
    assertThat(getLastLoggedEvent(times(1)).getTraceMetric()).isEqualTo(validTrace);
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 7 with TraceMetric

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

the class TransportManagerTest method logMultipleTraces_transportNotInitialized_tracesAfterMaxCapAreNotQueued.

@Test
public void logMultipleTraces_transportNotInitialized_tracesAfterMaxCapAreNotQueued() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Traces such that they are capped
    // only 50 TraceMetric events are allowed to cache
    int maxTracesCacheSize = 50;
    int totalTraceEvents = maxTracesCacheSize + 10;
    TraceMetric[] validTraces = new TraceMetric[totalTraceEvents];
    for (int i = 0; i < totalTraceEvents; i++) {
        validTraces[i] = createValidTraceMetric().toBuilder().setName("Trace - " + (i + 1)).build();
        testTransportManager.log(validTraces[i], ApplicationProcessState.FOREGROUND);
        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. Initialize Transport
    initializeTransport(true);
    // 5. Consume all queued Traces and validate them
    for (int i = 0; i < maxTracesCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidTrace = getLastLoggedEvent(times(1));
        assertThat(loggedValidTrace.getTraceMetric()).isEqualTo(validTraces[i]);
        validateApplicationInfo(loggedValidTrace, ApplicationProcessState.FOREGROUND);
    }
    // 6. Queue is all consumed after iterating "maxTracesCacheSize" events
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
    // 7. No pending events
    clearLastLoggedEvents();
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 8 with TraceMetric

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

the class TransportManagerTest method logNetworkRequests_fewNetworkRequestsAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap.

@Test
public void logNetworkRequests_fewNetworkRequestsAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Traces (any one of PerfMetric event other than NetworkRequestMetric) 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 Network Requests such that they are under the max cap
    // less than max cache for NetworkRequestMetric events
    int totalNetworkRequestEvents = 20;
    NetworkRequestMetric[] validNetworkRequests = new NetworkRequestMetric[totalNetworkRequestEvents];
    for (int i = 0; i < totalNetworkRequestEvents; i++) {
        validNetworkRequests[i] = createValidNetworkRequestMetric().toBuilder().setClientStartTimeUs(i + 1).build();
        testTransportManager.log(validNetworkRequests[i], ApplicationProcessState.FOREGROUND);
        fakeExecutorService.runAll();
        assertThat(getLastLoggedEvent(never())).isNull();
    }
    // 5. All NetworkRequests are queued even after Traces are capped
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxTracesCacheSize + totalNetworkRequestEvents);
    // 6. Initialize Transport
    initializeTransport(true);
    // 7. Consume all queued Traces
    for (int i = 0; i < maxTracesCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
    }
    // 8. Consume all queued Network Requests and validate them
    for (int i = 0; i < totalNetworkRequestEvents; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidNetworkRequest = getLastLoggedEvent(times(1));
        assertThat(loggedValidNetworkRequest.getNetworkRequestMetric()).isEqualTo(validNetworkRequests[i]);
        validateApplicationInfo(loggedValidNetworkRequest, 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) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 9 with TraceMetric

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

the class TransportManagerTest method validTraceMetric_knownApplicationProcessState_getLogged.

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

Example 10 with TraceMetric

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

the class TransportManagerTest method logMultipleEvents_transportNotInitialized_validEventsGetLoggedInOrderAfterInitialization.

@Test
public void logMultipleEvents_transportNotInitialized_validEventsGetLoggedInOrderAfterInitialization() {
    initializeTransport(false);
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace, ApplicationProcessState.BACKGROUND);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    TraceMetric invalidTrace = createInvalidTraceMetric();
    testTransportManager.log(invalidTrace, ApplicationProcessState.BACKGROUND);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
    testTransportManager.log(validNetworkRequest, ApplicationProcessState.FOREGROUND);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    NetworkRequestMetric invalidNetworkRequest = createInvalidNetworkRequestMetric();
    testTransportManager.log(invalidNetworkRequest, ApplicationProcessState.FOREGROUND);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    GaugeMetric validGauge = createValidGaugeMetric();
    testTransportManager.log(validGauge);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    GaugeMetric invalidGauge = createInValidGaugeMetric();
    testTransportManager.log(invalidGauge);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(6);
    initializeTransport(true);
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedValidTrace = getLastLoggedEvent(times(1));
    assertThat(loggedValidTrace.getTraceMetric()).isEqualTo(validTrace);
    validateApplicationInfo(loggedValidTrace, ApplicationProcessState.BACKGROUND);
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedInvalidTrace = getLastLoggedEvent(never());
    assertThat(loggedInvalidTrace).isNull();
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedValidNetworkRequest = getLastLoggedEvent(times(1));
    assertThat(loggedValidNetworkRequest.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
    validateApplicationInfo(loggedValidNetworkRequest, ApplicationProcessState.FOREGROUND);
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedInValidNetworkRequest = getLastLoggedEvent(never());
    assertThat(loggedInValidNetworkRequest).isNull();
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedValidGauge = getLastLoggedEvent(times(1));
    assertThat(loggedValidGauge.getGaugeMetric()).isEqualTo(validGauge);
    validateApplicationInfo(loggedValidGauge, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
    clearLastLoggedEvents();
    fakeExecutorService.runNext();
    PerfMetric loggedInValidGauge = getLastLoggedEvent(never());
    assertThat(loggedInValidGauge).isNull();
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) 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