Search in sources :

Example 16 with PerfMetric

use of com.google.firebase.perf.v1.PerfMetric 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 17 with PerfMetric

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

the class TransportManagerTest method validNetworkMetric_transportNotInitialized_getLoggedAfterInitialization.

@Test
public void validNetworkMetric_transportNotInitialized_getLoggedAfterInitialization() {
    initializeTransport(false);
    NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
    testTransportManager.log(validNetworkRequest, ApplicationProcessState.BACKGROUND);
    fakeExecutorService.runAll();
    assertThat(getLastLoggedEvent(never())).isNull();
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(1);
    initializeTransport(true);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.BACKGROUND);
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 18 with PerfMetric

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

the class TransportManagerTest method validGaugeMetric_withCpuReadings_isLogged.

// endregion
// region Gauge Specific
@Test
public void validGaugeMetric_withCpuReadings_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    // Construct a list of Cpu metric readings
    List<CpuMetricReading> expectedCpuMetricReadings = new ArrayList<>();
    expectedCpuMetricReadings.add(createValidCpuMetricReading(/* userTimeUs= */
    10, /* systemTimeUs= */
    20));
    expectedCpuMetricReadings.add(createValidCpuMetricReading(/* userTimeUs= */
    20, /* systemTimeUs= */
    30));
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").addAllCpuMetricReadings(expectedCpuMetricReadings).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getCpuMetricReadingsList()).containsExactlyElementsIn(expectedCpuMetricReadings);
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) PerfMetric(com.google.firebase.perf.v1.PerfMetric) ArrayList(java.util.ArrayList) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 19 with PerfMetric

use of com.google.firebase.perf.v1.PerfMetric 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 20 with PerfMetric

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

the class TransportManagerTest method logMultipleNetworkRequests_transportNotInitialized_networkRequestsAfterMaxCapAreNotQueued.

@Test
public void logMultipleNetworkRequests_transportNotInitialized_networkRequestsAfterMaxCapAreNotQueued() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Network Requests such that they are capped
    int maxNetworkRequestsCacheSize = // only 50 NetworkRequestMetric events are allowed to cache
    50;
    int totalNetworkRequestEvents = maxNetworkRequestsCacheSize + 10;
    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();
    }
    // 3. Even though we recorded "totalNetworkRequestEvents", events up-to
    // "maxNetworkRequestsCacheSize" are only queued
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxNetworkRequestsCacheSize);
    // 4. Initialize Transport
    initializeTransport(true);
    // 5. Consume all queued Network Requests and validate them
    for (int i = 0; i < maxNetworkRequestsCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidNetworkRequest = getLastLoggedEvent(times(1));
        assertThat(loggedValidNetworkRequest.getNetworkRequestMetric()).isEqualTo(validNetworkRequests[i]);
        validateApplicationInfo(loggedValidNetworkRequest, ApplicationProcessState.FOREGROUND);
    }
    // 6. Queue is all consumed after iterating "maxNetworkRequestsCacheSize" events
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
    // 7. 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)

Aggregations

PerfMetric (com.google.firebase.perf.v1.PerfMetric)51 Test (org.junit.Test)50 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)10 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)9 TraceMetric (com.google.firebase.perf.v1.TraceMetric)9 RateLimiterImpl (com.google.firebase.perf.transport.RateLimiter.RateLimiterImpl)6 ArrayList (java.util.ArrayList)4 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 Clock (com.google.firebase.perf.util.Clock)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2 WorkerThread (androidx.annotation.WorkerThread)1 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)1 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)1 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)1