Esempio n. 1
0
        public void TestAppendWithoutTxn()
        {
            testName = "TestAppendWithoutTxn";
            testHome = testFixtureHome + "/" + testName;
            string queueDBFileName = testHome + "/" + testName + ".db";

            Configuration.ClearDir(testHome);

            QueueDatabaseConfig queueConfig = new QueueDatabaseConfig();

            queueConfig.Creation = CreatePolicy.ALWAYS;
            queueConfig.Length   = 1000;
            QueueDatabase queueDB = QueueDatabase.Open(
                queueDBFileName, queueConfig);

            byte[] byteArr = new byte[4];
            byteArr = BitConverter.GetBytes((int)1);
            DatabaseEntry data  = new DatabaseEntry(byteArr);
            uint          recno = queueDB.Append(data);

            // Confirm that the recno is larger than 0.
            Assert.AreNotEqual(0, recno);

            // Confirm that the record exists in the database.
            byteArr = BitConverter.GetBytes(recno);
            DatabaseEntry key = new DatabaseEntry();

            key.Data = byteArr;
            Assert.IsTrue(queueDB.Exists(key));
            queueDB.Close();
        }
Esempio n. 2
0
        public void TestAppendWithTxn()
        {
            testName = "TestAppendWithTxn";
            testHome = testFixtureHome + "/" + testName;
            string queueDBFileName = testHome + "/" + testName + ".db";
            string queueDBName     =
                Path.GetFileNameWithoutExtension(queueDBFileName);

            Configuration.ClearDir(testHome);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create   = true;
            envConfig.UseTxns  = true;
            envConfig.UseMPool = true;

            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            Transaction txn = env.BeginTransaction();

            QueueDatabaseConfig queueConfig = new QueueDatabaseConfig();

            queueConfig.Creation = CreatePolicy.ALWAYS;
            queueConfig.Env      = env;
            queueConfig.Length   = 1000;

            /* If environmnet home is set, the file name in
             * Open() is the relative path.
             */
            QueueDatabase queueDB = QueueDatabase.Open(
                queueDBName, queueConfig, txn);
            DatabaseEntry data;
            int           i = 1000;

            try
            {
                while (i > 0)
                {
                    data = new DatabaseEntry(
                        BitConverter.GetBytes(i));
                    queueDB.Append(data, txn);
                    i--;
                }
                txn.Commit();
            }
            catch
            {
                txn.Abort();
            }
            finally
            {
                queueDB.Close();
                env.Close();
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void PutQueue(byte[] data, Transaction txn = null)
        {
            QueueDatabase queue = db as QueueDatabase;

            if (null != queue)
            {
                DatabaseEntry v = new DatabaseEntry(data);
                queue.Append(v, txn);
            }
        }
Esempio n. 5
0
        public void TestConsumeWithoutTxn()
        {
            testName = "TestConsumeWithoutTxn";
            testHome = testFixtureHome + "/" + testName;
            string queueDBFileName = testHome + "/" +
                                     testName + ".db";

            Configuration.ClearDir(testHome);

            QueueDatabaseConfig queueConfig =
                new QueueDatabaseConfig();

            queueConfig.Creation    = CreatePolicy.ALWAYS;
            queueConfig.ErrorPrefix = testName;
            queueConfig.Length      = 1000;

            QueueDatabase queueDB = QueueDatabase.Open(
                queueDBFileName, queueConfig);
            DatabaseEntry data = new DatabaseEntry(
                ASCIIEncoding.ASCII.GetBytes("data"));

            queueDB.Append(data);

            DatabaseEntry consumeData = new DatabaseEntry();
            KeyValuePair <uint, DatabaseEntry> pair = queueDB.Consume(false);

            try
            {
                DatabaseEntry key =
                    new DatabaseEntry(BitConverter.GetBytes(pair.Key));
                queueDB.Get(key);
            }
            catch (NotFoundException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                queueDB.Close();
            }
        }
Esempio n. 6
0
        public void TestConsumeWithTxn()
        {
            testName = "TestConsumeWithTxn";
            testHome = testFixtureHome + "/" + testName;
            string queueDBFileName = testHome + "/" + testName + ".db";
            string queueDBName     = Path.GetFileName(queueDBFileName);

            Configuration.ClearDir(testHome);

            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create   = true;
            envConfig.UseTxns  = true;
            envConfig.UseMPool = true;

            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            Transaction txn = env.BeginTransaction();

            QueueDatabaseConfig queueConfig =
                new QueueDatabaseConfig();

            queueConfig.Creation = CreatePolicy.ALWAYS;
            queueConfig.Env      = env;
            queueConfig.Length   = 1000;
            QueueDatabase queueDB = QueueDatabase.Open(
                queueDBName, queueConfig, txn);

            int           i = 1;
            DatabaseEntry data;
            DatabaseEntry getData = new DatabaseEntry();

            while (i <= 10)
            {
                data = new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes(i.ToString()));
                queueDB.Append(data, txn);
                if (i == 5)
                {
                    getData = data;
                }
                i++;
            }

            KeyValuePair <uint, DatabaseEntry> pair = queueDB.Consume(false, txn);

            queueDB.Close();
            txn.Commit();
            env.Close();

            Database db = Database.Open(queueDBFileName,
                                        new QueueDatabaseConfig());

            try
            {
                DatabaseEntry key =
                    new DatabaseEntry(BitConverter.GetBytes(pair.Key));
                db.Get(key);
            }
            catch (NotFoundException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                db.Close();
            }
        }