Search in sources :

Example 6 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class PerfSessionTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    DeviceCacheManager.clearInstance();
    ConfigResolver.clearInstance();
    appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().commit();
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setApplicationContext(appContext);
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) Before(org.junit.Before)

Example 7 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class PerfSessionTest method shouldCollectGaugesAndEvents_perfMonDeactivated_sessionNotVerbose.

@Test
public void shouldCollectGaugesAndEvents_perfMonDeactivated_sessionNotVerbose() {
    ConfigResolver configResolver = ConfigResolver.getInstance();
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 100f);
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    configResolver.setMetadataBundle(new ImmutableBundle(bundle));
    // Session will never be verbose if developer deactivated performance monitoring at build time.
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
    // Case #1: developer has enabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(true);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
    // Case #2: developer has disabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(false);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 8 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class TraceTest method setUp.

@Before
public void setUp() {
    currentTime = 1;
    initMocks(this);
    doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(mockClock).getTime();
    arguments = ArgumentCaptor.forClass(TraceMetric.class);
    DeviceCacheManager.clearInstance();
    ConfigResolver.clearInstance();
    appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().commit();
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
    configResolver.setApplicationContext(appContext);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Context(android.content.Context) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ArgumentMatchers(org.mockito.ArgumentMatchers) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Random(java.util.Random) PREFS_NAME(com.google.firebase.perf.util.Constants.PREFS_NAME) Parcel(android.os.Parcel) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) Answer(org.mockito.stubbing.Answer) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) Constants(com.google.firebase.perf.util.Constants) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfSession(com.google.firebase.perf.session.PerfSession) FirebasePerformanceTestBase(com.google.firebase.perf.FirebasePerformanceTestBase) GaugeManager(com.google.firebase.perf.session.gauges.GaugeManager) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Before(org.junit.Before) Timer(com.google.firebase.perf.util.Timer) Clock(com.google.firebase.perf.util.Clock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) TransportManager(com.google.firebase.perf.transport.TransportManager) Mockito.verify(org.mockito.Mockito.verify) SessionManager(com.google.firebase.perf.session.SessionManager) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) Mockito.never(org.mockito.Mockito.never) Mockito.mock(org.mockito.Mockito.mock) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Timer(com.google.firebase.perf.util.Timer) TraceMetric(com.google.firebase.perf.v1.TraceMetric) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) Before(org.junit.Before)

Aggregations

ConfigResolver (com.google.firebase.perf.config.ConfigResolver)8 Test (org.junit.Test)6 Bundle (android.os.Bundle)5 ImmutableBundle (com.google.firebase.perf.util.ImmutableBundle)5 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)4 FakeDirectExecutorService (com.google.testing.timing.FakeDirectExecutorService)4 Before (org.junit.Before)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 FirebasePerformanceInitializer (com.google.firebase.perf.FirebasePerformanceInitializer)2 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)2 AppStateMonitor (com.google.firebase.perf.application.AppStateMonitor)2 SessionManager (com.google.firebase.perf.session.SessionManager)2 GaugeManager (com.google.firebase.perf.session.gauges.GaugeManager)2 TransportManager (com.google.firebase.perf.transport.TransportManager)2 Clock (com.google.firebase.perf.util.Clock)2 Constants (com.google.firebase.perf.util.Constants)2 Timer (com.google.firebase.perf.util.Timer)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2