Search in sources :

Example 6 with FakeScheduledExecutorService

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

the class RemoteConfigManagerTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    fakeExecutor = new FakeScheduledExecutorService();
    when(mockFirebaseRemoteConfigProvider.get()).thenReturn(mockFirebaseRemoteConfigComponent);
    when(mockFirebaseRemoteConfigComponent.get(FIREPERF_FRC_NAMESPACE_NAME)).thenReturn(mockFirebaseRemoteConfig);
    when(mockFirebaseRemoteConfig.getAll()).thenReturn(new HashMap<>());
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Before(org.junit.Before)

Example 7 with FakeScheduledExecutorService

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

the class AppStartTraceTest method testDelayedAppStart.

@Test
public void testDelayedAppStart() {
    FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
    AppStartTrace trace = new AppStartTrace(transportManager, clock, fakeExecutorService);
    // Delays activity creation after 1 minute from app start time.
    currentTime = appStartTime + TimeUnit.MINUTES.toMicros(1) + 1;
    trace.onActivityCreated(activity1, bundle);
    Assert.assertEquals(currentTime, trace.getOnCreateTime().getMicros());
    ++currentTime;
    trace.onActivityStarted(activity1);
    ++currentTime;
    trace.onActivityResumed(activity1);
    Assert.assertNull(trace.getOnStartTime());
    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 8 with FakeScheduledExecutorService

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

the class TransportManagerTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    when(mockConfigResolver.isPerformanceMonitoringEnabled()).thenReturn(true);
    mockInstallationsGetId(FAKE_FIREBASE_INSTALLATIONS_ID);
    when(mockRateLimiter.isEventSampled(ArgumentMatchers.any())).thenReturn(true);
    when(mockRateLimiter.isEventRateLimited(ArgumentMatchers.any())).thenReturn(false);
    fakeExecutorService = new FakeScheduledExecutorService();
    initializeTransport(true);
    fakeExecutorService.runAll();
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Before(org.junit.Before)

Example 9 with FakeScheduledExecutorService

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

the class CpuGaugeCollectorTest method setUp.

@Before
public void setUp() throws IOException {
    fakeScheduledExecutorService = new FakeScheduledExecutorService();
    fakeProcFile = createFakeFileToEmulateProcPidStat("100", "100", "100", "100");
    testGaugeCollector = new CpuGaugeCollector(fakeScheduledExecutorService, fakeProcFile, fakeClockTicksPerSecond);
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Before(org.junit.Before)

Example 10 with FakeScheduledExecutorService

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

the class GaugeManagerTest method setUp.

@Before
public void setUp() {
    fakeScheduledExecutorService = new FakeScheduledExecutorService();
    mockTransportManager = mock(TransportManager.class);
    mockConfigResolver = mock(ConfigResolver.class);
    fakeGaugeMetadataManager = spy(new GaugeMetadataManager(Runtime.getRuntime(), ApplicationProvider.getApplicationContext()));
    fakeCpuGaugeCollector = spy(new CpuGaugeCollector());
    fakeMemoryGaugeCollector = spy(new MemoryGaugeCollector());
    doNothing().when(fakeCpuGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
    doNothing().when(fakeCpuGaugeCollector).stopCollecting();
    doNothing().when(fakeMemoryGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
    doNothing().when(fakeMemoryGaugeCollector).stopCollecting();
    doNothing().when(fakeCpuGaugeCollector).collectOnce(ArgumentMatchers.nullable(Timer.class));
    doNothing().when(fakeMemoryGaugeCollector).collectOnce(ArgumentMatchers.nullable(Timer.class));
    forceVerboseSession();
    doReturn(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_BG_MS).when(mockConfigResolver).getSessionsCpuCaptureFrequencyBackgroundMs();
    doReturn(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_FG_MS).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_BG_MS).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyBackgroundMs();
    doReturn(DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_FG_MS).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    when(mockTransportManager.isInitialized()).thenReturn(true);
    testGaugeManager = new GaugeManager(new Lazy<>(() -> fakeScheduledExecutorService), mockTransportManager, mockConfigResolver, fakeGaugeMetadataManager, new Lazy<>(() -> fakeCpuGaugeCollector), new Lazy<>(() -> fakeMemoryGaugeCollector));
}
Also used : FakeScheduledExecutorService(com.google.testing.timing.FakeScheduledExecutorService) Lazy(com.google.firebase.components.Lazy) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Timer(com.google.firebase.perf.util.Timer) TransportManager(com.google.firebase.perf.transport.TransportManager) Before(org.junit.Before)

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