Search in sources :

Example 21 with Timer

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

the class FirebasePerfOkHttpClient method enqueue.

@Keep
public static void enqueue(final Call call, final Callback callback) {
    Timer timer = new Timer();
    long startTime = timer.getMicros();
    call.enqueue(new InstrumentOkHttpEnqueueCallback(callback, TransportManager.getInstance(), timer, startTime));
}
Also used : Timer(com.google.firebase.perf.util.Timer) Keep(androidx.annotation.Keep)

Example 22 with Timer

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

the class RateLimiterTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    doAnswer(new Answer<Timer>() {

        @Override
        public Timer answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new Timer(MICROS.between(Instant.EPOCH, currentTime));
        }
    }).when(mClock).getTime();
}
Also used : Timer(com.google.firebase.perf.util.Timer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Example 23 with Timer

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

the class PerfSessionTest method testIsExpiredReturnsFalseWhenCurrentSessionLengthIsEqualToMaxSessionLength.

@Test
public void testIsExpiredReturnsFalseWhenCurrentSessionLengthIsEqualToMaxSessionLength() {
    Timer mockTimer = mock(Timer.class);
    when(mockTimer.getDurationMicros()).thenReturn(// Default Max Session Length is 4 hours
    TimeUnit.HOURS.toMicros(4));
    when(mockClock.getTime()).thenReturn(mockTimer);
    PerfSession session = new PerfSession("sessionId", mockClock);
    assertThat(session.isExpired()).isFalse();
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 24 with Timer

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

the class PerfSessionTest method testIsExpiredReturnsFalseWhenCurrentSessionLengthIsLessThanMaxSessionLength.

@Test
public void testIsExpiredReturnsFalseWhenCurrentSessionLengthIsLessThanMaxSessionLength() {
    Timer mockTimer = mock(Timer.class);
    when(mockTimer.getDurationMicros()).thenReturn(TimeUnit.HOURS.toMicros(4) - // Default Max Session Length is 4 hours
    TimeUnit.MINUTES.toMicros(1));
    when(mockClock.getTime()).thenReturn(mockTimer);
    PerfSession session = new PerfSession("sessionId", mockClock);
    assertThat(session.isExpired()).isFalse();
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 25 with Timer

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

the class PerfSessionTest method testIsExpiredReturnsTrueWhenCurrentSessionLengthIsGreaterThanMaxSessionLength.

@Test
public void testIsExpiredReturnsTrueWhenCurrentSessionLengthIsGreaterThanMaxSessionLength() {
    Timer mockTimer = mock(Timer.class);
    when(mockTimer.getDurationMicros()).thenReturn(// Default Max Session Length is 4 hours
    TimeUnit.HOURS.toMicros(5));
    when(mockClock.getTime()).thenReturn(mockTimer);
    PerfSession session = new PerfSession("sessionId", mockClock);
    assertThat(session.isExpired()).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