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();
        }
Example #2
0
        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();
        }
Example #3
0
        public void PutRecio(byte[] data, Transaction txn = null)
        {
            RecnoDatabase recno = db as RecnoDatabase;

            if (null != recno)
            {
                DatabaseEntry v = new DatabaseEntry(data);
                recno.Append(v, txn);
            }
        }
        protected void AddToDb(string keyval, byte[] dataval)
        {
            var key  = new DatabaseEntry(Encoding.UTF8.GetBytes(keyval));
            var data = new DatabaseEntry(dataval);

            //This is the data insertion method for Queue/Recno databases.
            db.Append(data);
            //...not this one
            //db.Put(key, data);
        }
Example #5
0
        public void ModifyRecordsInDB(RecnoDatabase db,
                                      Transaction txn)
        {
            uint[] recnos = new uint[100];

            if (txn == null)
            {
                // Add a lot of records into database.
                for (int i = 0; i < 100; i++)
                {
                    recnos[i] = db.Append(new DatabaseEntry(
                                              new byte[10240]));
                }

                // Remove some records from database.
                for (int i = 30; i < 100; i++)
                {
                    db.Delete(new DatabaseEntry(
                                  BitConverter.GetBytes(recnos[i])));
                }
            }
            else
            {
                // Add a lot of records into database in txn.
                for (int i = 0; i < 100; i++)
                {
                    recnos[i] = db.Append(new DatabaseEntry(
                                              new byte[10240]), txn);
                }

                // Remove some records from database in txn.
                for (int i = 30; i < 100; i++)
                {
                    db.Delete(new DatabaseEntry(
                                  BitConverter.GetBytes(recnos[i])), txn);
                }
            }
        }
        /*
         * Open environment, database and write data into database.
         * Generated log files are put under testHome.
         */
        public void Logging(string home, string dbName,
                            out DatabaseEnvironment env, out RecnoDatabase recnoDB)
        {
            string dbFileName = dbName + ".db";

            Configuration.ClearDir(home);

            // Open environment with logging subsystem.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create                    = true;
            envConfig.UseLogging                = true;
            envConfig.LogSystemCfg              = new LogConfig();
            envConfig.LogSystemCfg.FileMode     = 755;
            envConfig.LogSystemCfg.ZeroOnCreate = true;
            envConfig.UseMPool                  = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            /*
             * Open recno database, write 100000 records into
             * the database and close it.
             */
            RecnoDatabaseConfig recnoConfig =
                new RecnoDatabaseConfig();

            recnoConfig.Creation = CreatePolicy.IF_NEEDED;
            recnoConfig.Env      = env;
            // The db needs mpool to open.
            recnoConfig.NoMMap = false;
            recnoDB            = RecnoDatabase.Open(dbFileName,
                                                    recnoConfig);
            for (int i = 0; i < 1000; i++)
            {
                recnoDB.Append(new DatabaseEntry(
                                   ASCIIEncoding.ASCII.GetBytes("key")));
            }
        }