Search in sources :

Example 1 with ImmutableBundle

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

the class AppStateMonitorTest method foreGroundTrace_perfMonDeactivated_traceCreated.

@Test
public void foreGroundTrace_perfMonDeactivated_traceCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // Firebase Performance is deactivated at build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    // activity1 comes to foreground.
    currentTime = 1;
    monitor.onActivityResumed(activity1);
    // activity1 goes to background.
    currentTime = 2;
    monitor.onActivityStopped(activity1);
    assertThat(monitor.isForeground()).isFalse();
    // Foreground trace is not created because Performance Monitoring is deactivated at build time.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // Developer enabled Performance Monitoring during runtime.
    ConfigResolver.getInstance().setIsPerformanceCollectionEnabled(true);
    // activity1 comes to foreground.
    currentTime = 3;
    monitor.onActivityResumed(activity1);
    // activity1 goes to background.
    currentTime = 4;
    monitor.onActivityStopped(activity1);
    assertThat(monitor.isForeground()).isFalse();
    // Foreground trace is not created because deactivation takes higher priority.
    verify(transportManager, never()).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 2 with ImmutableBundle

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

the class FirebasePerformanceTestBase method forceVerboseSessionWithSamplingPercentage.

private static void forceVerboseSessionWithSamplingPercentage(long samplingPercentage) {
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", samplingPercentage);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
    SessionManager.getInstance().setPerfSession(PerfSession.create());
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle)

Example 3 with ImmutableBundle

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

the class AppStateMonitorTest method screenTrace_perfMonDeactivated_traceNotCreated.

@Test
public void screenTrace_perfMonDeactivated_traceNotCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Activity activityWithNonHardwareAcceleratedView = createFakeActivity(/* isHardwareAccelerated =*/
    true);
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    configResolver.setMetadataBundle(new ImmutableBundle(bundle));
    // Developer has enabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(true);
    // Assert that screen trace has not been created.
    monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
    // Confirm that this doesn't throw an exception.
    monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Activity(android.app.Activity) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 4 with ImmutableBundle

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

the class ConfigResolverTest method getSessionsMaxDurationMinutes_invalidMetadataBundle_returnCacheValue.

@Test
public void getSessionsMaxDurationMinutes_invalidMetadataBundle_returnCacheValue() {
    when(mockRemoteConfigManager.getLong(SESSIONS_MAX_DURATION_MIN_FRC_KEY)).thenReturn(Optional.absent());
    when(mockDeviceCacheManager.getLong(SESSIONS_MAX_DURATION_MIN_CACHE_KEY)).thenReturn(Optional.of(200L));
    assertThat(testConfigResolver.getSessionsMaxDurationMinutes()).isEqualTo(200L);
    // Android Metadata bundle value is too high.
    Bundle bundle = new Bundle();
    bundle.putInt(SESSIONS_MAX_DURATION_MIN_METADATA_KEY, -200);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsMaxDurationMinutes()).isEqualTo(200L);
    // Android Metadata bundle value is 0.
    bundle.putInt(SESSIONS_MAX_DURATION_MIN_METADATA_KEY, 0);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsMaxDurationMinutes()).isEqualTo(200L);
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 5 with ImmutableBundle

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

the class ConfigResolverTest method getSessionsSamplingRate_metadataAndRemoteConfigAndCacheAreSet_metadataHasHighestConfigPrecedence.

@Test
public void getSessionsSamplingRate_metadataAndRemoteConfigAndCacheAreSet_metadataHasHighestConfigPrecedence() {
    // Set cache value.
    when(mockDeviceCacheManager.getFloat(SESSION_SAMPLING_RATE_CACHE_KEY)).thenReturn(Optional.of(0.2f));
    // Set remote config value.
    when(mockRemoteConfigManager.getFloat(SESSION_SAMPLING_RATE_FRC_KEY)).thenReturn(Optional.of(0.3f));
    // Set Android Manifest value.
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 4.0f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.04f);
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Aggregations

Bundle (android.os.Bundle)63 ImmutableBundle (com.google.firebase.perf.util.ImmutableBundle)63 Test (org.junit.Test)60 TraceMetric (com.google.firebase.perf.v1.TraceMetric)5 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)4 Activity (android.app.Activity)3 ApplicationInfo (android.content.pm.ApplicationInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)1 FakeDirectExecutorService (com.google.testing.timing.FakeDirectExecutorService)1