Search in sources :

Example 11 with CrashlyticsReportWithSessionId

use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.

the class CrashlyticsReportPersistenceTest method testFinalizeSessionWithNativeEvent_writesNativeSessions.

public void testFinalizeSessionWithNativeEvent_writesNativeSessions() {
    final CrashlyticsReport testReport = makeTestReport("sessionId");
    reportPersistence.persistReport(testReport);
    CrashlyticsReport.FilesPayload filesPayload = makeFilePayload();
    List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(0, finalizedReports.size());
    reportPersistence.finalizeSessionWithNativeEvent("sessionId", filesPayload);
    finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(1, finalizedReports.size());
    assertEquals(filesPayload, finalizedReports.get(0).getReport().getNdkPayload());
}
Also used : CrashlyticsReport(com.google.firebase.crashlytics.internal.model.CrashlyticsReport) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)

Example 12 with CrashlyticsReportWithSessionId

use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId 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 13 with CrashlyticsReportWithSessionId

use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId 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 14 with CrashlyticsReportWithSessionId

use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.

the class CrashlyticsReportPersistenceTest method testFinalizeReports_prioritizesNativeAndNonnativeFatals.

public void testFinalizeReports_prioritizesNativeAndNonnativeFatals() throws IOException {
    CrashlyticsReport.FilesPayload filesPayload = makeFilePayload();
    reportPersistence = new CrashlyticsReportPersistence(fileStore, createSettingsProviderMock(4, VERY_LARGE_UPPER_LIMIT));
    persistReportWithEvent(reportPersistence, "testSession1", true);
    reportPersistence.finalizeSessionWithNativeEvent("testSession1", filesPayload);
    persistReportWithEvent(reportPersistence, "testSession2low", false);
    persistReportWithEvent(reportPersistence, "testSession3low", false);
    persistReportWithEvent(reportPersistence, "testSession4", true);
    reportPersistence.finalizeSessionWithNativeEvent("testSession4", filesPayload);
    reportPersistence.finalizeReports("skippedSession", 0L);
    List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
    Set<String> reportNames = new HashSet<>();
    for (CrashlyticsReportWithSessionId finalizedReport : finalizedReports) {
        reportNames.add(finalizedReport.getSessionId());
    }
    assertEquals(Sets.newSet("testSession1", "testSession4"), reportNames);
    assertEquals(4, finalizedReports.size());
}
Also used : CrashlyticsReport(com.google.firebase.crashlytics.internal.model.CrashlyticsReport) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) HashSet(java.util.HashSet)

Example 15 with CrashlyticsReportWithSessionId

use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.

the class CrashlyticsReportPersistenceTest method testLoadFinalizedReports_reportsWithUserIdInMultipleSessions_returnsReportsWithProperUserIds.

public void testLoadFinalizedReports_reportsWithUserIdInMultipleSessions_returnsReportsWithProperUserIds() {
    final String userId1 = "testUser1";
    final String userId2 = "testUser2";
    final String sessionId1 = "testSession1";
    final String sessionId2 = "testSession2";
    final CrashlyticsReport testReport1 = makeTestReport(sessionId1, userId1);
    final CrashlyticsReport testReport2 = makeTestReport(sessionId2, userId2);
    final CrashlyticsReport.Session.Event testEvent1 = makeTestEvent();
    final CrashlyticsReport.Session.Event testEvent2 = makeTestEvent();
    reportPersistence.persistReport(testReport1);
    reportPersistence.persistReport(testReport2);
    reportPersistence.persistEvent(testEvent1, sessionId1);
    reportPersistence.persistEvent(testEvent2, sessionId2);
    reportPersistence.finalizeReports("skippedSession", 0L);
    final List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
    assertEquals(2, finalizedReports.size());
    final CrashlyticsReportWithSessionId finalizedReport1 = finalizedReports.get(1);
    assertNotNull(finalizedReport1.getReport().getSession().getUser());
    assertEquals(userId1, finalizedReport1.getReport().getSession().getUser().getIdentifier());
    final CrashlyticsReportWithSessionId finalizedReport2 = finalizedReports.get(0);
    assertNotNull(finalizedReport2.getReport().getSession().getUser());
    assertEquals(userId2, finalizedReport2.getReport().getSession().getUser().getIdentifier());
}
Also used : 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) Session(com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session)

Aggregations

CrashlyticsReportWithSessionId (com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)21 CrashlyticsReport (com.google.firebase.crashlytics.internal.model.CrashlyticsReport)14 Event (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event)8 Session (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session)7 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 NonNull (androidx.annotation.NonNull)2 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)2 Settings (com.google.firebase.crashlytics.internal.settings.Settings)2 FeatureFlagData (com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)2 SettingsProvider (com.google.firebase.crashlytics.internal.settings.SettingsProvider)2 File (java.io.File)2 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 Logger (com.google.firebase.crashlytics.internal.Logger)1 HashSet (java.util.HashSet)1