Search in sources :

Example 21 with StartSessionLog

use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog 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.onPreparingLog(log, TEST_GROUP);
        mSessionTracker.onPreparingLog(expectedStartSessionLog, TEST_GROUP);
        assertNotNull(log.getSid());
        expectedSid = log.getSid();
        expectedStartSessionLog.setSid(expectedSid);
        verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP, DEFAULTS);
    }
    /* 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.onPreparingLog(log, TEST_GROUP);
        mSessionTracker.onPreparingLog(expectedStartSessionLog, TEST_GROUP);
        assertNotEquals(expectedSid, log.getSid());
        expectedSid = log.getSid();
        expectedStartSessionLog.setSid(expectedSid);
        verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP, DEFAULTS);
    }
    /* 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(), eq(DEFAULTS));
}
Also used : StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) 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 22 with StartSessionLog

use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.

the class SessionTrackerTest method startSessionWithoutLogs.

@Test
public void startSessionWithoutLogs() {
    final AtomicReference<StartSessionLog> startSessionLog = new AtomicReference<>();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            startSessionLog.set((StartSessionLog) invocation.getArguments()[0]);
            return null;
        }
    }).when(mChannel).enqueue(notNull(StartSessionLog.class), eq(TEST_GROUP), anyInt());
    /* Go foreground, start session is sent. */
    mSessionTracker.onActivityResumed();
    verify(mChannel, times(1)).enqueue(notNull(StartSessionLog.class), eq(TEST_GROUP), eq(DEFAULTS));
    assertNotNull(startSessionLog.get());
    UUID sid = startSessionLog.get().getSid();
    assertNotNull(sid);
    /* Change screen after a long time, session reused. */
    spendTime(30000);
    mSessionTracker.onActivityPaused();
    spendTime(1);
    mSessionTracker.onActivityResumed();
    verify(mChannel, times(1)).enqueue(notNull(StartSessionLog.class), eq(TEST_GROUP), eq(DEFAULTS));
    /* Go background and come back after timeout, second session. */
    spendTime(1);
    mSessionTracker.onActivityPaused();
    spendTime(30000);
    mSessionTracker.onActivityResumed();
    verify(mChannel, times(2)).enqueue(notNull(StartSessionLog.class), eq(TEST_GROUP), eq(DEFAULTS));
    assertNotEquals(sid, startSessionLog.get().getSid());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)22 Test (org.junit.Test)17 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)12 Log (com.microsoft.appcenter.ingestion.models.Log)12 UUID (java.util.UUID)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 StartServiceLog (com.microsoft.appcenter.ingestion.models.StartServiceLog)10 PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)6 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)6 Date (java.util.Date)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Context (android.content.Context)5 Channel (com.microsoft.appcenter.channel.Channel)5 UserIdContext (com.microsoft.appcenter.utils.context.UserIdContext)3 SessionContext (com.microsoft.appcenter.SessionContext)2 EventLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.EventLogFactory)2 PageLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.PageLogFactory)2 StartSessionLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.StartSessionLogFactory)2 Device (com.microsoft.appcenter.ingestion.models.Device)2 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)2