}
@Test
public void testPersistentTailTrackIncreasingDateField() throws Exception {
assertEquals(0, cappedTestCollection.count());
final MockEndpoint mock = getMockEndpoint("mock:test");
final Calendar startTimestamp = Calendar.getInstance();
// get default tracking collection
DBCollection trackingCol = db.getCollection(MongoDbTailTrackingConfig.DEFAULT_COLLECTION);
trackingCol.drop();
trackingCol = db.getCollection(MongoDbTailTrackingConfig.DEFAULT_COLLECTION);
// create a capped collection with max = 1000
cappedTestCollection = db.createCollection(cappedTestCollectionName,
BasicDBObjectBuilder.start().add("capped", true).add("size", 1000000000).add("max", 1000).get());
addTestRoutes();
context.startRoute("tailableCursorConsumer2");
mock.expectedMessageCount(300);
// pump 300 records
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 1; i <= 300; i++) {
Calendar c = (Calendar) (startTimestamp.clone());
c.add(Calendar.MINUTE, i);
cappedTestCollection.insert(BasicDBObjectBuilder.start("increasing", c.getTime()).add("string", "value" + i).get(), WriteConcern.SAFE);
}
}
});
// start the data pumping
t.start();
// before we continue wait for the data pump to end
t.join();
mock.assertIsSatisfied();
mock.reset();
// ensure that the persisted lastVal is startTimestamp + 300min
Calendar cal300 = (Calendar) startTimestamp.clone();
cal300.add(Calendar.MINUTE, 300);
context.stopRoute("tailableCursorConsumer2");
assertEquals(cal300.getTime(), trackingCol.findOne(new BasicDBObject("persistentId", "darwin")).get(MongoDbTailTrackingConfig.DEFAULT_FIELD));
context.startRoute("tailableCursorConsumer2");
// expect 300 messages and not 600
mock.expectedMessageCount(300);
// pump 300 records
t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 301; i <= 600; i++) {
Calendar c = (Calendar) (startTimestamp.clone());
c.add(Calendar.MINUTE, i);
cappedTestCollection.insert(BasicDBObjectBuilder.start("increasing", c.getTime()).add("string", "value" + i).get(), WriteConcern.SAFE);
}
}
});
// start the data pumping
t.start();
// before we continue wait for the data pump to end
t.join();
mock.assertIsSatisfied();
Object firstBody = mock.getExchanges().get(0).getIn().getBody();
assertTrue(firstBody instanceof DBObject);
Calendar cal301 = (Calendar) startTimestamp.clone();
cal301.add(Calendar.MINUTE, 301);
assertEquals(cal301.getTime(), ((DBObject) firstBody).get("increasing"));
// check that the persisted lastVal after stopping the route is startTimestamp + 600min