Commit ae867474 authored by Simon Chae's avatar Simon Chae Committed by Sebastian Kaspari
Browse files

Closes #1999: Add overloading constructor EventsMeasurement

Optional for filename to be configurable
parent a2609262
......@@ -36,12 +36,18 @@ public class EventsMeasurement extends TelemetryMeasurement {
private TelemetryConfiguration configuration;
private Logger logger;
private String filename;
public EventsMeasurement(TelemetryConfiguration configuration) {
this(configuration, "events");
}
public EventsMeasurement(TelemetryConfiguration configuration, String filename) {
super(FIELD_NAME);
this.configuration = configuration;
this.logger = new Logger("telemetry/events");
this.filename = filename;
}
public EventsMeasurement add(final TelemetryEvent event) {
......@@ -103,7 +109,7 @@ public class EventsMeasurement extends TelemetryMeasurement {
}
@VisibleForTesting File getEventFile() {
return new File(configuration.getDataDirectory(), "events" + VERSION);
return new File(configuration.getDataDirectory(), filename + VERSION);
}
private synchronized void saveEventToDisk(TelemetryEvent event) {
......
......@@ -40,7 +40,7 @@ public class TelemetryPocketEventPingBuilder extends TelemetryPingBuilder {
addMeasurement(new OperatingSystemVersionMeasurement());
addMeasurement(new CreatedTimestampMeasurement());
addMeasurement(new TimezoneOffsetMeasurement());
addMeasurement(eventsMeasurement = new EventsMeasurement(configuration));
addMeasurement(eventsMeasurement = new EventsMeasurement(configuration, "pocket-events"));
}
@Override
......
......@@ -508,7 +508,7 @@ public class TelemetryTest {
doReturn("ffffffff-0000-0000-ffff-ffffffffffff").when(eventPingBuilder).generateDocumentId();
final Telemetry telemetry = new Telemetry(configuration, storage, client, scheduler)
.addPingBuilder(eventPingBuilder).addPingBuilder(pocketPingBuilder);
.addPingBuilder(pocketPingBuilder).addPingBuilder(eventPingBuilder);
TelemetryHolder.set(telemetry);
......@@ -518,7 +518,7 @@ public class TelemetryTest {
assertNotNull(moPingBuilder);
pocketPingBuilder.getEventsMeasurement()
moPingBuilder.getEventsMeasurement()
.add(TelemetryEvent.create("action", "type", "search_bar"))
.add(TelemetryEvent.create("action", "type_query", "search_bar"))
.add(TelemetryEvent.create("action", "click", "erase_button"));
......@@ -531,10 +531,10 @@ public class TelemetryTest {
assertNotNull(poPingBuilder);
pocketPingBuilder.getEventsMeasurement()
poPingBuilder.getEventsMeasurement()
.add(TelemetryEvent.create("action", "click", "video_id"))
.add(TelemetryEvent.create("action", "click", "video_id"))
.add(TelemetryEvent.create("action", "impression", "video_id"));
.add(TelemetryEvent.create("action", "impression", "video_id"))
.add(TelemetryEvent.create("action", "click", "video_id"));
}
telemetry.queuePing(TelemetryPocketEventPingBuilder.TYPE);
......@@ -554,6 +554,27 @@ public class TelemetryTest {
final JSONArray pocketEvents = pocketObject.getJSONArray("events");
assertEquals(3, pocketEvents.length());
final JSONArray event1 = pocketEvents.getJSONArray(0);
assertEquals(4, event1.length());
assertTrue(event1.getLong(0) >= 0);
assertEquals("action", event1.getString(1));
assertEquals("click", event1.getString(2));
assertEquals("video_id", event1.getString(3));
final JSONArray event2 = pocketEvents.getJSONArray(1);
assertEquals(4, event2.length());
assertTrue(event2.getLong(0) >= 0);
assertEquals("action", event2.getString(1));
assertEquals("impression", event2.getString(2));
assertEquals("video_id", event2.getString(3));
final JSONArray event3 = pocketEvents.getJSONArray(2);
assertEquals(4, event3.length());
assertTrue(event3.getLong(0) >= 0);
assertEquals("action", event3.getString(1));
assertEquals("click", event3.getString(2));
assertEquals("video_id", event3.getString(3));
server.shutdown();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment