public void TestAppend() { uint recno; testName = "TestAppend"; SetUpTest(true); string dbFileName = testHome + "/" + testName + ".db"; RecnoDatabaseConfig recnoConfig = new RecnoDatabaseConfig(); recnoConfig.Creation = CreatePolicy.IF_NEEDED; recnoConfig.Append = new AppendRecordDelegate( AppendRecord); RecnoDatabase recnoDB = RecnoDatabase.Open( dbFileName, recnoConfig); recno = recnoDB.Append(new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes("data"))); KeyValuePair <DatabaseEntry, DatabaseEntry> pair; pair = recnoDB.Get( new DatabaseEntry(BitConverter.GetBytes(recno))); Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data"), pair.Value.Data); recnoDB.Close(); }
public void GetCursorWithImplicitTxn(string home, string dbFile, bool ifConfig) { DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseCDB = true; envConfig.UseMPool = true; DatabaseEnvironment env = DatabaseEnvironment.Open( home, envConfig); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; RecnoDatabase db = RecnoDatabase.Open(dbFile, dbConfig); RecnoCursor cursor; if (ifConfig == false) { cursor = db.Cursor(); } else { cursor = db.Cursor(new CursorConfig()); } cursor.Close(); db.Close(); env.Close(); }
public void TestConfig() { testName = "TestConfig"; SetUpTest(true); string dbFileName = testHome + "/" + testName + ".db"; XmlElement xmlElem = Configuration.TestSetUp( testFixtureName, testName); // Open a primary btree database. RecnoDatabaseConfig recDBConfig = new RecnoDatabaseConfig(); recDBConfig.Creation = CreatePolicy.IF_NEEDED; RecnoDatabase recDB = RecnoDatabase.Open( dbFileName, recDBConfig); SecondaryRecnoDatabaseConfig secDBConfig = new SecondaryRecnoDatabaseConfig(recDB, null); Config(xmlElem, ref secDBConfig, true); Confirm(xmlElem, secDBConfig, true); // Close the primary btree database. recDB.Close(); }
public void TestTruncateUnusedPages() { testName = "TestTruncateUnusedPages"; SetUpTest(true); DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseCDB = true; envConfig.UseMPool = true; DatabaseEnvironment env = DatabaseEnvironment.Open( testHome, envConfig); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; dbConfig.PageSize = 512; RecnoDatabase db = RecnoDatabase.Open( testName + ".db", dbConfig); ModifyRecordsInDB(db, null); Assert.Less(0, db.TruncateUnusedPages()); db.Close(); env.Close(); }
public void TestAppendWithoutTxn() { testName = "TestAppendWithoutTxn"; SetUpTest(true); string recnoDBFileName = testHome + "/" + testName + ".db"; RecnoDatabaseConfig recnoConfig = new RecnoDatabaseConfig(); recnoConfig.Creation = CreatePolicy.ALWAYS; RecnoDatabase recnoDB = RecnoDatabase.Open( recnoDBFileName, recnoConfig); DatabaseEntry data = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes("data")); uint num = recnoDB.Append(data); DatabaseEntry key = new DatabaseEntry( BitConverter.GetBytes(num)); Assert.IsTrue(recnoDB.Exists(key)); KeyValuePair <DatabaseEntry, DatabaseEntry> record = recnoDB.Get(key); Assert.IsTrue(data.Data.Length == record.Value.Data.Length); for (int i = 0; i < data.Data.Length; i++) { Assert.IsTrue(data.Data[i] == record.Value.Data[i]); } recnoDB.Close(); }
public void TestOpenExistingRecnoDB() { testName = "TestOpenExistingRecnoDB"; SetUpTest(true); string recnoDBFileName = testHome + "/" + testName + ".db"; RecnoDatabaseConfig recConfig = new RecnoDatabaseConfig(); recConfig.Creation = CreatePolicy.ALWAYS; RecnoDatabase recDB = RecnoDatabase.Open( recnoDBFileName, recConfig); recDB.Close(); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); string backingFile = testHome + "/backingFile"; File.Copy(recnoDBFileName, backingFile); dbConfig.BackingFile = backingFile; RecnoDatabase db = RecnoDatabase.Open(recnoDBFileName, dbConfig); Assert.AreEqual(db.Type, DatabaseType.RECNO); db.Close(); }
public void TestStats() { testName = "TestStats"; SetUpTest(true); string dbFileName = testHome + "/" + testName + ".db"; RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); ConfigCase1(dbConfig); RecnoDatabase db = RecnoDatabase.Open(dbFileName, dbConfig); RecnoStats stats = db.Stats(); ConfirmStatsPart1Case1(stats); // Put 1000 records into the database. PutRecordCase1(db, null); stats = db.Stats(); ConfirmStatsPart2Case1(stats); // Delete 500 records. for (int i = 250; i <= 750; i++) { db.Delete(new DatabaseEntry(BitConverter.GetBytes(i))); } stats = db.Stats(); ConfirmStatsPart3Case1(stats); db.Close(); }
private void Dispose(bool disposing) { if (!disposing) { return; } db?.Close(true); db?.Dispose(); }
public void TestMessageFile() { testName = "TestMessageFile"; SetUpTest(true); // Configure and open an environment. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseMPool = true; DatabaseEnvironment env = DatabaseEnvironment.Open( testHome, envConfig); // Configure and open a database. RecnoDatabaseConfig DBConfig = new RecnoDatabaseConfig(); DBConfig.Env = env; DBConfig.Creation = CreatePolicy.IF_NEEDED; string DBFileName = testName + ".db"; RecnoDatabase db = RecnoDatabase.Open( DBFileName, DBConfig); // Confirm message file does not exist. string messageFile = testHome + "/" + "msgfile"; Assert.AreEqual(false, File.Exists(messageFile)); // Call set_msgfile() of db. db.Msgfile = messageFile; // Print db statistic to message file. db.PrintStats(true); // Confirm message file exists now. Assert.AreEqual(true, File.Exists(messageFile)); db.Msgfile = ""; string line = null; // Read the third line of message file. System.IO.StreamReader file = new System.IO.StreamReader(@"" + messageFile); line = file.ReadLine(); line = file.ReadLine(); line = file.ReadLine(); // Confirm the message file is not empty. Assert.AreEqual(line, "DB handle information:"); file.Close(); // Close database and environment. db.Close(); env.Close(); }
public void GetCursorWithExplicitTxn(string home, string dbFile, bool ifConfig) { DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseTxns = true; envConfig.UseMPool = true; DatabaseEnvironment env = DatabaseEnvironment.Open( home, envConfig); Transaction openTxn = env.BeginTransaction(); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; RecnoDatabase db = RecnoDatabase.Open(dbFile, dbConfig, openTxn); openTxn.Commit(); Transaction cursorTxn = env.BeginTransaction(); RecnoCursor cursor; if (ifConfig == false) { cursor = db.Cursor(cursorTxn); } else { cursor = db.Cursor(new CursorConfig(), cursorTxn); } cursor.Close(); cursorTxn.Commit(); db.Close(); env.Close(); }
public void TestTruncateUnusedPagesInTxn() { testName = "TestTruncateUnusedPagesInTxn"; testHome = testFixtureHome + "/" + testName; Configuration.ClearDir(testHome); DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseLogging = true; envConfig.UseMPool = true; envConfig.UseTxns = true; DatabaseEnvironment env = DatabaseEnvironment.Open( testHome, envConfig); Transaction openTxn = env.BeginTransaction(); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; dbConfig.PageSize = 512; RecnoDatabase db = RecnoDatabase.Open( testName + ".db", dbConfig, openTxn); openTxn.Commit(); Transaction modifyTxn = env.BeginTransaction(); ModifyRecordsInDB(db, modifyTxn); Assert.Less(0, db.TruncateUnusedPages(modifyTxn)); modifyTxn.Commit(); db.Close(); env.Close(); }
public void StatsInTxn(string home, string name, bool ifIsolation) { DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); EnvConfigCase1(envConfig); DatabaseEnvironment env = DatabaseEnvironment.Open( home, envConfig); Transaction openTxn = env.BeginTransaction(); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); ConfigCase1(dbConfig); dbConfig.Env = env; RecnoDatabase db = RecnoDatabase.Open(name + ".db", dbConfig, openTxn); openTxn.Commit(); Transaction statsTxn = env.BeginTransaction(); RecnoStats stats; RecnoStats fastStats; if (ifIsolation == false) { stats = db.Stats(statsTxn); fastStats = db.FastStats(statsTxn); } else { stats = db.Stats(statsTxn, Isolation.DEGREE_ONE); fastStats = db.FastStats(statsTxn, Isolation.DEGREE_ONE); } ConfirmStatsPart1Case1(stats); // Put 1000 records into the database. PutRecordCase1(db, statsTxn); if (ifIsolation == false) { stats = db.Stats(statsTxn); fastStats = db.FastStats(statsTxn); } else { stats = db.Stats(statsTxn, Isolation.DEGREE_TWO); fastStats = db.FastStats(statsTxn, Isolation.DEGREE_TWO); } ConfirmStatsPart2Case1(stats); // Delete 500 records. for (int i = 250; i <= 750; i++) { db.Delete(new DatabaseEntry(BitConverter.GetBytes(i)), statsTxn); } if (ifIsolation == false) { stats = db.Stats(statsTxn); fastStats = db.FastStats(statsTxn); } else { stats = db.Stats(statsTxn, Isolation.DEGREE_THREE); fastStats = db.FastStats(statsTxn, Isolation.DEGREE_THREE); } ConfirmStatsPart3Case1(stats); statsTxn.Commit(); db.Close(); env.Close(); }
public void OpenSecRecnoDBWithinTxn(string className, string funName, string home, string dbFileName, string dbSecFileName, bool ifDbName) { XmlElement xmlElem = Configuration.TestSetUp( className, funName); // Open an environment. DatabaseEnvironmentConfig envConfig = new DatabaseEnvironmentConfig(); envConfig.Create = true; envConfig.UseTxns = true; envConfig.UseMPool = true; envConfig.UseLogging = true; DatabaseEnvironment env = DatabaseEnvironment.Open( home, envConfig); // Open a primary recno database. Transaction openDBTxn = env.BeginTransaction(); RecnoDatabaseConfig dbConfig = new RecnoDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.Env = env; RecnoDatabase db = RecnoDatabase.Open( dbFileName, dbConfig, openDBTxn); openDBTxn.Commit(); // Open a secondary recno database. Transaction openSecTxn = env.BeginTransaction(); SecondaryRecnoDatabaseConfig secDBConfig = new SecondaryRecnoDatabaseConfig(db, new SecondaryKeyGenDelegate(SecondaryKeyGen)); SecondaryRecnoDatabaseConfigTest.Config(xmlElem, ref secDBConfig, false); secDBConfig.Env = env; SecondaryRecnoDatabase secDB; if (ifDbName == false) { secDB = SecondaryRecnoDatabase.Open( dbSecFileName, secDBConfig, openSecTxn); } else { secDB = SecondaryRecnoDatabase.Open( dbSecFileName, "secondary", secDBConfig, openSecTxn); } openSecTxn.Commit(); // Confirm its flags configured in secDBConfig. Confirm(xmlElem, secDB, true); secDB.Close(); // Open the existing secondary database. Transaction secTxn = env.BeginTransaction(); SecondaryDatabaseConfig secConfig = new SecondaryDatabaseConfig(db, new SecondaryKeyGenDelegate(SecondaryKeyGen)); secConfig.Env = env; SecondaryDatabase secExDB; if (ifDbName == false) { secExDB = SecondaryRecnoDatabase.Open( dbSecFileName, secConfig, secTxn); } else { secExDB = SecondaryRecnoDatabase.Open( dbSecFileName, "secondary", secConfig, secTxn); } secExDB.Close(); secTxn.Commit(); db.Close(); env.Close(); }