@Test public void testRecordEvent() throws Exception { when(event.getName()).thenReturn(Event.Name.valueOf("ASSIGNMENT")); when(event.getType()).thenReturn(Event.Type.IMPRESSION); when(assignment.getUserID()).thenReturn(User.ID.valueOf("user-a")); Bucket.Label bucketLabel = Bucket.Label.valueOf("red"); when(assignment.getBucketLabel()).thenReturn(bucketLabel); Experiment.ID experimentID = Experiment.ID.valueOf("27ec196b-e90d-4752-9baf-5c3f11d9f78a"); when(assignment.getExperimentID()).thenReturn(experimentID); eventsEnvelope.run(); verify(event, times(1)).getName(); verify(assignment, times(1)).getBucketLabel(); verify(transaction, times(1)).insert(any(String.class), any(String.class), any(Experiment.ID.class), any(Bucket.Label.class), any(String.class), any(Context.class), any(Date.class)); }
void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; Experiment.ID experimentIDValue = assignment.getExperimentID(); Bucket.Label bucketLabelValue = assignment.getBucketLabel(); if (bucketLabelValue != null && experimentIDValue != null) { if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + "(user_id, experiment_id, bucket_label, action, " + "context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload); } } }
EventsEnvelope implements Runnable { void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; Experiment.ID experimentIDValue = assignment.getExperimentID(); Bucket.Label bucketLabelValue = assignment.getBucketLabel(); if (bucketLabelValue != null && experimentIDValue != null) { if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + "(user_id, experiment_id, bucket_label, action, " + "context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload); } } } }
EventsEnvelope implements Runnable { void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; Experiment.ID experimentIDValue = assignment.getExperimentID(); Bucket.Label bucketLabelValue = assignment.getBucketLabel(); if (bucketLabelValue != null && experimentIDValue != null) { if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + "(user_id, experiment_id, bucket_label, action, " + "context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload); } } } EventsEnvelope(final Assignment assignment, final Event event, final Transaction transaction); }
EventsEnvelope implements Runnable { void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; Experiment.ID experimentIDValue = assignment.getExperimentID(); Bucket.Label bucketLabelValue = assignment.getBucketLabel(); if (bucketLabelValue != null && experimentIDValue != null) { if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + "(user_id, experiment_id, bucket_label, action, " + "context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload); } } } EventsEnvelope(final Assignment assignment, final Event event, final Transaction transaction); @Override void run(); }
EventsEnvelope implements Runnable { void recordEvent(Assignment assignment, Event event) throws Exception { String actionNameString = event.getName().toString(); String payload = (event.getPayload() != null) ? event.getPayload().toString() : null; String userIDString = assignment.getUserID().toString(); String context = (event.getContext() != null) ? event.getContext().getContext() : "PROD"; Experiment.ID experimentIDValue = assignment.getExperimentID(); Bucket.Label bucketLabelValue = assignment.getBucketLabel(); if (bucketLabelValue != null && experimentIDValue != null) { if (event.getType().equals(Event.Type.IMPRESSION)) { transaction.insert("INSERT INTO event_impression " + "(user_id, experiment_id, bucket_label, context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, context, event.getTimestamp(), payload); } else { transaction.insert("INSERT INTO event_action " + "(user_id, experiment_id, bucket_label, action, " + "context, timestamp, payload) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", userIDString, experimentIDValue, bucketLabelValue, actionNameString, context, event.getTimestamp(), payload); } } } EventsEnvelope(final Assignment assignment, final Event event, final Transaction transaction); @Override void run();  }