use of com.microsoft.appcenter.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesAndroidTest method getLastSessionCrashReportStackOverflowException.
@Test
public void getLastSessionCrashReportStackOverflowException() throws Exception {
/* Null before start. */
Crashes.unsetInstance();
assertNull(Crashes.getLastSessionCrashReport().get());
assertFalse(Crashes.hasCrashedInLastSession().get());
/* Crash on 1st process. */
Thread.UncaughtExceptionHandler uncaughtExceptionHandler = mock(Thread.UncaughtExceptionHandler.class);
Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
startFresh(null);
assertNull(Crashes.getLastSessionCrashReport().get());
assertFalse(Crashes.hasCrashedInLastSession().get());
final Error exception = generateStackOverflowError();
assertTrue(exception.getStackTrace().length > ErrorLogHelper.FRAME_LIMIT);
final Thread thread = new Thread() {
@Override
public void run() {
throw exception;
}
};
thread.start();
thread.join();
/* Get last session crash on 2nd process. */
startFresh(null);
ErrorReport errorReport = Crashes.getLastSessionCrashReport().get();
assertNotNull(errorReport);
assertNotNull(errorReport.getStackTrace());
assertTrue(Crashes.hasCrashedInLastSession().get());
}
use of com.microsoft.appcenter.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesAndroidTest method getLastSessionCrashReportNative.
@Test
public void getLastSessionCrashReportNative() throws Exception {
/* Null before start. */
Crashes.unsetInstance();
assertNull(Crashes.getLastSessionCrashReport().get());
assertFalse(Crashes.hasCrashedInLastSession().get());
assertNull(Crashes.getMinidumpDirectory().get());
/* Simulate we have minidump from previous run. */
File minidumpDirectory = getNewMinidumpDirectory();
File sNewMinidumpDirectory = new File(minidumpDirectory, UUID.randomUUID().toString());
FileManager.mkdir(sNewMinidumpDirectory.getPath());
/* Simulate we have a minidump. */
File newMinidumpDirectory = ErrorLogHelper.getNewMinidumpSubfolder();
File minidumpFile = new File(newMinidumpDirectory, "minidump.dmp");
FileManager.write(minidumpFile, "{\"DEVICE_INFO\":\"{mock minidump}\"}");
/* Start crashes now. */
startFresh(null);
/* We can access directory now. */
assertEquals(newMinidumpDirectory.getAbsolutePath(), Crashes.getMinidumpDirectory().get());
ErrorReport errorReport = Crashes.getLastSessionCrashReport().get();
assertNotNull(errorReport);
assertTrue(Crashes.hasCrashedInLastSession().get());
assertNotNull(errorReport.getStackTrace());
/* File has been deleted. */
assertFalse(minidumpFile.exists());
/* After restart, it's processed. */
Crashes.unsetInstance();
startFresh(null);
assertNull(Crashes.getLastSessionCrashReport().get());
assertFalse(Crashes.hasCrashedInLastSession().get());
}
use of com.microsoft.appcenter.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class WrapperSdkExceptionManagerAndroidTest method buildHandledErrorReport.
@Test
public void buildHandledErrorReport() {
/* If we start the Crashes sdk. */
long beforeStartTime = System.currentTimeMillis();
startFresh();
long afterStartTime = System.currentTimeMillis();
/* When we build an error report for an handled error. */
long beforeBuildTime = System.currentTimeMillis();
String errorReportId = UUID.randomUUID().toString();
ErrorReport errorReport = WrapperSdkExceptionManager.buildHandledErrorReport(sApplication, errorReportId);
long afterBuildTime = System.currentTimeMillis();
/* Then it contains the following properties. */
assertNotNull(errorReport);
assertEquals(errorReportId, errorReport.getId());
assertNotNull(errorReport.getDevice());
assertNotNull(errorReport.getAppErrorTime());
assertNotNull(errorReport.getAppStartTime());
assertNull(errorReport.getStackTrace());
assertNull(errorReport.getThreadName());
/* Check start time is consistent. */
assertTrue(errorReport.getAppStartTime().getTime() >= beforeStartTime);
assertTrue(errorReport.getAppStartTime().getTime() <= afterStartTime);
/* Check error time is consistent. */
assertTrue(errorReport.getAppErrorTime().getTime() >= beforeBuildTime);
assertTrue(errorReport.getAppErrorTime().getTime() <= afterBuildTime);
/* Check device info is cached. */
ErrorReport errorReport2 = WrapperSdkExceptionManager.buildHandledErrorReport(sApplication, UUID.randomUUID().toString());
assertSame(errorReport.getDevice(), errorReport2.getDevice());
}
use of com.microsoft.appcenter.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method checkStacktraceWithLegacyThrowableFile.
@Test
public void checkStacktraceWithLegacyThrowableFile() throws Exception {
String expectedStacktrace = "type: message\n" + " ClassName.MethodName(FileName:1)";
/* Mock FileManager call. */
when(FileManager.read(any(File.class))).thenReturn(expectedStacktrace);
/* Create throwable file. */
UUID logId = UUID.randomUUID();
String throwableFileName = logId + ErrorLogHelper.THROWABLE_FILE_EXTENSION;
File errorStorageDirectory = mTemporaryFolder.newFolder("error");
ErrorLogHelper.setErrorLogDirectory(errorStorageDirectory);
File throwableFile = new File(errorStorageDirectory, throwableFileName);
assertTrue(throwableFile.createNewFile());
/* Write file content. */
BufferedWriter writer = new BufferedWriter(new FileWriter(throwableFile));
writer.write(expectedStacktrace);
writer.close();
/* Mock log. */
ManagedErrorLog mockLog = new ManagedErrorLog();
mockLog.setId(logId);
mockLog.setErrorThreadName("Thread name");
mockLog.setAppLaunchTimestamp(new Date());
mockLog.setTimestamp(new Date());
mockLog.setDevice(new Device());
/* Build error report. */
Crashes crashes = Mockito.spy(Crashes.getInstance());
ErrorReport report = crashes.buildErrorReport(mockLog);
/* Verify. */
assertEquals(expectedStacktrace, report.getStackTrace());
verify(crashes, never()).buildStackTrace(any(com.microsoft.appcenter.crashes.ingestion.models.Exception.class));
verifyStatic();
FileManager.read(any(File.class));
}
use of com.microsoft.appcenter.crashes.model.ErrorReport in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method buildErrorReport.
@Test
public void buildErrorReport() {
/* Mock and set exception data. */
com.microsoft.appcenter.crashes.ingestion.models.Exception mockException = mock(com.microsoft.appcenter.crashes.ingestion.models.Exception.class);
when(mockException.getType()).thenReturn("type");
when(mockException.getMessage()).thenReturn("message");
mErrorLog.setException(mockException);
mErrorLog.setDevice(mock(Device.class));
ErrorReport errorReport = ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE);
mockStatic(ErrorLogHelper.class);
File throwableFile = mock(File.class);
when(throwableFile.length()).thenReturn(1L);
when(ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE)).thenReturn(errorReport);
when(FileManager.read(any(File.class))).thenReturn(STACK_TRACE);
Crashes crashes = Crashes.getInstance();
ErrorReport report = crashes.buildErrorReport(mErrorLog);
assertErrorEquals(mErrorLog, report);
verifyStatic();
ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE);
/* Verify the caching. */
assertEquals(report, crashes.buildErrorReport(mErrorLog));
verifyStatic();
ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE);
mErrorLog.setId(UUID.randomUUID());
report = crashes.buildErrorReport(mErrorLog);
assertNotNull(report);
}
Aggregations