Search in sources :

Example 36 with Log

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));
}
Also used : Context(android.content.Context) AnalyticsListener(com.microsoft.appcenter.analytics.channel.AnalyticsListener) PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) Channel(com.microsoft.appcenter.channel.Channel) IOException(java.io.IOException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Log

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());
}
Also used : StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) ArgumentMatcher(org.mockito.ArgumentMatcher) UUID(java.util.UUID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with Log

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);
    }
}
Also used : StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) UUID(java.util.UUID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with Log

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());
}
Also used : ErrorAttachmentLog(com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Log(com.microsoft.appcenter.ingestion.models.Log) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) ErrorReport(com.microsoft.appcenter.crashes.model.ErrorReport) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatcher(org.mockito.ArgumentMatcher) ErrorAttachmentLog(com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog) File(java.io.File) Test(org.junit.Test)

Example 40 with Log

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);
}
Also used : Log(com.microsoft.appcenter.ingestion.models.Log)

Aggregations

Log (com.microsoft.appcenter.ingestion.models.Log)64 Test (org.junit.Test)50 ArrayList (java.util.ArrayList)27 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)25 Context (android.content.Context)24 UUID (java.util.UUID)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)20 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)15 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)15 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)14 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)14 Channel (com.microsoft.appcenter.channel.Channel)12 Persistence (com.microsoft.appcenter.persistence.Persistence)12 HashMap (java.util.HashMap)11 Matchers.anyString (org.mockito.Matchers.anyString)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 Date (java.util.Date)10 MediumTest (android.support.test.filters.MediumTest)9 IngestionHttp (com.microsoft.appcenter.ingestion.IngestionHttp)9