use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class Crashes method queueException.
/**
* Send an exception.
*
* @param throwable An exception.
*/
private synchronized void queueException(@NonNull final Throwable throwable) {
if (isInactive())
return;
ManagedErrorLog errorLog = ErrorLogHelper.createErrorLog(mContext, Thread.currentThread(), throwable, Thread.getAllStackTraces(), getInitializeTimestamp(), false);
mChannel.enqueue(errorLog, ERROR_GROUP);
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class CrashesAndroidTest method wrapperSdkOverrideLog.
@Test
public void wrapperSdkOverrideLog() throws InterruptedException {
Thread.UncaughtExceptionHandler uncaughtExceptionHandler = mock(Thread.UncaughtExceptionHandler.class);
Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
Channel channel = mock(Channel.class);
Crashes.getInstance().onStarted(sContext, "", channel);
Crashes.WrapperSdkListener wrapperSdkListener = mock(Crashes.WrapperSdkListener.class);
Crashes.getInstance().setWrapperSdkListener(wrapperSdkListener);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ManagedErrorLog errorLog = (ManagedErrorLog) invocationOnMock.getArguments()[0];
errorLog.setErrorThreadName("ReplacedErrorThreadName");
WrapperSdkExceptionManager.saveWrapperSdkErrorLog(errorLog);
return null;
}
}).when(wrapperSdkListener).onCrashCaptured(notNull(ManagedErrorLog.class));
final RuntimeException exception = new RuntimeException("mock");
final Thread thread = new Thread() {
@Override
public void run() {
throw exception;
}
};
thread.start();
thread.join();
verify(wrapperSdkListener).onCrashCaptured(notNull(ManagedErrorLog.class));
Crashes.unsetInstance();
Crashes.getInstance().onStarted(sContext, "", channel);
waitForCrashesHandlerTasksToComplete();
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
@Override
public void onResult(ErrorReport errorReport) {
assertNotNull(errorReport);
assertEquals("ReplacedErrorThreadName", errorReport.getThreadName());
}
});
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method trackException.
@Test
public void trackException() {
/* Track exception test. */
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
crashes.onStarted(mock(Context.class), "", mockChannel);
Crashes.trackException(EXCEPTION);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof ManagedErrorLog && EXCEPTION.getMessage().equals(((ManagedErrorLog) item).getException().getMessage());
}
}), eq(crashes.getGroupName()));
ManagedErrorLog mockLog = mock(ManagedErrorLog.class);
when(mockLog.getFatal()).thenReturn(false);
CrashesListener mockListener = mock(CrashesListener.class);
crashes.setInstanceListener(mockListener);
/* Crashes callback test for trackException. */
crashes.getChannelListener().onBeforeSending(mockLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(mockLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(mockLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
ErrorAttachmentLog attachmentLog = mock(ErrorAttachmentLog.class);
crashes.getChannelListener().onBeforeSending(attachmentLog);
verify(mockListener, never()).onBeforeSending(any(ErrorReport.class));
crashes.getChannelListener().onSuccess(attachmentLog);
verify(mockListener, never()).onSendingSucceeded(any(ErrorReport.class));
crashes.getChannelListener().onFailure(attachmentLog, EXCEPTION);
verify(mockListener, never()).onSendingFailed(any(ErrorReport.class), eq(EXCEPTION));
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method saveWrapperSdkErrorLogIOException.
@Test
public void saveWrapperSdkErrorLogIOException() throws IOException, JSONException {
mockStatic(MobileCenterLog.class);
ManagedErrorLog errorLog = new ManagedErrorLog();
errorLog.setId(UUIDUtils.randomUUID());
mockStatic(StorageHelper.InternalStorage.class);
doThrow(new IOException()).when(StorageHelper.InternalStorage.class);
StorageHelper.InternalStorage.write(any(File.class), anyString());
LogSerializer logSerializer = mock(LogSerializer.class);
when(logSerializer.serializeLog(errorLog)).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
WrapperSdkExceptionManager.saveWrapperSdkErrorLog(errorLog);
verifyStatic();
MobileCenterLog.error(anyString(), anyString(), any(IOException.class));
}
use of com.microsoft.azure.mobile.crashes.ingestion.models.ManagedErrorLog in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method setWrapperSdkListener.
@Test
public void setWrapperSdkListener() {
mockStatic(ErrorLogHelper.class);
ManagedErrorLog errorLog = new ManagedErrorLog();
errorLog.setId(UUIDUtils.randomUUID());
when(ErrorLogHelper.createErrorLog(any(Context.class), any(Thread.class), any(Throwable.class), anyMapOf(Thread.class, StackTraceElement[].class), anyLong(), anyBoolean())).thenReturn(errorLog);
Crashes.getInstance().setLogSerializer(mock(LogSerializer.class));
Crashes.WrapperSdkListener wrapperSdkListener = mock(Crashes.WrapperSdkListener.class);
Crashes.getInstance().setWrapperSdkListener(wrapperSdkListener);
Crashes.getInstance().saveUncaughtException(Thread.currentThread(), new TestCrashException());
verify(wrapperSdkListener).onCrashCaptured(errorLog);
}
Aggregations