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));
}
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());
}
Aggregations