예제 #1
0
        public void InitClientTest()
        {
            // test1: test default value
            bool      boolValue = true;
            long      longValue = 300 * 1000;
            Sequoiadb db        = new Sequoiadb(config.conf.Coord.Address);

            db.Connect(config.conf.UserName, config.conf.Password);
            // check
            Type         t               = typeof(Sequoiadb);
            BindingFlags flag            = BindingFlags.Static | BindingFlags.NonPublic;
            FieldInfo    f_enableCache   = t.GetField("enableCache", flag);
            FieldInfo    f_cacheInterval = t.GetField("cacheInterval", flag);

            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(longValue, f_cacheInterval.GetValue(db));

            // test2: test user defined value
            boolValue = false;
            longValue = 100;
            ClientOptions opt = new ClientOptions();

            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(longValue, f_cacheInterval.GetValue(db));

            // test3: test user definded value
            boolValue         = true;
            longValue         = -1;
            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(300000L, f_cacheInterval.GetValue(db));

            // test4: opt to be null
            boolValue = true;
            longValue = 300000;
            opt       = null;
            Sequoiadb.InitClient(opt);
            // check
            f_enableCache   = t.GetField("enableCache", flag);
            f_cacheInterval = t.GetField("cacheInterval", flag);
            Assert.AreEqual(boolValue, f_enableCache.GetValue(db));
            Assert.AreEqual(300000L, f_cacheInterval.GetValue(db));

            db.Disconnect();
        }
예제 #2
0
        public void CheckCacheWorksOrNotTest()
        {
            bool          boolValue = true;
            long          longValue = 6 * 1000;
            ClientOptions opt       = new ClientOptions();

            opt.CacheInterval = longValue;
            opt.EnableCache   = boolValue;
            Sequoiadb.InitClient(opt);
            Thread.Sleep(6000);
            CollectionSpace cs = sdb.GetCollecitonSpace(csName);

            Console.Out.WriteLine("begin, expect get cl from db");
            DBCollection cl = cs.GetCollection(cName);

            Thread.Sleep(3000);
            Console.Out.WriteLine("begin, expect get cl from cache");
            cl = cs.GetCollection(cName);
            Thread.Sleep(3500);
            Console.Out.WriteLine("begin, expect get cl from db");
            cl = cs.GetCollection(cName);
            Console.Out.WriteLine("haha");
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }