Search in sources :

Example 11 with Timer

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

the class CpuGaugeCollectorTest method testDoesntCollectAnyDataWhenInvalidValueForCpuClockTicksPerSecond.

@Test
public void testDoesntCollectAnyDataWhenInvalidValueForCpuClockTicksPerSecond() {
    final long invalidClockTicksPerSecond = -1;
    testGaugeCollector = new CpuGaugeCollector(fakeScheduledExecutorService, fakeProcFile, invalidClockTicksPerSecond);
    testGaugeCollector.startCollecting(100, new Timer());
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 12 with Timer

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

the class MemoryGaugeCollectorTest method testStopCollecting_cancelsFutureTasks.

@Test
public void testStopCollecting_cancelsFutureTasks() {
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    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 13 with Timer

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

the class MemoryGaugeCollectorTest method testCollectedMemoryMetric_containsApproximatelyCorrectTimestamp.

@Test
public void testCollectedMemoryMetric_containsApproximatelyCorrectTimestamp() {
    Timer testTimer = new Timer();
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    100, testTimer);
    long beforeTimestampUs = testTimer.getCurrentTimestampMicros();
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    long afterTimestampUs = testTimer.getCurrentTimestampMicros();
    AndroidMemoryReading metricReading = testGaugeCollector.memoryMetricReadings.poll();
    assertThat(metricReading.getClientTimeUs()).isAtLeast(beforeTimestampUs);
    assertThat(metricReading.getClientTimeUs()).isAtMost(afterTimestampUs);
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 14 with Timer

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

the class MemoryGaugeCollectorTest method testStartCollecting_hasCorrectInterval.

@Test
public void testStartCollecting_hasCorrectInterval() {
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    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(/* memoryMetricCollectionRateMs= */
    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 15 with Timer

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

the class MemoryGaugeCollectorTest method testCollectMemoryMetric_doesNotStartCollecting_withInvalidMemoryMetricCollectionRate.

@Test
public void testCollectMemoryMetric_doesNotStartCollecting_withInvalidMemoryMetricCollectionRate() {
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    -1, new Timer());
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    0, new Timer());
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
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