Search in sources :

Example 16 with Clock

use of com.google.firebase.perf.util.Clock 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 17 with Clock

use of com.google.firebase.perf.util.Clock 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 18 with Clock

use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testStopCollectingGaugesStopsCollectingAllGaugeMetrics.

@Test
public void testStopCollectingGaugesStopsCollectingAllGaugeMetrics() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    verify(fakeCpuGaugeCollector).startCollecting(eq(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_BG_MS), ArgumentMatchers.any());
    testGaugeManager.stopCollectingGauges();
    verify(fakeCpuGaugeCollector).stopCollecting();
    verify(fakeMemoryGaugeCollector).stopCollecting();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 19 with Clock

use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.

the class GaugeManagerTest method startCollectingGaugesOnForeground_invalidMemoryCaptureMs_onlyDisableMemoryCollection.

@Test
public void startCollectingGaugesOnForeground_invalidMemoryCaptureMs_onlyDisableMemoryCollection() {
    // PASS 1: Test with 0
    doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
    // Verify that Memory metric collection is not started
    verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // Verify that Cpu metric collection is started
    verify(fakeCpuGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // PASS 2: Test with -ve value
    doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
    // Verify that Memory metric collection is not started
    verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
    // Verify that Cpu metric collection is started
    verify(fakeCpuGaugeCollector, times(2)).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
}
Also used : Timer(com.google.firebase.perf.util.Timer) PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 20 with Clock

use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.

the class GaugeManagerTest method stopCollectingGauges_invalidGaugeCollectionFrequency_appInForeground.

@Test
public void stopCollectingGauges_invalidGaugeCollectionFrequency_appInForeground() {
    // PASS 1: Test with 0
    doReturn(0L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
    // PASS 2: Test with -ve value
    doReturn(-25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Aggregations

Clock (com.google.firebase.perf.util.Clock)24 Test (org.junit.Test)23 PerfSession (com.google.firebase.perf.session.PerfSession)19 Timer (com.google.firebase.perf.util.Timer)9 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)5 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)5 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)5 TraceMetric (com.google.firebase.perf.v1.TraceMetric)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)2 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)2 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)2 Trace (com.google.firebase.perf.metrics.Trace)2 TransportManager (com.google.firebase.perf.transport.TransportManager)2 Constants (com.google.firebase.perf.util.Constants)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2 PerfMetric (com.google.firebase.perf.v1.PerfMetric)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2