Search in sources :

Example 46 with PerfMetric

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

the class TransportManagerTest method validNetworkMetric_unknownApplicationProcessState_getLogged.

@Test
public void validNetworkMetric_unknownApplicationProcessState_getLogged() {
    NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
    testTransportManager.log(validNetworkRequest);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) Test(org.junit.Test)

Example 47 with PerfMetric

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

the class TransportManagerTest method validGaugeMetric_unknownApplicationProcessState_getLogged.

@Test
public void validGaugeMetric_unknownApplicationProcessState_getLogged() {
    GaugeMetric validGauge = createValidGaugeMetric();
    testTransportManager.log(validGauge);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric()).isEqualTo(validGauge);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 48 with PerfMetric

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

the class TransportManagerTest method logTraceMetric_sessionEnabled_doesNotStripOffSessionId.

// endregion
// region Session's Behaviour
@Test
public void logTraceMetric_sessionEnabled_doesNotStripOffSessionId() {
    TraceMetric.Builder validTrace = createValidTraceMetric().toBuilder();
    List<PerfSession> perfSessions = new ArrayList<>();
    perfSessions.add(new com.google.firebase.perf.session.PerfSession("fakeSessionId", new Clock()).build());
    validTrace.addAllPerfSessions(perfSessions);
    testTransportManager.log(validTrace.build());
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getTraceMetric().getPerfSessionsCount()).isEqualTo(1);
    assertThat(loggedPerfMetric.getTraceMetric().getPerfSessions(0).getSessionId()).isEqualTo("fakeSessionId");
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfSession(com.google.firebase.perf.v1.PerfSession) PerfMetric(com.google.firebase.perf.v1.PerfMetric) ArrayList(java.util.ArrayList) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 49 with PerfMetric

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

the class TransportManagerTest method logNetworkMetric_sessionEnabled_doesNotStripOffSessionId.

@Test
public void logNetworkMetric_sessionEnabled_doesNotStripOffSessionId() {
    NetworkRequestMetric.Builder validNetworkRequest = createValidNetworkRequestMetric().toBuilder();
    List<PerfSession> perfSessions = new ArrayList<>();
    perfSessions.add(new com.google.firebase.perf.session.PerfSession("fakeSessionId", new Clock()).build());
    validNetworkRequest.clearPerfSessions().addAllPerfSessions(perfSessions);
    testTransportManager.log(validNetworkRequest.build());
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getNetworkRequestMetric().getPerfSessionsCount()).isEqualTo(1);
    assertThat(loggedPerfMetric.getNetworkRequestMetric().getPerfSessions(0).getSessionId()).isEqualTo("fakeSessionId");
}
Also used : PerfSession(com.google.firebase.perf.v1.PerfSession) PerfMetric(com.google.firebase.perf.v1.PerfMetric) NetworkRequestMetric(com.google.firebase.perf.v1.NetworkRequestMetric) ArrayList(java.util.ArrayList) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 50 with PerfMetric

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

the class TransportManagerTest method logTraces_fewTracesAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap.

@Test
public void logTraces_fewTracesAfterOtherCappedEventsAndTransportNotInitialized_cappedEventsDoesNotCauseOtherEventsToCap() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Network Requests (any one of PerfMetric event other than TraceMetric) such
    // that they are capped
    int maxNetworkRequestsCacheSize = // only 50 NetworkRequestMetric events are allowed to cache
    50;
    int totalNetworkRequestEvents = maxNetworkRequestsCacheSize + 10;
    for (int i = 0; i < totalNetworkRequestEvents; i++) {
        testTransportManager.log(createValidNetworkRequestMetric().toBuilder().setClientStartTimeUs(i + 1).build());
        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. Log few Traces such that they are under the max cap
    // less than max cache for TraceMetric events
    int totalTraceEvents = 20;
    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();
    }
    // 5. All Traces are queued even after Network Requests are capped
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxNetworkRequestsCacheSize + totalTraceEvents);
    // 6. Initialize Transport
    initializeTransport(true);
    // 7. Consume all queued Network Requests
    for (int i = 0; i < maxNetworkRequestsCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
    }
    // 8. Consume all queued Traces and validate them
    for (int i = 0; i < totalTraceEvents; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidTrace = getLastLoggedEvent(times(1));
        assertThat(loggedValidTrace.getTraceMetric()).isEqualTo(validTraces[i]);
        validateApplicationInfo(loggedValidTrace, 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 : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) 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