Search in sources :

Example 26 with Timer

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();
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 27 with Timer

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();
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 28 with Timer

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);
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 29 with Timer

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));
}
Also used : Timer(com.google.firebase.perf.util.Timer) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) Test(org.junit.Test)

Example 30 with Timer

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);
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Aggregations

Timer (com.google.firebase.perf.util.Timer)38 Test (org.junit.Test)29 Before (org.junit.Before)7 TransportManager (com.google.firebase.perf.transport.TransportManager)4 TraceMetric (com.google.firebase.perf.v1.TraceMetric)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)3 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)3 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)3 Clock (com.google.firebase.perf.util.Clock)3 Constants (com.google.firebase.perf.util.Constants)3 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)3 RunWith (org.junit.runner.RunWith)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 ArgumentMatchers.nullable (org.mockito.ArgumentMatchers.nullable)3 Mock (org.mockito.Mock)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 Mockito.mock (org.mockito.Mockito.mock)3