Search in sources :

Example 46 with ImmutableBundle

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

the class ConfigResolverTest method getSessionsSamplingRate_invalidAndroidMetadataBundle_returnDefaultValue.

@Test
public void getSessionsSamplingRate_invalidAndroidMetadataBundle_returnDefaultValue() {
    when(mockRemoteConfigManager.getFloat(SESSION_SAMPLING_RATE_FRC_KEY)).thenReturn(Optional.absent());
    when(mockDeviceCacheManager.getFloat(SESSION_SAMPLING_RATE_CACHE_KEY)).thenReturn(Optional.absent());
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.01f);
    // Case #1: Android Metadata bundle value is too high.
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 200.00f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.01f);
    // Case #2: Android Metadata bundle value is too low.
    bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", -1.00f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.01f);
}
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 47 with ImmutableBundle

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

the class ConfigResolverTest method getSessionsSamplingRate_invalidAndroidMetadataBundle_returnRemoteConfigValue.

@Test
public void getSessionsSamplingRate_invalidAndroidMetadataBundle_returnRemoteConfigValue() {
    when(mockRemoteConfigManager.getFloat(SESSION_SAMPLING_RATE_FRC_KEY)).thenReturn(Optional.of(0.25f));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.25f);
    // Case #1: Android Metadata bundle value is too high.
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 200.00f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.25f);
    // Case #2: Android Metadata bundle value is too low.
    bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", -1.00f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.25f);
}
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 48 with ImmutableBundle

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

the class ConfigResolverTest method getSessionsSamplingRate_validMetadata_returnsMetadata.

@Test
public void getSessionsSamplingRate_validMetadata_returnsMetadata() {
    // #1 pass: Validate that method returns Remote Config Value when there is no metadata value.
    when(mockRemoteConfigManager.getFloat(SESSION_SAMPLING_RATE_FRC_KEY)).thenReturn(Optional.of(0.01f));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.01f);
    // #2 pass: Validate that method returns Metadata value which takes higher precedence.
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 20.0f);
    testConfigResolver.setMetadataBundle(new ImmutableBundle(bundle));
    assertThat(testConfigResolver.getSessionsSamplingRate()).isEqualTo(0.2f);
}
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 49 with ImmutableBundle

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

the class FirebasePerformanceTestBase method forceSessionsFeatureDisabled.

protected static void forceSessionsFeatureDisabled() {
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 0);
    ConfigResolver.getInstance().setMetadataBundle(new ImmutableBundle(bundle));
}
Also used : Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle)

Example 50 with ImmutableBundle

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

the class AppStateMonitorTest method foregroundTrace_perfMonEnabledAtRuntime_traceCreated.

@Test
public void foregroundTrace_perfMonEnabledAtRuntime_traceCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    // Firebase Performance is disabled at build time.
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_enabled", false);
    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 disabled 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);
    // Background trace has been created because Performance Monitoring is enabled.
    verify(transportManager, times(1)).log(any(TraceMetric.class), eq(FOREGROUND_BACKGROUND));
    // activity1 goes to background.
    currentTime = 4;
    monitor.onActivityStopped(activity1);
    assertThat(monitor.isForeground()).isFalse();
    // Foreground trace has been created because Performance Monitoring is enabled.
    verify(transportManager, times(2)).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)

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