use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method testFinalizeReports_removesLowPriorityReportsFirst.
public void testFinalizeReports_removesLowPriorityReportsFirst() throws IOException {
reportPersistence = new CrashlyticsReportPersistence(fileStore, createSettingsProviderMock(4, VERY_LARGE_UPPER_LIMIT));
for (int i = 0; i < 10; i++) {
boolean priority = i >= 3 && i <= 8;
String sessionId = "testSession" + i + (priority ? "high" : "low");
persistReportWithEvent(reportPersistence, sessionId, priority);
}
reportPersistence.finalizeReports("skippedSession", 0L);
final List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
assertEquals(4, finalizedReports.size());
for (CrashlyticsReportWithSessionId finalizedReport : finalizedReports) {
assertTrue(finalizedReport.getReport().getSession().getIdentifier().contains("high"));
}
}
use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method testPersistReportWithAnrEvent.
public void testPersistReportWithAnrEvent() throws IOException {
reportPersistence = new CrashlyticsReportPersistence(fileStore, createSettingsProviderMock(VERY_LARGE_UPPER_LIMIT, 4));
final String sessionId = "testSession";
final CrashlyticsReport testReport = makeTestReport(sessionId);
final Event testEvent = makeTestAnrEvent();
reportPersistence.persistReport(testReport);
reportPersistence.persistEvent(testEvent, sessionId, true);
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(1, finalizedReport.getSession().getEvents().size());
}
use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method testFinalizeReports_capsOldestSessionsFirst.
public void testFinalizeReports_capsOldestSessionsFirst() throws IOException {
DecimalFormat format = new DecimalFormat("00");
for (int i = 0; i < 16; i++) {
persistReportWithEvent(reportPersistence, "testSession" + format.format(i), true);
}
final long endedAt = System.currentTimeMillis();
reportPersistence.finalizeReports("skippedSession", endedAt);
final List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
assertEquals(8, finalizedReports.size());
List<String> reportIdentifiers = new ArrayList<>();
for (CrashlyticsReportWithSessionId finalizedReport : finalizedReports) {
reportIdentifiers.add(finalizedReport.getSessionId());
}
List<String> expectedSessions = Arrays.asList("testSession12", "testSession13", "testSession14", "testSession15");
List<String> unexpectedSessions = Arrays.asList("testSession4", "testSession5", "testSession6", "testSession7");
assertTrue(reportIdentifiers.containsAll(expectedSessions));
for (String unexpectedSession : unexpectedSessions) {
assertFalse(reportIdentifiers.contains(unexpectedSession));
}
}
use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId in project firebase-android-sdk by firebase.
the class DataTransportCrashlyticsReportSenderTest method testSendReportsFailure.
@Test
public void testSendReportsFailure() throws Exception {
final Exception ex = new Exception("fail");
doAnswer(callbackAnswer(ex)).when(mockTransport).schedule(any(), any());
final CrashlyticsReportWithSessionId report1 = mockReportWithSessionId();
final CrashlyticsReportWithSessionId report2 = mockReportWithSessionId();
final Task<CrashlyticsReportWithSessionId> send1 = reportSender.enqueueReport(report1, false);
final Task<CrashlyticsReportWithSessionId> send2 = reportSender.enqueueReport(report2, false);
try {
// give time to process queue
Thread.sleep(2_000);
Tasks.await(send1);
Tasks.await(send2);
} catch (ExecutionException e) {
// Allow this to fall through
}
assertFalse(send1.isSuccessful());
assertEquals(ex, send1.getException());
assertFalse(send2.isSuccessful());
assertEquals(ex, send2.getException());
}
use of com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId 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;
}
Aggregations