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