Search in sources :

Example 1 with FakeScheduledExecutorService

use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.

the class MemoryGaugeCollectorTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    mockMemory();
    fakeScheduledExecutorService = new FakeScheduledExecutorService();
    testGaugeCollector = new MemoryGaugeCollector(fakeScheduledExecutorService, runtime);
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Before(org.junit.Before)

Example 2 with FakeScheduledExecutorService

use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.

the class DeviceCacheManagerTest method setUp.

@Before
public void setUp() {
    fakeScheduledExecutorService = new FakeScheduledExecutorService();
    deviceCacheManager = new DeviceCacheManager(fakeScheduledExecutorService);
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Before(org.junit.Before)

Example 3 with FakeScheduledExecutorService

use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.

the class AppStartTraceTest method testStartFromBackground.

@Test
public void testStartFromBackground() {
    FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
    AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
    trace.setIsStartFromBackground();
    trace.onActivityCreated(activity1, bundle);
    Assert.assertNull(trace.getOnCreateTime());
    ++currentTime;
    trace.onActivityStarted(activity1);
    Assert.assertNull(trace.getOnStartTime());
    ++currentTime;
    trace.onActivityResumed(activity1);
    Assert.assertNull(trace.getOnResumeTime());
    // There should be no trace sent.
    verify(transportManager, times(0)).log(traceArgumentCaptor.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) Test(org.junit.Test)

Example 4 with FakeScheduledExecutorService

use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.

the class AppStartTraceTest method testInterleavedActivity.

/**
 * Test second activity kicking in before the first activity onResume(). Second activity has no
 * effect on AppStartTrace object.
 */
@Test
public void testInterleavedActivity() {
    FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
    AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
    // first activity onCreate()
    currentTime = 1;
    trace.onActivityCreated(activity1, bundle);
    Assert.assertEquals(activity1, trace.getLaunchActivity());
    Assert.assertEquals(1, trace.getOnCreateTime().getMicros());
    // second activity onCreate(), should not change onCreate time.
    currentTime = 2;
    trace.onActivityCreated(activity2, bundle);
    Assert.assertEquals(1, trace.getOnCreateTime().getMicros());
    // second activity onStart() time is recorded as onStartTime.
    currentTime = 3;
    trace.onActivityStarted(activity2);
    Assert.assertEquals(3, trace.getOnStartTime().getMicros());
    // second activity onResume() time is recorded as onResumeTime.
    // and second activity is recorded as AppStartActivity.
    currentTime = 4;
    trace.onActivityResumed(activity2);
    Assert.assertEquals(activity1, trace.getLaunchActivity());
    Assert.assertEquals(activity2, trace.getAppStartActivity());
    fakeExecutorService.runAll();
    verifyFinalState(activity2, trace, 1, 3, 4);
    // first activity continues.
    currentTime = 5;
    trace.onActivityStarted(activity1);
    currentTime = 6;
    trace.onActivityResumed(activity1);
    fakeExecutorService.runAll();
    verifyFinalState(activity2, trace, 1, 3, 4);
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Test(org.junit.Test)

Example 5 with FakeScheduledExecutorService

use of com.google.testing.timing.FakeScheduledExecutorService in project firebase-android-sdk by firebase.

the class AppStartTraceTest method testLaunchActivity.

/**
 * Test activity sequentially goes through onCreate()->onStart()->onResume() state change.
 */
@Test
public void testLaunchActivity() {
    FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
    AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
    // first activity goes through onCreate()->onStart()->onResume() state change.
    currentTime = 1;
    trace.onActivityCreated(activity1, bundle);
    currentTime = 2;
    trace.onActivityStarted(activity1);
    currentTime = 3;
    trace.onActivityResumed(activity1);
    fakeExecutorService.runAll();
    verifyFinalState(activity1, trace, 1, 2, 3);
    // same activity goes through onCreate()->onStart()->onResume() state change again.
    // should have no effect on AppStartTrace.
    currentTime = 4;
    trace.onActivityCreated(activity1, bundle);
    currentTime = 5;
    trace.onActivityStarted(activity1);
    currentTime = 6;
    trace.onActivityResumed(activity1);
    fakeExecutorService.runAll();
    verifyFinalState(activity1, trace, 1, 2, 3);
    // a different activity goes through onCreate()->onStart()->onResume() state change.
    // should have no effect on AppStartTrace.
    currentTime = 7;
    trace.onActivityCreated(activity2, bundle);
    currentTime = 8;
    trace.onActivityStarted(activity2);
    currentTime = 9;
    trace.onActivityResumed(activity2);
    fakeExecutorService.runAll();
    verifyFinalState(activity1, trace, 1, 2, 3);
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Test(org.junit.Test)

Aggregations

FakeScheduledExecutorService (com.google.testing.timing.FakeScheduledExecutorService)10 Before (org.junit.Before)6 Test (org.junit.Test)4 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2 Lazy (com.google.firebase.components.Lazy)1 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1 Timer (com.google.firebase.perf.util.Timer)1