Search in sources :

Example 1 with Lazy

use of com.google.firebase.components.Lazy in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testLogGaugeMetadataLogsAfterApplicationContextIsSet.

@Test
public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
    testGaugeManager = new GaugeManager(new Lazy<>(() -> fakeScheduledExecutorService), mockTransportManager, mockConfigResolver, /* gaugeMetadataManager= */
    null, new Lazy<>(() -> fakeCpuGaugeCollector), new Lazy<>(() -> fakeMemoryGaugeCollector));
    assertThat(testGaugeManager.logGaugeMetadata("sessionId", ApplicationProcessState.FOREGROUND)).isFalse();
    testGaugeManager.initializeGaugeMetadataManager(ApplicationProvider.getApplicationContext());
    assertThat(testGaugeManager.logGaugeMetadata("sessionId", ApplicationProcessState.FOREGROUND)).isTrue();
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
    GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
    assertThat(recordedGaugeMetric.getSessionId()).isEqualTo("sessionId");
    assertThat(recordedGaugeMetadata.hasProcessName()).isTrue();
}
Also used : Lazy(com.google.firebase.components.Lazy) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) Test(org.junit.Test)

Example 2 with Lazy

use of com.google.firebase.components.Lazy 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

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