Search in sources :

Example 6 with CrashlyticsReportWithSessionId

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"));
    }
}
Also used : CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)

Example 7 with CrashlyticsReportWithSessionId

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());
}
Also used : CrashlyticsReport(com.google.firebase.crashlytics.internal.model.CrashlyticsReport) Event(com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)

Example 8 with CrashlyticsReportWithSessionId

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));
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)

Example 9 with CrashlyticsReportWithSessionId

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());
}
Also used : CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) ExecutionException(java.util.concurrent.ExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 10 with CrashlyticsReportWithSessionId

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;
}
Also used : CrashlyticsReport(com.google.firebase.crashlytics.internal.model.CrashlyticsReport) ArrayList(java.util.ArrayList) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) IOException(java.io.IOException) File(java.io.File) NonNull(androidx.annotation.NonNull)

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