Search in sources :

Example 6 with Settings

use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.

the class CrashlyticsReportPersistenceTest method testPersistEvent_whenSettingsChanges_keepsAppropriateNumberOfMostRecentEvents.

public void testPersistEvent_whenSettingsChanges_keepsAppropriateNumberOfMostRecentEvents() throws IOException {
    SettingsProvider settingsProvider = mock(SettingsProvider.class);
    Settings.SessionData sessionData1 = new Settings.SessionData(4, VERY_LARGE_UPPER_LIMIT);
    Settings.SessionData sessionData2 = new Settings.SessionData(8, VERY_LARGE_UPPER_LIMIT);
    Settings settings1 = new Settings(0, sessionData1, new FeatureFlagData(true, true), 3, 0, 1.0, 1.0, 1);
    Settings settings2 = new Settings(0, sessionData2, new FeatureFlagData(true, true), 3, 0, 1.0, 1.0, 1);
    when(settingsProvider.getSettingsSync()).thenReturn(settings1);
    reportPersistence = new CrashlyticsReportPersistence(fileStore, settingsProvider);
    final String sessionId = "testSession";
    final CrashlyticsReport testReport = makeTestReport(sessionId);
    final CrashlyticsReport.Session.Event testEvent1 = makeTestEvent("type1", "reason1");
    final CrashlyticsReport.Session.Event testEvent2 = makeTestEvent("type2", "reason2");
    final CrashlyticsReport.Session.Event testEvent3 = makeTestEvent("type3", "reason3");
    final CrashlyticsReport.Session.Event testEvent4 = makeTestEvent("type4", "reason4");
    final CrashlyticsReport.Session.Event testEvent5 = makeTestEvent("type5", "reason5");
    reportPersistence.persistReport(testReport);
    reportPersistence.persistEvent(testEvent1, sessionId);
    reportPersistence.persistEvent(testEvent2, sessionId);
    reportPersistence.persistEvent(testEvent3, sessionId);
    reportPersistence.persistEvent(testEvent4, sessionId);
    reportPersistence.persistEvent(testEvent5, sessionId);
    long endedAt = System.currentTimeMillis();
    reportPersistence.finalizeReports("skippedSession", endedAt);
    final List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(1, finalizedReports.size());
    final CrashlyticsReport finalizedReport = finalizedReports.get(0).getReport();
    assertEquals(4, finalizedReport.getSession().getEvents().size());
    assertEquals(testReport.withSessionEndFields(endedAt, false, null).withEvents(ImmutableList.from(testEvent2, testEvent3, testEvent4, testEvent5)), finalizedReport);
    when(settingsProvider.getSettingsSync()).thenReturn(settings2);
    final CrashlyticsReport.Session.Event testEvent6 = makeTestEvent("type6", "reason6");
    final CrashlyticsReport.Session.Event testEvent7 = makeTestEvent("type7", "reason7");
    final CrashlyticsReport.Session.Event testEvent8 = makeTestEvent("type8", "reason8");
    final CrashlyticsReport.Session.Event testEvent9 = makeTestEvent("type9", "reason9");
    final CrashlyticsReport.Session.Event testEvent10 = makeTestEvent("type10", "reason10");
    final String sessionId2 = "testSession2";
    final CrashlyticsReport testReport2 = makeTestReport(sessionId2);
    reportPersistence.persistReport(testReport2);
    reportPersistence.persistEvent(testEvent1, sessionId2);
    reportPersistence.persistEvent(testEvent2, sessionId2);
    reportPersistence.persistEvent(testEvent3, sessionId2);
    reportPersistence.persistEvent(testEvent4, sessionId2);
    reportPersistence.persistEvent(testEvent5, sessionId2);
    reportPersistence.persistEvent(testEvent6, sessionId2);
    reportPersistence.persistEvent(testEvent7, sessionId2);
    reportPersistence.persistEvent(testEvent8, sessionId2);
    reportPersistence.persistEvent(testEvent9, sessionId2);
    reportPersistence.persistEvent(testEvent10, sessionId2);
    endedAt = System.currentTimeMillis();
    reportPersistence.finalizeReports("skippedSession", endedAt);
    final List<CrashlyticsReportWithSessionId> finalizedReports2 = reportPersistence.loadFinalizedReports();
    assertEquals(2, finalizedReports2.size());
    final CrashlyticsReport finalizedReport2 = finalizedReports2.get(0).getReport();
    assertEquals(8, finalizedReport2.getSession().getEvents().size());
    assertEquals(testReport2.withSessionEndFields(endedAt, false, null).withEvents(ImmutableList.from(testEvent3, testEvent4, testEvent5, testEvent6, testEvent7, testEvent8, testEvent9, testEvent10)), finalizedReport2);
}
Also used : FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData) SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) CrashlyticsReport(com.google.firebase.crashlytics.internal.model.CrashlyticsReport) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) Event(com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event) Settings(com.google.firebase.crashlytics.internal.settings.Settings) Session(com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session)

Example 7 with Settings

use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.

the class CrashlyticsControllerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    testContext = getContext();
    FirebaseInstallationsApi installationsApiMock = mock(FirebaseInstallationsApi.class);
    when(installationsApiMock.getId()).thenReturn(Tasks.forResult("instanceId"));
    idManager = new IdManager(testContext, testContext.getPackageName(), installationsApiMock, DataCollectionArbiterTest.MOCK_ARBITER_ENABLED);
    testFileStore = new FileStore(testContext);
    Settings testSettings = new TestSettings(3);
    mockSessionReportingCoordinator = mock(SessionReportingCoordinator.class);
    mockDataCollectionArbiter = mock(DataCollectionArbiter.class);
    when(mockDataCollectionArbiter.isAutomaticDataCollectionEnabled()).thenReturn(true);
    testSettingsProvider = mock(SettingsProvider.class);
    when(testSettingsProvider.getSettingsSync()).thenReturn(testSettings);
    when(testSettingsProvider.getSettingsAsync()).thenReturn(Tasks.forResult(testSettings));
}
Also used : SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) FileStore(com.google.firebase.crashlytics.internal.persistence.FileStore) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) FirebaseInstallationsApi(com.google.firebase.installations.FirebaseInstallationsApi) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) Settings(com.google.firebase.crashlytics.internal.settings.Settings)

Example 8 with Settings

use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.

the class CrashlyticsCoreInitializationTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mockAppContext = newMockContext();
    mockResources = mock(Resources.class);
    testFirebaseOptions = new FirebaseOptions.Builder().setApplicationId(GOOGLE_APP_ID).build();
    fileStore = new FileStore(getContext());
    mockSettingsController = mock(SettingsController.class);
    Settings settings = new TestSettings();
    when(mockSettingsController.getSettingsSync()).thenReturn(settings);
    when(mockSettingsController.getSettingsAsync()).thenReturn(Tasks.forResult(settings));
}
Also used : FileStore(com.google.firebase.crashlytics.internal.persistence.FileStore) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) Resources(android.content.res.Resources) FirebaseOptions(com.google.firebase.FirebaseOptions) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) Settings(com.google.firebase.crashlytics.internal.settings.Settings) SettingsController(com.google.firebase.crashlytics.internal.settings.SettingsController)

Example 9 with Settings

use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.

the class CrashlyticsCoreTest method startCoreAsync.

// Starts the given CrashlyticsCore.
private Task<CrashlyticsCore> startCoreAsync(CrashlyticsCore crashlyticsCore) {
    // Swallow exceptions so tests don't crash.
    Thread.setDefaultUncaughtExceptionHandler(NOOP_HANDLER);
    SettingsController mockSettingsController = mock(SettingsController.class);
    final Settings settings = new TestSettings(3);
    when(mockSettingsController.getSettingsSync()).thenReturn(settings);
    when(mockSettingsController.getSettingsAsync()).thenReturn(Tasks.forResult(settings));
    AppData appData = new AppData(GOOGLE_APP_ID, "buildId", "installerPackageName", "packageName", "versionCode", "versionName", mock(DevelopmentPlatformProvider.class));
    crashlyticsCore.onPreExecute(appData, mockSettingsController);
    return crashlyticsCore.doBackgroundInitializationAsync(mockSettingsController).onSuccessTask(new SuccessContinuation<Void, CrashlyticsCore>() {

        @NonNull
        @Override
        public Task<CrashlyticsCore> then(@Nullable Void aVoid) throws Exception {
            return Tasks.forResult(crashlyticsCore);
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) DevelopmentPlatformProvider(com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) NonNull(androidx.annotation.NonNull) TestSettings(com.google.firebase.crashlytics.internal.settings.TestSettings) Settings(com.google.firebase.crashlytics.internal.settings.Settings) SettingsController(com.google.firebase.crashlytics.internal.settings.SettingsController)

Aggregations

Settings (com.google.firebase.crashlytics.internal.settings.Settings)9 FeatureFlagData (com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)4 SettingsProvider (com.google.firebase.crashlytics.internal.settings.SettingsProvider)4 TestSettings (com.google.firebase.crashlytics.internal.settings.TestSettings)3 NonNull (androidx.annotation.NonNull)2 Task (com.google.android.gms.tasks.Task)2 CrashlyticsReportWithSessionId (com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)2 FileStore (com.google.firebase.crashlytics.internal.persistence.FileStore)2 SettingsController (com.google.firebase.crashlytics.internal.settings.SettingsController)2 TimeoutException (java.util.concurrent.TimeoutException)2 Resources (android.content.res.Resources)1 FirebaseOptions (com.google.firebase.FirebaseOptions)1 DevelopmentPlatformProvider (com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider)1 CrashlyticsReport (com.google.firebase.crashlytics.internal.model.CrashlyticsReport)1 Session (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session)1 Event (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event)1 SessionData (com.google.firebase.crashlytics.internal.settings.Settings.SessionData)1 FirebaseInstallationsApi (com.google.firebase.installations.FirebaseInstallationsApi)1 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1