Search in sources :

Example 41 with PerfMetric

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

the class TransportManagerTest method validNetworkMetric_knownApplicationProcessState_getLogged.

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

Example 42 with PerfMetric

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

the class TransportManagerTest method logTraceMetric_globalCustomAttributesAreAdded.

// endregion
// region Global Custom Attributes Behaviour
@Test
public void logTraceMetric_globalCustomAttributesAreAdded() {
    FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
    FirebasePerformance.getInstance().putAttribute("test_key2", "test_value2");
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getTraceMetric()).isEqualTo(validTrace);
    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 : TraceMetric(com.google.firebase.perf.v1.TraceMetric) PerfMetric(com.google.firebase.perf.v1.PerfMetric) Test(org.junit.Test)

Example 43 with PerfMetric

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

the class TransportManagerTest method validNetworkMetric_nullInstallationsDuringInitButValidValueLater_getLogged.

@Test
public void validNetworkMetric_nullInstallationsDuringInitButValidValueLater_getLogged() {
    // Null Installations during initialization
    mockInstallationsGetId(null);
    initializeTransport(true);
    fakeExecutorService.runAll();
    // Valid FID later
    mockInstallationsGetId(FAKE_FIREBASE_INSTALLATIONS_ID);
    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 44 with PerfMetric

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

Example 45 with PerfMetric

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

the class TransportManagerTest method validTraceMetric_transportNotInitialized_getLoggedAfterInitialization.

// region Transport Initialization
@Test
public void validTraceMetric_transportNotInitialized_getLoggedAfterInitialization() {
    initializeTransport(false);
    TraceMetric validTrace = createValidTraceMetric();
    testTransportManager.log(validTrace, 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.getTraceMetric()).isEqualTo(validTrace);
    validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.BACKGROUND);
    assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
}
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