Search in sources :

Example 1 with SettingsProvider

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

the class CrashlyticsReportPersistenceTest method testFinalizeReports_whenSettingsChanges_capsReports.

public void testFinalizeReports_whenSettingsChanges_capsReports() throws IOException {
    SettingsProvider settingsProvider = mock(SettingsProvider.class);
    Settings.SessionData sessionData1 = new Settings.SessionData(VERY_LARGE_UPPER_LIMIT, 4);
    Settings.SessionData sessionData2 = new Settings.SessionData(VERY_LARGE_UPPER_LIMIT, 8);
    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);
    DecimalFormat format = new DecimalFormat("00");
    for (int i = 0; i < 16; i++) {
        persistReportWithEvent(reportPersistence, "testSession" + format.format(i), true);
    }
    reportPersistence.finalizeReports("skippedSession", 0L);
    List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(4, finalizedReports.size());
    when(settingsProvider.getSettingsSync()).thenReturn(settings2);
    for (int i = 16; i < 32; i++) {
        persistReportWithEvent(reportPersistence, "testSession" + i, true);
    }
    reportPersistence.finalizeReports("skippedSession", 0L);
    finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(8, finalizedReports.size());
}
Also used : SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) DecimalFormat(java.text.DecimalFormat) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) Settings(com.google.firebase.crashlytics.internal.settings.Settings) FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)

Example 2 with SettingsProvider

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

the class CrashlyticsReportPersistenceTest method createSettingsProviderMock.

private static SettingsProvider createSettingsProviderMock(int maxCompleteSessionsCount, int maxCustomExceptionEvents) {
    SettingsProvider settingsProvider = mock(SettingsProvider.class);
    Settings.SessionData sessionData = new Settings.SessionData(maxCustomExceptionEvents, maxCompleteSessionsCount);
    Settings settings = new Settings(0, sessionData, new FeatureFlagData(true, false), 3, 0, 1.0, 1.0, 1);
    when(settingsProvider.getSettingsSync()).thenReturn(settings);
    return settingsProvider;
}
Also used : SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) Settings(com.google.firebase.crashlytics.internal.settings.Settings) FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)

Example 3 with SettingsProvider

use of com.google.firebase.crashlytics.internal.settings.SettingsProvider 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)

Aggregations

Settings (com.google.firebase.crashlytics.internal.settings.Settings)3 FeatureFlagData (com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)3 SettingsProvider (com.google.firebase.crashlytics.internal.settings.SettingsProvider)3 CrashlyticsReportWithSessionId (com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)2 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 DecimalFormat (java.text.DecimalFormat)1