use of com.microsoft.azure.mobile.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.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);
}
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method sdkConfiguredBetweenPauseAndResume.
@Test
public void sdkConfiguredBetweenPauseAndResume() {
/* Pause application before we saw the first resume event (integration problem). We are handling that gracefully though. */
mSessionTracker.onActivityPaused();
/* Application is in background, send a log, verify decoration. */
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);
}
/* Verify session reused for second log. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* No usage from background for a long time: new session. */
{
spendTime(30000);
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);
}
/* App comes to foreground and sends a log, we were in background for a long time but we sent a log recently, still session. */
{
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* We are in foreground, even after timeout a log is still in session. */
{
spendTime(30000);
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.azure.mobile.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method disableAutomaticPageTracking.
@Test
public void disableAutomaticPageTracking() {
Analytics analytics = Analytics.getInstance();
assertTrue(Analytics.isAutoPageTrackingEnabled());
Analytics.setAutoPageTrackingEnabled(false);
assertFalse(Analytics.isAutoPageTrackingEnabled());
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
analytics.onActivityResumed(new MyActivity());
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof StartSessionLog;
}
}), anyString());
verify(channel, never()).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object argument) {
return argument instanceof PageLog;
}
}), anyString());
Analytics.setAutoPageTrackingEnabled(true);
assertTrue(Analytics.isAutoPageTrackingEnabled());
analytics.onActivityResumed(new SomeScreen());
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return "SomeScreen".equals(pageLog.getName());
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.StartSessionLog 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.azure.mobile.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method longSessionStartingFromBackground.
@Test
public void longSessionStartingFromBackground() {
/* Application is in background, send a log, verify decoration. */
UUID firstSid;
long firstSessionTime = mMockTime;
UUID expectedSid;
StartSessionLog expectedStartSessionLog = new StartSessionLog();
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotNull(log.getSid());
firstSid = expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Verify session reused for second log. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* No usage from background for a long time: new session. */
{
spendTime(30000);
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);
}
/* App comes to foreground and sends a log, still session. */
{
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* We are in foreground, even after timeout a log is still in session. */
{
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Switch to another activity and send a log, still session. */
{
spendTime(2);
mSessionTracker.onActivityPaused();
spendTime(2);
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* We are in foreground, even after timeout a log is still in session. */
{
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a short time and send log: still in session. */
{
spendTime(2);
mSessionTracker.onActivityPaused();
spendTime(2);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a long time but correlating a log to first session: should not trigger new session. */
{
Log log = newEvent();
log.setToffset(firstSessionTime + 20);
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(firstSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a long time and coming back to foreground: new session. */
{
spendTime(30000);
mSessionTracker.onActivityResumed();
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);
}
/* Background for a long time sending a log: new session. */
{
mSessionTracker.onActivityPaused();
spendTime(30000);
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);
}
}
Aggregations