use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method analyticsListener.
@Test
public void analyticsListener() throws IOException, ClassNotFoundException {
AnalyticsListener listener = mock(AnalyticsListener.class);
Analytics.setListener(listener);
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
final ArgumentCaptor<Channel.GroupListener> captor = ArgumentCaptor.forClass(Channel.GroupListener.class);
verify(channel).addGroup(anyString(), anyInt(), anyLong(), anyInt(), captor.capture());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
captor.getValue().onBeforeSending((Log) invocation.getArguments()[0]);
captor.getValue().onSuccess((Log) invocation.getArguments()[0]);
captor.getValue().onFailure((Log) invocation.getArguments()[0], new Exception());
return null;
}
}).when(channel).enqueue(any(Log.class), anyString());
Analytics.trackEvent("name");
verify(listener).onBeforeSending(notNull(Log.class));
verify(listener).onSendingSucceeded(notNull(Log.class));
verify(listener).onSendingFailed(notNull(Log.class), notNull(Exception.class));
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method goBackgroundAndComeBackMuchLater.
@Test
public void goBackgroundAndComeBackMuchLater() {
/* Application is in foreground, send a log, verify decoration with a new session. */
mSessionTracker.onActivityResumed();
UUID expectedSid;
StartSessionLog expectedStartSessionLog = new StartSessionLog();
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotNull(log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Go background. */
spendTime(1);
mSessionTracker.onActivityPaused();
/* Come back after a long time. */
spendTime(30000);
mSessionTracker.onActivityResumed();
/* Send a log again: new session. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotEquals(expectedSid, log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* In total we sent only 2 session logs. */
verify(mChannel, times(2)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof StartSessionLog;
}
}), anyString());
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method stayOnFirstScreenForLong.
@Test
public void stayOnFirstScreenForLong() {
/* Application is in foreground, send a log, verify decoration with a new session. */
mSessionTracker.onActivityResumed();
UUID expectedSid;
StartSessionLog expectedStartSessionLog = new StartSessionLog();
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotNull(log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Wait a long time. */
spendTime(30000);
/* Go to another activity. */
mSessionTracker.onActivityPaused();
spendTime(2);
mSessionTracker.onActivityResumed();
/* Send a log again: session must be reused. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class CrashesAndroidTest method processingWithMinidump.
@Test
public void processingWithMinidump() throws Exception {
/* Simulate we have a minidump. */
File newMinidumpDirectory = ErrorLogHelper.getNewMinidumpDirectory();
File minidumpFile = new File(newMinidumpDirectory, "minidump.dmp");
StorageHelper.InternalStorage.write(minidumpFile, "mock minidump");
/* Set up crash listener. */
CrashesListener crashesListener = mock(CrashesListener.class);
when(crashesListener.shouldProcess(any(ErrorReport.class))).thenReturn(true);
when(crashesListener.shouldAwaitUserConfirmation()).thenReturn(true);
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("Hello", "hello.txt");
when(crashesListener.getErrorAttachments(any(ErrorReport.class))).thenReturn(Collections.singletonList(textAttachment));
startFresh(crashesListener);
/* Check last session error report. */
assertTrue(Crashes.hasCrashedInLastSession().get());
/* Wait U.I. thread callback (shouldAwaitUserConfirmation). */
final Semaphore semaphore = new Semaphore(0);
HandlerUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
semaphore.release();
}
});
semaphore.acquire();
/* Waiting user confirmation so no log sent yet. */
ArgumentMatcher<Log> matchCrashLog = new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object o) {
return o instanceof ManagedErrorLog;
}
};
verify(mChannel, never()).enqueue(argThat(matchCrashLog), anyString());
assertEquals(2, ErrorLogHelper.getErrorStorageDirectory().listFiles(mMinidumpFilter).length);
verify(crashesListener).shouldProcess(any(ErrorReport.class));
verify(crashesListener).shouldAwaitUserConfirmation();
verifyNoMoreInteractions(crashesListener);
/* Confirm to resume processing. */
final AtomicReference<Log> log = new AtomicReference<>();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
log.set((Log) invocationOnMock.getArguments()[0]);
return null;
}
}).when(mChannel).enqueue(argThat(matchCrashLog), anyString());
Crashes.notifyUserConfirmation(Crashes.SEND);
assertTrue(Crashes.isEnabled().get());
verify(mChannel).enqueue(argThat(matchCrashLog), anyString());
assertNotNull(log.get());
assertEquals(1, ErrorLogHelper.getErrorStorageDirectory().listFiles(mMinidumpFilter).length);
verify(crashesListener).getErrorAttachments(any(ErrorReport.class));
verifyNoMoreInteractions(crashesListener);
/* Verify automatic minidump attachment. */
verify(mChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
if (argument instanceof ErrorAttachmentLog) {
ErrorAttachmentLog log = (ErrorAttachmentLog) argument;
return "application/octet-stream".equals(log.getContentType()) && "minidump.dmp".equals(log.getFileName());
}
return false;
}
}), anyString());
/* Verify custom text attachment. */
verify(mChannel).enqueue(eq(textAttachment), anyString());
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class ErrorModelTest method checkSerialization.
private static void checkSerialization(Log log, LogSerializer serializer) throws JSONException {
String payload = serializer.serializeLog(log);
Log deSerializedLog = serializer.deserializeLog(payload);
checkEquals(log, deSerializedLog);
}
Aggregations