use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class CpuGaugeCollectorTest method testStopCollectingCancelsFutureTasks.
@Test
public void testStopCollectingCancelsFutureTasks() {
testGaugeCollector.startCollecting(500, new Timer());
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(0);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(500);
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
testGaugeCollector.stopCollecting();
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class CpuGaugeCollectorTest method testCollectCpuMetricDoesntStartCollectingWithInvalidCpuMetricCollectionRate.
@Test
public void testCollectCpuMetricDoesntStartCollectingWithInvalidCpuMetricCollectionRate() {
testGaugeCollector.startCollecting(-1, new Timer());
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
testGaugeCollector.startCollecting(0, new Timer());
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class CpuGaugeCollectorTest method testStartCollectingHasCorrectInterval.
@Test
public void testStartCollectingHasCorrectInterval() {
testGaugeCollector.startCollecting(/* cpuMetricCollectionRateMs= */
500, new Timer());
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(0);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(500);
testGaugeCollector.collectOnce(new Timer());
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(0);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(500);
testGaugeCollector.startCollecting(/* cpuMetricCollectionRateMs= */
200, new Timer());
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(0);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(200);
testGaugeCollector.collectOnce(new Timer());
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(0);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(200);
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class CpuGaugeCollectorTest method testCollectingCpuMetricHasCorrectValuesFromProcPidStatFile.
@Test
public void testCollectingCpuMetricHasCorrectValuesFromProcPidStatFile() throws IOException {
testGaugeCollector.startCollecting(500, new Timer());
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
deleteFakeProcFile();
createFakeFileToEmulateProcPidStat("200", "200", "400", "400");
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
CpuMetricReading recordedReadingOne = testGaugeCollector.cpuMetricReadings.poll();
CpuMetricReading recordedReadingTwo = testGaugeCollector.cpuMetricReadings.poll();
assertThat(recordedReadingOne.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, fakeClockTicksPerSecond));
assertThat(recordedReadingOne.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, fakeClockTicksPerSecond));
assertThat(recordedReadingTwo.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(800, fakeClockTicksPerSecond));
assertThat(recordedReadingTwo.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(400, fakeClockTicksPerSecond));
}
use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.
the class CpuGaugeCollectorTest method testCollectingCpuMetricDoesntAddAnythingToQueueWhenItEncountersProcFileWithInsufficientData.
@Test
public void testCollectingCpuMetricDoesntAddAnythingToQueueWhenItEncountersProcFileWithInsufficientData() throws IOException {
deleteFakeProcFile();
createFakeFileWithContents("INVALID_CONTENT");
testGaugeCollector.startCollecting(500, new Timer());
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
assertThat(testGaugeCollector.cpuMetricReadings).hasSize(0);
}
Aggregations