Search in sources :

Example 11 with PerfSession

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

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

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

the class GaugeManagerTest method testStartCollectingGaugesStartsAJobToConsumeTheGeneratedMetrics.

@Test
public void testStartCollectingGaugesStartsAJobToConsumeTheGeneratedMetrics() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
    assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(getMinimumBackgroundCollectionFrequency() * APPROX_NUMBER_OF_DATA_POINTS_PER_GAUGE_METRIC);
    CpuMetricReading fakeCpuMetricReading1 = createFakeCpuMetricReading(200, 100);
    CpuMetricReading fakeCpuMetricReading2 = createFakeCpuMetricReading(300, 200);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading1);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading2);
    AndroidMemoryReading fakeMemoryMetricReading1 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    123456);
    AndroidMemoryReading fakeMemoryMetricReading2 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23454678);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading1);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading2);
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeCpuMetricReading1, fakeCpuMetricReading2);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeMemoryMetricReading1, fakeMemoryMetricReading2);
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) PerfSession(com.google.firebase.perf.session.PerfSession) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Clock (com.google.firebase.perf.util.Clock)7 PerfSession (com.google.firebase.perf.session.PerfSession)6 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)6 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)5 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)5 PerfSession (com.google.firebase.perf.v1.PerfSession)5 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)2 PerfMetric (com.google.firebase.perf.v1.PerfMetric)2 ArrayList (java.util.ArrayList)2 Timer (com.google.firebase.perf.util.Timer)1 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1 TraceMetric (com.google.firebase.perf.v1.TraceMetric)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1