use of com.google.firebase.crashlytics.internal.model.CrashlyticsReport in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistence method loadFinalizedReports.
/**
* @return finalized (no longer changing) Crashlytics Reports, sorted first from high to low
* priority, secondarily sorted from most recent to least
*/
@NonNull
public List<CrashlyticsReportWithSessionId> loadFinalizedReports() {
final List<File> allReportFiles = getAllFinalizedReportFiles();
final ArrayList<CrashlyticsReportWithSessionId> allReports = new ArrayList<>();
for (File reportFile : allReportFiles) {
try {
CrashlyticsReport jsonReport = TRANSFORM.reportFromJson(readTextFile(reportFile));
allReports.add(CrashlyticsReportWithSessionId.create(jsonReport, reportFile.getName(), reportFile));
} catch (IOException e) {
Logger.getLogger().w("Could not load report file " + reportFile + "; deleting", e);
reportFile.delete();
}
}
return allReports;
}
use of com.google.firebase.crashlytics.internal.model.CrashlyticsReport 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());
}
use of com.google.firebase.crashlytics.internal.model.CrashlyticsReport 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);
}
use of com.google.firebase.crashlytics.internal.model.CrashlyticsReport 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());
}
use of com.google.firebase.crashlytics.internal.model.CrashlyticsReport in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method testLoadFinalizedReports_reportThenMultipleEvents_returnsReportWithMultipleEvents.
public void testLoadFinalizedReports_reportThenMultipleEvents_returnsReportWithMultipleEvents() {
final String sessionId = "testSession";
final CrashlyticsReport testReport = makeTestReport(sessionId);
final CrashlyticsReport.Session.Event testEvent = makeTestEvent();
final CrashlyticsReport.Session.Event testEvent2 = makeTestEvent();
reportPersistence.persistReport(testReport);
reportPersistence.persistEvent(testEvent, sessionId);
reportPersistence.persistEvent(testEvent2, sessionId);
final 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(testReport.withSessionEndFields(endedAt, false, null).withEvents(ImmutableList.from(testEvent, testEvent2)), finalizedReport);
}
Aggregations