Search in sources :

Example 11 with GaugeMetric

use of com.google.firebase.perf.v1.GaugeMetric 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)

Example 12 with GaugeMetric

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

the class TransportManagerTest method validGaugeMetric_knownApplicationProcessState_getLogged.

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

Example 13 with GaugeMetric

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

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

the class TransportManagerTest method validGaugeMetric_withMemoryReadings_isLogged.

@Test
public void validGaugeMetric_withMemoryReadings_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    // Construct a list of Memory metric readings
    List<AndroidMemoryReading> expectedMemoryMetricReadings = new ArrayList<>();
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234));
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23456));
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").addAllAndroidMemoryReadings(expectedMemoryMetricReadings).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getAndroidMemoryReadingsList()).containsExactlyElementsIn(expectedMemoryMetricReadings);
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfMetric(com.google.firebase.perf.v1.PerfMetric) ArrayList(java.util.ArrayList) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 15 with GaugeMetric

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

the class TransportManagerTest method validGaugeMetric_transportNotInitialized_getLoggedAfterInitialization.

@Test
public void validGaugeMetric_transportNotInitialized_getLoggedAfterInitialization() {
    initializeTransport(false);
    GaugeMetric validGauge = createValidGaugeMetric();
    testTransportManager.log(validGauge, 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.getGaugeMetric()).isEqualTo(validGauge);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.BACKGROUND);
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
}
Also used : PerfMetric(com.google.firebase.perf.v1.PerfMetric) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Aggregations

GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)18 Test (org.junit.Test)17 PerfMetric (com.google.firebase.perf.v1.PerfMetric)10 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)6 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)6 PerfSession (com.google.firebase.perf.session.PerfSession)5 Clock (com.google.firebase.perf.util.Clock)5 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)3 ArrayList (java.util.ArrayList)2 Lazy (com.google.firebase.components.Lazy)1 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)1 TraceMetric (com.google.firebase.perf.v1.TraceMetric)1