public void QueryOneTest() { for (int i = 0; i < 10; ++i) { string date = DateTime.Now.ToString(); BsonDocument insertor = new BsonDocument(); insertor.Add("operation", "Query"); insertor.Add("date", date); coll.Insert(insertor); } BsonDocument matcher = new BsonDocument(); DBQuery query = new DBQuery(); matcher.Add("operation", "Query"); query.Matcher = matcher; query.ReturnRowsCount = 5; query.SkipRowsCount = 5; query.Flag = DBQuery.FLG_QUERY_WITH_RETURNDATA; DBCursor cursor = coll.Query(query); Assert.IsNotNull(cursor); sdb.CloseAllCursors(); int count = 0; while (cursor.Next() != null) { ++count; BsonDocument bson = cursor.Current(); Assert.IsNotNull(bson); } Assert.IsTrue(count == 5); }
public void CloseAllCursorsTest() { int num = 10000; for (int i = 0; i < num; i++) { BsonDocument insertor = new BsonDocument(); insertor.Add("num", i); coll.Insert(insertor); } BsonDocument dummy = new BsonDocument(); DBCursor cursor = coll.Query(dummy, dummy, dummy, dummy); DBCursor cursor1 = coll.Query(dummy, dummy, dummy, dummy); DBCursor cursor2 = coll.Query(dummy, dummy, dummy, dummy); BsonDocument obj = new BsonDocument(); obj = cursor1.Next(); obj = cursor2.Next(); // DO: sdb.CloseAllCursors(); // cursor try { while (null != cursor.Next()) { } } catch (BaseException e) { int eno = e.ErrorCode; Assert.IsTrue(e.ErrorType.Equals("SDB_RTN_CONTEXT_NOTEXIST")); } // cursor1 try { while (null != cursor1.Next()) { } } catch (BaseException e) { int eno = e.ErrorCode; Assert.IsTrue(e.ErrorType.Equals("SDB_RTN_CONTEXT_NOTEXIST")); } // curosr2 try { obj = cursor2.Current(); cursor2.Close(); } catch (BaseException) { Assert.Fail(); //int eno = e.ErrorCode; //Assert.IsTrue(e.ErrorType.Equals("SDB_RTN_CONTEXT_NOTEXIST")); } }