public void CheckInvalidSituaction() { bool boolValue = true; long longValue = 300 * 1000; ClientOptions opt = new ClientOptions(); opt.CacheInterval = longValue; opt.EnableCache = boolValue; Sequoiadb db = new Sequoiadb(config.conf.Coord.Address); db.Connect(config.conf.UserName, config.conf.Password); Sequoiadb.InitClient(opt); // check Type t = db.GetType(); BindingFlags flag = BindingFlags.NonPublic | BindingFlags.Instance; FieldInfo f_nameCache = t.GetField("nameCache", flag); Dictionary <String, DateTime> dic = f_nameCache.GetValue(db) as Dictionary <String, DateTime>; Assert.AreEqual(0, dic.Count); String csName = "foo_csharp."; String clName = "bar_csharp."; try { db.DropCollectionSpace(csName); } catch (BaseException e) { } try { db.CreateCollectionSpace(csName); Assert.Fail(); } catch (BaseException e) { csName = "foo_csharp"; } try { db.DropCollectionSpace(csName); } catch (BaseException e) { } // check Assert.AreEqual(0, dic.Count); CollectionSpace cs = db.CreateCollectionSpace(csName); // check Assert.AreEqual(1, dic.Count); Assert.IsTrue(dic.ContainsKey(csName)); try { cs.CreateCollection(clName); Assert.Fail(); } catch (BaseException e) { clName = "bar_csharp"; } // check Assert.AreEqual(1, dic.Count); Assert.IsTrue(dic.ContainsKey(csName)); cs.CreateCollection(clName); // check Assert.AreEqual(2, dic.Count); Assert.IsTrue(dic.ContainsKey(csName + "." + clName)); Assert.IsTrue(dic.ContainsKey(csName)); db.DropCollectionSpace(csName); // check Assert.AreEqual(0, dic.Count); db.Disconnect(); }
public void CheckDisableCacheLogic() { // test1: test default value bool boolValue = false; long longValue = 300 * 1000; ClientOptions opt = new ClientOptions(); opt.CacheInterval = longValue; opt.EnableCache = boolValue; Sequoiadb db = new Sequoiadb(config.conf.Coord.Address); db.Connect(config.conf.UserName, config.conf.Password); Sequoiadb.InitClient(opt); // check Type t = db.GetType(); BindingFlags flag = BindingFlags.NonPublic | BindingFlags.Instance; FieldInfo f_nameCache = t.GetField("nameCache", flag); Dictionary <String, DateTime> dic = f_nameCache.GetValue(db) as Dictionary <String, DateTime>; Assert.AreEqual(0, dic.Count); // create cs CollectionSpace[] csObjArr = new CollectionSpace[3]; for (int i = 0; i < csArr.Length; i++) { try { db.DropCollectionSpace(csArr[i]); } catch (BaseException e) { } } for (int i = 0; i < csArr.Length; i++) { csObjArr[i] = db.CreateCollectionSpace(csArr[i]); } // test1: 检测db对象中cs的缓存情况 Console.Out.WriteLine("point 1: after creating cs, nameCache.Count is: " + dic.Count); Assert.AreEqual(0, dic.Count); // drop one cs db.DropCollectionSpace(csArr[0]); // test2: 删除一个cs之后,检测db对象中cs的缓存情况 Assert.AreEqual(0, dic.Count); // create the drop cs csObjArr[0] = db.CreateCollectionSpace(csArr[0]); Assert.AreEqual(0, dic.Count); // create cl BsonDocument conf = new BsonDocument(); conf.Add("ReplSize", 0); for (int i = 0; i < clArr1.Length; i++) { //Console.Out.WriteLine("csObjArr[0] is: " + csObjArr[0].getName() + ", clArr1[x] is: " + clArr1[i]); csObjArr[0].CreateCollection(clArr1[i], conf); } // test3: 检测db对象中cs,cl的缓存情况 Assert.AreEqual(0, dic.Count); // drop one cl csObjArr[0].DropCollection(clArr1[0]); // test4: 检测删除cl之后,cs,cl的缓存情况 Assert.AreEqual(0, dic.Count); // drop one cs db.DropCollectionSpace(csArr[0]); // test5: 检测删除cs之后,cs,cl的缓存情况 Assert.AreEqual(0, dic.Count); db.Disconnect(); }