Search in sources :

Example 11 with BSONTimestamp

use of org.bson.types.BSONTimestamp in project camel by apache.

the class MongoDBTailTrackingStrategyTest method testExtractLastValForTimestamp.

@Test
public void testExtractLastValForTimestamp() throws Exception {
    DBObject o = mock(DBObject.class);
    final int lastVal = 1483701465;
    when(o.get(INCREASING_FIELD_NAME)).thenReturn(new BSONTimestamp(lastVal, 1));
    Object res = MongoDBTailTrackingEnum.TIMESTAMP.extractLastVal(o, INCREASING_FIELD_NAME);
    assertThat(res, is(lastVal));
}
Also used : BSONTimestamp(org.bson.types.BSONTimestamp) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Example 12 with BSONTimestamp

use of org.bson.types.BSONTimestamp in project camel by apache.

the class MongoDBTailTrackingStrategyTest method testExtracCreateQueryForTimestamp.

@Test
public void testExtracCreateQueryForTimestamp() throws Exception {
    final int lastVal = 1483701465;
    BasicDBObject basicDBObject = MongoDBTailTrackingEnum.TIMESTAMP.createQuery(lastVal, INCREASING_FIELD_NAME);
    final Object actual = basicDBObject.get(INCREASING_FIELD_NAME);
    assertThat(actual, is(notNullValue()));
    assertThat(actual instanceof BasicDBObject, is(true));
    assertThat(((BasicDBObject) actual).get("$gt") instanceof BSONTimestamp, is(true));
    BSONTimestamp bsonTimestamp = (BSONTimestamp) ((BasicDBObject) actual).get("$gt");
    assertThat(bsonTimestamp.getTime(), is(lastVal));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) BSONTimestamp(org.bson.types.BSONTimestamp) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Test(org.junit.Test)

Aggregations

BSONTimestamp (org.bson.types.BSONTimestamp)12 Date (java.util.Date)8 Test (org.junit.Test)8 Binary (org.bson.types.Binary)7 Code (org.bson.types.Code)6 CodeWScope (org.bson.types.CodeWScope)6 ObjectId (org.bson.types.ObjectId)6 BasicDBObject (com.mongodb.BasicDBObject)5 MaxKey (org.bson.types.MaxKey)5 MinKey (org.bson.types.MinKey)5 DBObject (com.mongodb.DBObject)3 DBRef (com.mongodb.DBRef)3 SimpleDateFormat (java.text.SimpleDateFormat)3 GregorianCalendar (java.util.GregorianCalendar)3 SimpleTimeZone (java.util.SimpleTimeZone)3 BasicBSONObject (org.bson.BasicBSONObject)3 Symbol (org.bson.types.Symbol)3 UUID (java.util.UUID)2 Pattern (java.util.regex.Pattern)2 BSONObject (org.bson.BSONObject)2