Search in sources :

Example 21 with PerfMetric

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

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

the class TransportManagerTest method logMultipleGauges_transportNotInitialized_gaugesAfterMaxCapAreNotQueued.

@Test
public void logMultipleGauges_transportNotInitialized_gaugesAfterMaxCapAreNotQueued() {
    // 1. Transport is not initialized in the beginning
    initializeTransport(false);
    // 2. Log multiple Gauges such that they are capped
    // only 50 GaugeMetric events are allowed to cache
    int maxGaugesCacheSize = 50;
    int totalGaugeEvents = maxGaugesCacheSize + 10;
    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();
    }
    // 3. Even though we recorded "totalGaugeEvents", events up-to "maxGaugesCacheSize" are only
    // queued
    assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxGaugesCacheSize);
    // 4. Initialize Transport
    initializeTransport(true);
    // 5. Consume all queued Gauges and validate them
    for (int i = 0; i < maxGaugesCacheSize; i++) {
        clearLastLoggedEvents();
        fakeExecutorService.runNext();
        PerfMetric loggedValidGauge = getLastLoggedEvent(times(1));
        assertThat(loggedValidGauge.getGaugeMetric()).isEqualTo(validGauges[i]);
        validateApplicationInfo(loggedValidGauge, ApplicationProcessState.FOREGROUND);
    }
    // 6. Queue is all consumed after iterating "maxGaugesCacheSize" 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) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 23 with PerfMetric

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

the class TransportManagerTest method validGaugeMetric_withMetadata_isLogged.

@Test
public void validGaugeMetric_withMetadata_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    GaugeMetadata gaugeMetadata = GaugeMetadata.newBuilder().setDeviceRamSizeKb(2000).setMaxAppJavaHeapMemoryKb(1000).setMaxEncouragedAppJavaHeapMemoryKb(800).build();
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").setGaugeMetadata(gaugeMetadata).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getDeviceRamSizeKb()).isEqualTo(2000);
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxAppJavaHeapMemoryKb()).isEqualTo(1000);
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxEncouragedAppJavaHeapMemoryKb()).isEqualTo(800);
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfMetric(com.google.firebase.perf.v1.PerfMetric) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 24 with PerfMetric

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

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

the class TransportManagerTest method logNetworkMetric_globalCustomAttributesAreAdded.

@Test
public void logNetworkMetric_globalCustomAttributesAreAdded() {
    FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
    FirebasePerformance.getInstance().putAttribute("test_key2", "test_value2");
    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);
    Map<String, String> globalCustomAttributes = loggedPerfMetric.getApplicationInfo().getCustomAttributesMap();
    assertThat(globalCustomAttributes).hasSize(2);
    assertThat(globalCustomAttributes).containsEntry("test_key1", "test_value1");
    assertThat(globalCustomAttributes).containsEntry("test_key2", "test_value2");
}
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