Skip to content

Commit

Permalink
Merge branch 'release/2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBenny committed Jul 16, 2021
2 parents fbd4320 + 998dc95 commit 46ff630
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 75 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
@@ -1,4 +1,10 @@

Version 2.2.0 (2021-07-16)
--------------------------
Set amended v_tracker indicating wrapper tracker version (#465)
Remove bufferOption tests (#464)
Set application install timestamp on device timestamp field (#462)

Version 2.1.1 (2021-06-24)
--------------------------
Fix Gdpr context being tracked without enabling it (#457)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.1.1
2.2.0
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -17,7 +17,7 @@ buildscript {

subprojects {
group = 'com.snowplowanalytics'
version = '2.1.1'
version = '2.2.0'
repositories {
google()
maven {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -30,7 +30,7 @@ systemProp.org.gradle.internal.http.socketTimeout=120000
SONATYPE_STAGING_PROFILE=comsnowplowanalytics
GROUP=com.snowplowanalytics
POM_ARTIFACT_ID=snowplow-android-tracker
VERSION_NAME=2.1.1
VERSION_NAME=2.2.0

POM_NAME=snowplow-android-tracker
POM_PACKAGING=aar
Expand Down
@@ -0,0 +1,79 @@
package com.snowplowanalytics.snowplow.event;

import android.content.Context;
import android.test.AndroidTestCase;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.snowplowanalytics.snowplow.Snowplow;
import com.snowplowanalytics.snowplow.configuration.EmitterConfiguration;
import com.snowplowanalytics.snowplow.configuration.NetworkConfiguration;
import com.snowplowanalytics.snowplow.configuration.TrackerConfiguration;
import com.snowplowanalytics.snowplow.controller.TrackerController;
import com.snowplowanalytics.snowplow.emitter.EmitterEvent;
import com.snowplowanalytics.snowplow.internal.constants.TrackerConstants;
import com.snowplowanalytics.snowplow.internal.emitter.Executor;
import com.snowplowanalytics.snowplow.network.HttpMethod;
import com.snowplowanalytics.snowplow.payload.Payload;
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
import com.snowplowanalytics.snowplow.tracker.MockEventStore;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
public class ApplicationInstallTest extends AndroidTestCase {

@Before
public void setUp() throws Exception {
ExecutorService es = Executor.shutdown();
if (es != null) {
es.awaitTermination(60, TimeUnit.SECONDS);
}
}

// Tests

@Test
public void testApplicationInstall() throws InterruptedException {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();

// Prepare application install event
SelfDescribingJson installEvent = new SelfDescribingJson(TrackerConstants.SCHEMA_APPLICATION_INSTALL);
SelfDescribing event = new SelfDescribing(installEvent);
long currentTimestamp = 12345L;
event.trueTimestamp = currentTimestamp;

// Setup tracker
TrackerConfiguration trackerConfiguration = new TrackerConfiguration("appId")
.base64encoding(false)
.installAutotracking(false);
MockEventStore eventStore = new MockEventStore();
NetworkConfiguration networkConfiguration = new NetworkConfiguration("fake-url", HttpMethod.POST);
EmitterConfiguration emitterConfiguration = new EmitterConfiguration()
.eventStore(eventStore)
.threadPoolSize(10);
TrackerController trackerController = Snowplow.createTracker(context, "namespace", networkConfiguration, trackerConfiguration, emitterConfiguration);

// Track event
trackerController.track(event);
for (int i=0; eventStore.getSize() < 1 && i < 10; i++) {
Thread.sleep(1000);
}
List<EmitterEvent> events = eventStore.getEmittableEvents(10);
eventStore.removeAllEvents();
assertEquals(1, events.size());
Payload payload = events.get(0).payload;

// Check timestamp field
String deviceTimestamp = (String)payload.getMap().get("dtm");
String expected = Long.toString(currentTimestamp);
assertEquals(expected, deviceTimestamp);
}
}
Expand Up @@ -23,6 +23,7 @@
import com.snowplowanalytics.snowplow.network.Protocol;
import com.snowplowanalytics.snowplow.payload.Payload;
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
import com.snowplowanalytics.snowplow.tracker.BuildConfig;
import com.snowplowanalytics.snowplow.tracker.MockEventStore;
import com.snowplowanalytics.snowplow.util.Basis;
import com.snowplowanalytics.snowplow.util.TimeMeasure;
Expand Down Expand Up @@ -138,6 +139,38 @@ public void emitterConfiguration() throws InterruptedException {
assertEquals(1, emitterController.getEmitRange());
}
*/

@Test
public void trackerVersionSuffix() throws InterruptedException {
TrackerConfiguration trackerConfiguration = new TrackerConfiguration("appId")
.base64encoding(false)
.installAutotracking(false)
.trackerVersionSuffix("test With Space 1-2-3");

// Setup tracker
MockEventStore eventStore = new MockEventStore();
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
NetworkConfiguration networkConfiguration = new NetworkConfiguration("fake-url", HttpMethod.POST);
EmitterConfiguration emitterConfiguration = new EmitterConfiguration()
.eventStore(eventStore)
.threadPoolSize(10);
TrackerController trackerController = Snowplow.createTracker(context, "namespace", networkConfiguration, trackerConfiguration, emitterConfiguration);

// Track fake event
trackerController.track(new Structured("category", "action"));
for (int i = 0; eventStore.getSize() < 1 && i < 10; i++) {
Thread.sleep(1000);
}
List<EmitterEvent> events = eventStore.getEmittableEvents(10);
eventStore.removeAllEvents();
assertEquals(1, events.size());
Payload payload = events.get(0).payload;

// Check v_tracker field
String versionTracker = (String) payload.getMap().get("tv");
String expected = BuildConfig.TRACKER_LABEL + " testWithSpace1-2-3";
assertEquals(expected, versionTracker);
}

@Test
public void gdprConfiguration() throws InterruptedException {
Expand Down
Expand Up @@ -347,76 +347,6 @@ public void testEmitSinglePostEventWithSuccess() throws InterruptedException {
emitter.flush();
}

public void testEmitEventsPostAsGroup() throws InterruptedException {
MockNetworkConnection networkConnection = new MockNetworkConnection(POST, false);
Emitter emitter = getEmitter(networkConnection, DefaultGroup);

List<Payload> payloads = generatePayloads(15);
for (int i = 0; i < 14; i++) {
emitter.add(payloads.get(i));
}

for (int i = 0; i < 10 && (networkConnection.sendingCount() < 1 || emitter.getEmitterStatus()); i++) {
Thread.sleep(600);
}

assertEquals(14, emitter.getEventStore().getSize());
networkConnection.successfulConnection = true;
int prevSendingCount = networkConnection.sendingCount();
emitter.add(payloads.get(14));

for (int i = 0; i < 10 && (networkConnection.sendingCount() - prevSendingCount < 1 || emitter.getEmitterStatus()); i++) {
Thread.sleep(600);
}

assertEquals(0, emitter.getEventStore().getSize());
int totEvents = 0;
boolean areGrouped = false;
List<List<RequestResult>> prevResults = networkConnection.previousResults.subList(prevSendingCount, networkConnection.previousResults.size());
for (List<RequestResult> results : prevResults) {
for (RequestResult result : results) {
assertTrue(result.getSuccess());
int ids = result.getEventIds().size();
totEvents += ids;
areGrouped = areGrouped || ids > 1;
}
}
assertEquals(15, totEvents);
assertTrue(areGrouped);

emitter.flush();
}

public void testEmitOversizeEventsPostAsGroup() throws InterruptedException {
Logger.updateLogLevel(LogLevel.VERBOSE);

MockNetworkConnection networkConnection = new MockNetworkConnection(POST, false);
Emitter emitter = getEmitterBuilder(networkConnection, DefaultGroup)
.byteLimitPost(5)
.build();

List<Payload> payloads = generatePayloads(15);
for (int i = 0; i < 14; i++) {
emitter.add(payloads.get(i));
}

for (int i = 0; i < 10 && (networkConnection.sendingCount() < 1 || emitter.getEmitterStatus()); i++) {
Thread.sleep(600);
}

assertEquals(0, emitter.getEventStore().getSize());
networkConnection.successfulConnection = true;
emitter.add(payloads.get(14));

for (int i = 0; i < 10 && (networkConnection.sendingCount() < 2 || emitter.getEmitterStatus()); i++) {
Thread.sleep(600);
}

assertEquals(0, emitter.getEventStore().getSize());

emitter.flush();
}

// Emitter Builder

public Emitter getEmitter(NetworkConnection networkConnection, BufferOption option) {
Expand Down
Expand Up @@ -64,18 +64,21 @@ public long getSize() {
public List<EmitterEvent> getEmittableEvents(int queryLimit) {
synchronized (this) {
List<Long> eventIds = new ArrayList<>();
List<String> eventPayloads = new ArrayList<>();
List<EmitterEvent> events = new ArrayList<>();
for (Map.Entry<Long, Payload> entry : db.entrySet()) {
Payload payloadCopy = new TrackerPayload();
payloadCopy.addMap(entry.getValue().getMap());
EmitterEvent event = new EmitterEvent(payloadCopy, entry.getKey());
eventIds.add(event.eventId);
eventPayloads.add(payloadCopy.getMap().toString());
events.add(event);
}
if (queryLimit < events.size()) {
events = events.subList(0, queryLimit);
}
Logger.v("MockEventStore", "getEmittableEvents: %s", eventIds);
Logger.v("MockEventStore", "getEmittableEvents ids: %s", eventIds);
Logger.v("MockEventStore", "getEmittableEvents payloads: %s", eventPayloads);
return events;
}
}
Expand Down
Expand Up @@ -88,6 +88,11 @@ public class TrackerConfiguration implements TrackerConfigurationInterface, Conf
* @see #diagnosticAutotracking(boolean)
*/
public boolean diagnosticAutotracking;
/**
* @see #trackerVersionSuffix(String)
*/
@Nullable
public String trackerVersionSuffix;

// Getters and Setters

Expand Down Expand Up @@ -245,6 +250,17 @@ public void setDiagnosticAutotracking(boolean diagnosticAutotracking) {
this.diagnosticAutotracking = diagnosticAutotracking;
}

@Override
@Nullable
public String getTrackerVersionSuffix() {
return trackerVersionSuffix;
}

@Override
public void setTrackerVersionSuffix(@Nullable String trackerVersionSuffix) {
this.trackerVersionSuffix = trackerVersionSuffix;
}

// Constructors

/**
Expand Down Expand Up @@ -428,6 +444,16 @@ public TrackerConfiguration diagnosticAutotracking(boolean diagnosticAutotrackin
return this;
}

/**
* Decorate the v_tracker field in the tracker protocol.
* @note Do not use. Internal use only.
*/
@NonNull
public TrackerConfiguration trackerVersionSuffix(@Nullable String trackerVersionSuffix) {
this.trackerVersionSuffix = trackerVersionSuffix;
return this;
}

// Copyable

@NonNull
Expand All @@ -450,6 +476,7 @@ public Configuration copy() {
copy.installAutotracking = installAutotracking;
copy.exceptionAutotracking = exceptionAutotracking;
copy.diagnosticAutotracking = diagnosticAutotracking;
copy.trackerVersionSuffix = trackerVersionSuffix;
return copy;
}

Expand Down
Expand Up @@ -378,6 +378,7 @@ private Tracker makeTracker() {
SessionConfigurationInterface sessionConfig = getSessionConfigurationUpdate();
Tracker.TrackerBuilder builder = new Tracker.TrackerBuilder(emitter, namespace, trackerConfig.getAppId(), context)
.subject(subject)
.trackerVersionSuffix(trackerConfig.getTrackerVersionSuffix())
.base64(trackerConfig.isBase64encoding())
.level(trackerConfig.getLogLevel())
.loggerDelegate(trackerConfig.getLoggerDelegate())
Expand Down

0 comments on commit 46ff630

Please sign in to comment.