@Test
@Ignore("Ignored until EventService and Event model objects can be properly factored/replaced in analytics tests.")
public void testEventSpout() throws Exception {
// EventService eventService = applicationManager.getEventService();
// List<Event> allEvents = new ArrayList<Event>();
MockOutputCollector outputCollector = new MockOutputCollector();
EventSpout spout = new EventSpout();
List<BasicDBObject> allRawEvents = new ArrayList<>();
spout.open(null, null, new SpoutOutputCollector(outputCollector));
// Add all events
allRawEvents.addAll(spout.getQueue());
// Filter out any events in the raw events after the last event date in the
// events returned from the service. (This is to work around a potential
// situation where an event(s) is fired in between getting events via the
// EventService and via the EventSpout.
final Date lastEventDate = new Date(allRawEvents.get(allRawEvents.size() - 1).getLong("timestamp"));
// allEvents.addAll(Collections2.filter(eventService.getEventsForAccount(null), new Predicate<Event>() {
// @Override
// public boolean apply(Event event) {
// Date eventDate = new Date(event.getTimestamp());
//
// return !eventDate.after(lastEventDate);
// }
// }));
//
// // Make sure the events in the queue and the events in the DB collection are the same
// Assert.assertEquals(allEvents.size(), allRawEvents.size());
// Exhaust the queue
while (!spout.isQuiet()) {
spout.nextTuple();
if (Math.random() < 0.3) {
BasicDBObject last = (BasicDBObject) outputCollector.getLastEmmitedValue().get(0);
Assert.assertNotNull(last);
spout.fail(last.get("_id"));
}
}
// Wait until we re-poll for new events
while(spout.isQuiet()) {
Thread.sleep(10000);
spout.nextTuple();
}
// Get expected total of events
int totalEventsEmitted = allRawEvents.size() + spout.getQueue().size();
// Exhaust the queue
while (!spout.isQuiet()) {
spout.nextTuple();
}
// Make sure events processed count is as expected
Assert.assertEquals(totalEventsEmitted, outputCollector.getEmittedSpoutValues().size());
// Validate the events were sent to the proper stream
for (Map.Entry<String, List<Values>> entry : outputCollector.getEmittedSpoutValuesMap().entrySet()) {
String streamId = entry.getKey();
List<Values> events = entry.getValue();
for (Values values : events) {
BasicDBObject event = (BasicDBObject)values.get(0);