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);
}
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);
}
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);
}
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));
}
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));
}
Aggregations