'Test the get_oplog_cursor method'

def test_get_oplog_cursor(self):

    cursor1 = self.opman1.get_oplog_cursor(None)
    oplog1 = self.shard1_conn['local']['oplog.rs'].find({'op': {'$ne': 'n'}})
    self.assertEqual(list(cursor1), list(oplog1))
    cursor2 = self.opman2.get_oplog_cursor(None)
    oplog2 = self.shard2_conn['local']['oplog.rs'].find({'op': {'$ne': 'n'}})
    self.assertEqual(list(cursor2), list(oplog2))
    doc = {'ts': bson.Timestamp(1000, 0), 'i': 1}
    self.mongos_conn['test']['mcsharded'].insert_one(doc)
    latest_timestamp = self.opman1.get_last_oplog_timestamp()
    cursor = self.opman1.get_oplog_cursor(latest_timestamp)
    self.assertNotEqual(cursor, None)
    entries = list(cursor)
    self.assertEqual(len(entries), 1)
    next_entry_id = entries[0]['o']['_id']
    retrieved = self.mongos_conn.test.mcsharded.find_one(next_entry_id)
    self.assertEqual(retrieved, doc)
    for i in range(2, 2002):
        self.mongos_conn['test']['mcsharded'].insert_one({'i': i})
    oplog1 = self.shard1_conn['local']['oplog.rs'].find(sort=[('ts', pymongo.ASCENDING)])
    oplog2 = self.shard2_conn['local']['oplog.rs'].find(sort=[('ts', pymongo.ASCENDING)])
    oplog1_count = oplog1.count()
    oplog2_count = oplog2.count()
    self.assertGreaterEqual(oplog1_count, 998)
    self.assertGreaterEqual(oplog2_count, 1002)
    pivot1 = oplog1.skip(400).limit((-1))[0]
    pivot2 = oplog2.skip(400).limit((-1))[0]
    cursor1 = self.opman1.get_oplog_cursor(pivot1['ts'])
    cursor2 = self.opman2.get_oplog_cursor(pivot2['ts'])
    self.assertEqual(cursor1.count(), (oplog1_count - 400))
    self.assertEqual(cursor2.count(), (oplog2_count - 400))
