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");
}
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");
}
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();
}
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));
}
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();
}
Aggregations