use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class GaugeManagerTest method stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequency.
@Test
public void stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequency() {
// PASS 1: Test with 0
doReturn(0L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
// Verify that Cpu metric collection is not started
verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
// Verify that Memory metric collection is started
verify(fakeMemoryGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
// PASS 2: Test with -ve value
doReturn(-25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
// Verify that Cpu metric collection is not started
verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// Verify that Memory metric collection is started
verify(fakeMemoryGaugeCollector, 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 startCollectingGauges_validGaugeCollectionFrequency_appInForeground.
@Test
public void startCollectingGauges_validGaugeCollectionFrequency_appInForeground() {
doReturn(25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
doReturn(15L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
PerfSession fakeSession = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.FOREGROUND);
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(15L * APPROX_NUMBER_OF_DATA_POINTS_PER_GAUGE_METRIC);
}
use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class GaugeManagerTest method testStartCollectingGaugesDoesNotStartCollectingMetricsWithUnknownApplicationProcessState.
@Test
public void testStartCollectingGaugesDoesNotStartCollectingMetricsWithUnknownApplicationProcessState() {
PerfSession fakeSession = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
}
use of com.google.firebase.perf.util.Clock 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);
}
Aggregations