public void GetSnapshotTest() { Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address); sdb2.Connect(); BsonDocument dummy = new BsonDocument(); DBCursor cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONSPACES, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_DATABASE, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SYSTEM, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); if (Constants.isClusterEnv(sdb)) { cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_CATALOG, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument obj = cursor.Next(); Assert.IsNotNull(obj); } sdb2.Disconnect(); }
public void AlterCollectionTest() { DBCollection coll = null; BsonDocument options = null; string clName_alter = "alterCLTest"; string fullName = null; int partition = 0; string type = null; int rs = -1; coll = cs.CreateCollection(clName_alter); fullName = coll.CollSpace.Name + "." + clName_alter; // alter collecton attrubute options = new BsonDocument { { "ReplSize", 0 }, { "ShardingKey", new BsonDocument { { "a", 1 } } }, { "ShardingType", "hash" }, { "Partition", 4096 } }; coll.Alter(options); // check BsonDocument matcher = new BsonDocument { { "Name", fullName } }; DBCursor cur = sdb.GetSnapshot(8, matcher, null, null); BsonDocument obj = cur.Next(); if (null == obj) { Assert.Fail(); } try { rs = obj["ReplSize"].AsInt32; Assert.IsTrue(7 == rs); partition = obj["Partition"].AsInt32; Assert.IsTrue(4096 == partition); type = obj["ShardingType"].AsString; Assert.IsTrue(type.Equals("hash")); } catch (System.Exception) { Assert.Fail(); } }
public void GetSnapshotTest() { Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address); sdb2.Connect(); BsonDocument dummy = new BsonDocument(); DBCursor cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONSPACES, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_DATABASE, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SYSTEM, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); if (Constants.isClusterEnv(sdb)) { cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_CATALOG, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument obj = cursor.Next(); Assert.IsNotNull(obj); } sdb2.Disconnect(); // snapshot transation sdb.TransactionBegin(); try { BsonDocument o = null; coll.Insert(new BsonDocument()); cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: "); while (null != (o = cursor.Next())) { Console.WriteLine(o); } cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS_CURRENT, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS_CURRENT is: "); while (null != (o = cursor.Next())) { Console.WriteLine(o); } } catch (BaseException e) { Console.WriteLine("The error info is: " + e.ErrorType + ", " + e.ErrorCode + ", " + e.Message); Assert.IsTrue(e.ErrorType == "SDB_DPS_TRANS_DIABLED"); } finally { sdb.TransactionCommit(); } // snapshot accessplans { BsonDocument o = null; cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_ACCESSPLANS, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: "); while (null != (o = cursor.Next())) { Console.WriteLine(o); } } // node health { cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_HEALTH, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_HEALTH is: "); BsonDocument rec = null; while (null != (rec = cursor.Next())) { Console.WriteLine(rec); } } }
public void setSessionAttrTest() { // create another node string host = "192.168.20.42"; int port = 55555; string dataPath = "/opt/sequoiadb/database/data/55555"; string groupName = "group1"; ReplicaGroup rg = null; try { // get the exist group rg = sdb.GetReplicaGroup(groupName); // remove the node we going to use SequoiaDB.Node node = rg.GetNode(host, port); if (node != null) { rg.RemoveNode(host, port, new BsonDocument()); } // create node Dictionary <string, string> opt = new Dictionary <string, string>(); rg.CreateNode(host, port, dataPath, opt); rg.Start(); // insert some records first int num = 10; List <BsonDocument> insertor = new List <BsonDocument>(); for (int i = 0; i < num; i++) { BsonDocument obj = new BsonDocument(); obj.Add("id", i); insertor.Add(obj); } coll.BulkInsert(insertor, 0); // begin a new session Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address); sdb2.Connect(config.conf.UserName, config.conf.Password); Assert.IsNotNull(sdb2.Connection); // TODO: BsonDocument conf = new BsonDocument("PreferedInstance", "m"); sdb2.SetSessionAttr(conf); // check // record the slave note "TotalDataRead" before query Sequoiadb sddb = new Sequoiadb(host, port); sddb.Connect(config.conf.UserName, config.conf.Password); DBCursor cur1 = sddb.GetSnapshot(6, null, null, null); BsonDocument status1 = cur1.Next(); long count1 = status1.GetValue("TotalDataRead").AsInt64; // query DBCursor cursor = coll.Query(null, null, null, null, 0, -1); BsonDocument o = new BsonDocument(); long count = 0; while ((o = cursor.Next()) != null) { count++; } // record the slave note "TotalRead" after query DBCursor cur2 = sddb.GetSnapshot(6, null, null, null); BsonDocument status2 = cur2.Next(); long count2 = status2.GetValue("TotalDataRead").AsInt64; //Assert.IsTrue(num == count2 - count1); long temp = count2 - count1; Console.WriteLine("count2 is " + count2 + ", count1 is " + count1); DBCursor cur3 = sddb.GetSnapshot(6, null, null, null); BsonDocument status3 = cur3.Next(); long count3 = status3.GetValue("TotalRead").AsInt64; } finally { // remove the newly build node SequoiaDB.Node node = rg.GetNode(host, port); if (node != null) { rg.RemoveNode(host, port, new BsonDocument()); } } }
public void setSessionAttrTest() { // create another node string host = "192.168.20.42"; int port = 55555; string dataPath = "/opt/sequoiadb/database/data/55555"; string groupName = "group1"; ReplicaGroup rg = null; try { // get the exist group rg = sdb.GetReplicaGroup(groupName); // remove the node we going to use var node = rg.GetNode(host, port); if (node != null) { rg.RemoveNode(host, port, new BsonDocument()); } // create node Dictionary<string, string> opt = new Dictionary<string, string>(); rg.CreateNode(host, port, dataPath, opt); rg.Start(); // insert some records first int num = 10; List<BsonDocument> insertor = new List<BsonDocument>(); for (int i = 0; i < num; i++) { BsonDocument obj = new BsonDocument(); obj.Add("id", i); insertor.Add(obj); } coll.BulkInsert(insertor, 0); // begin a new session Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address); sdb2.Connect(config.conf.UserName, config.conf.Password); Assert.IsNotNull(sdb2.Connection); // TODO: BsonDocument conf = new BsonDocument("PreferedInstance", "m"); sdb2.SetSessionAttr(conf); // check // record the slave note "TotalDataRead" before query var sddb = new Sequoiadb(host, port); sddb.Connect(config.conf.UserName, config.conf.Password); DBCursor cur1 = sddb.GetSnapshot(6, null, null, null); BsonDocument status1 = cur1.Next(); long count1 = status1.GetValue("TotalDataRead").AsInt64; // query DBCursor cursor = coll.Query(null, null, null, null, 0, -1); BsonDocument o = new BsonDocument(); long count = 0; while ((o = cursor.Next()) != null) count++; // record the slave note "TotalRead" after query DBCursor cur2 = sddb.GetSnapshot(6, null, null, null); BsonDocument status2 = cur2.Next(); long count2 = status2.GetValue("TotalDataRead").AsInt64; //Assert.IsTrue(num == count2 - count1); long temp = count2 - count1; Console.WriteLine("count2 is " + count2 + ", count1 is " + count1); DBCursor cur3 = sddb.GetSnapshot(6, null, null, null); BsonDocument status3 = cur3.Next(); long count3 = status3.GetValue("TotalRead").AsInt64; } finally { // remove the newly build node var node = rg.GetNode(host, port); if (node != null) { rg.RemoveNode(host, port, new BsonDocument()); } } }
public void GetSnapshotTest() { Sequoiadb sdb2 = new Sequoiadb(config.conf.Coord.Address); sdb2.Connect(); BsonDocument dummy = new BsonDocument(); DBCursor cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_CONTEXTS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SESSIONS_CURRENT, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONS, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_COLLECTIONSPACES, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_DATABASE, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); cursor = sdb2.GetSnapshot(SDBConst.SDB_SNAP_SYSTEM, dummy, dummy, dummy); Assert.IsNotNull(cursor); bson = cursor.Next(); Assert.IsNotNull(bson); if (Constants.isClusterEnv(sdb)) { cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_CATALOG, dummy, dummy, dummy); Assert.IsNotNull(cursor); BsonDocument obj = cursor.Next(); Assert.IsNotNull(obj); } sdb2.Disconnect(); // snapshot transation sdb.TransactionBegin(); try { BsonDocument o = null; coll.Insert(new BsonDocument()); cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS is: "); while (null != (o = cursor.Next())) { Console.WriteLine(o); } cursor = sdb.GetSnapshot(SDBConst.SDB_SNAP_TRANSACTIONS_CURRENT, dummy, dummy, dummy); Console.WriteLine("the result of SDB_SNAP_TRANSACTIONS_CURRENT is: "); while (null != (o = cursor.Next())) { Console.WriteLine(o); } } finally { sdb.TransactionCommit(); } }