use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsSerializerTest method someBatch.
@Test
public void someBatch() throws JSONException {
LogContainer expectedContainer = new LogContainer();
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion("1.2.3");
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion("4.0.3");
device.setOsBuild("LMY47X");
device.setOsApiLevel(15);
device.setLocale("en_US");
device.setTimeZoneOffset(120);
device.setScreenSize("800x600");
device.setAppVersion("3.2.1");
device.setAppBuild("42");
List<Log> logs = new ArrayList<>();
{
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setTimestamp(new Date());
logs.add(startSessionLog);
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("click");
eventLog.setProperties(new HashMap<String, String>() {
{
put("x", "1");
put("y", "2");
}
});
logs.add(eventLog);
}
{
List<TypedProperty> properties = new ArrayList<>();
BooleanTypedProperty bp = new BooleanTypedProperty();
bp.setName("n1");
bp.setValue(true);
properties.add(bp);
DateTimeTypedProperty dtp = new DateTimeTypedProperty();
dtp.setName("n2");
dtp.setValue(new Date());
properties.add(dtp);
DoubleTypedProperty dp = new DoubleTypedProperty();
dp.setName("n3");
dp.setValue(10);
properties.add(dp);
LongTypedProperty lp = new LongTypedProperty();
lp.setName("n4");
lp.setValue(10000000000L);
properties.add(lp);
StringTypedProperty sp = new StringTypedProperty();
sp.setName("n5");
sp.setValue("value");
properties.add(sp);
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUID.randomUUID());
eventLog.setName("event");
eventLog.setTypedProperties(properties);
logs.add(eventLog);
}
UUID sid = UUID.randomUUID();
for (Log log : logs) {
log.setSid(sid);
log.setDevice(device);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
android.util.Log.v(TAG, payload);
LogContainer actualContainer = serializer.deserializeContainer(payload, null);
Assert.assertEquals(expectedContainer, actualContainer);
}
use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class SessionTracker method sendStartSession.
/**
* Generate session id and send start session log.
*/
private void sendStartSession() {
mSid = UUID.randomUUID();
/* Update session storage. */
SessionContext.getInstance().addSession(mSid);
/* Enqueue a start session log. */
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setSid(mSid);
mChannel.enqueue(startSessionLog, mGroupName, Flags.DEFAULTS);
}
use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method setManualSessionTracker.
@Test
public void setManualSessionTracker() {
/* Set manual session tracker. */
Analytics.enableManualSessionTracker();
/* Before start it does not work to change state, it's disabled. */
Analytics analytics = Analytics.getInstance();
/* Prepare channel. */
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), channel, "", null, true);
/* Verify that start session log wasn't sent. */
ArgumentCaptor<StartSessionLog> log = ArgumentCaptor.forClass(StartSessionLog.class);
verify(channel, never()).enqueue(log.capture(), eq(analytics.getGroupName()), anyInt());
/* Verify that start session log was sent. */
Analytics.startSession();
verify(channel).enqueue(log.capture(), eq(analytics.getGroupName()), anyInt());
assertNotNull(log.getValue());
assertNotNull(log.getValue().getSid());
}
use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project AppCenter-SDK-Android by Microsoft.
the class AnalyticsSerializerTest method someBatch.
@Test
public void someBatch() throws JSONException {
LogContainer expectedContainer = new LogContainer();
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion("1.2.3");
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion("4.0.3");
device.setOsBuild("LMY47X");
device.setOsApiLevel(15);
device.setLocale("en_US");
device.setTimeZoneOffset(120);
device.setScreenSize("800x600");
device.setAppVersion("3.2.1");
device.setAppBuild("42");
List<Log> logs = new ArrayList<>();
{
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setTimestamp(new Date());
logs.add(startSessionLog);
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("click");
eventLog.setProperties(new HashMap<String, String>() {
{
put("x", "1");
put("y", "2");
}
});
logs.add(eventLog);
}
UUID sid = UUIDUtils.randomUUID();
for (Log log : logs) {
log.setSid(sid);
log.setDevice(device);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
android.util.Log.v(TAG, payload);
LogContainer actualContainer = serializer.deserializeContainer(payload);
Assert.assertEquals(expectedContainer, actualContainer);
}
use of com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog in project AppCenter-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);
}
}
Aggregations