示例#1
0
        public void OpenSecQueueDB(string className,
                                   string funName, string dbFileName, string dbSecFileName)
        {
            XmlElement xmlElem = Configuration.TestSetUp(
                className, funName);

            // Open a primary queue database.
            QueueDatabaseConfig primaryDBConfig =
                new QueueDatabaseConfig();

            primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
            QueueDatabase primaryDB;

            /*
             * If secondary database name is given, the primary
             * database is also opened with database name.
             */
            primaryDB = QueueDatabase.Open(dbFileName,
                                           primaryDBConfig);

            try
            {
                // Open a new secondary database.
                SecondaryQueueDatabaseConfig secQueueDBConfig =
                    new SecondaryQueueDatabaseConfig(
                        primaryDB, null);
                SecondaryQueueDatabaseConfigTest.Config(
                    xmlElem, ref secQueueDBConfig, false);
                secQueueDBConfig.Creation =
                    CreatePolicy.IF_NEEDED;

                SecondaryQueueDatabase secQueueDB;
                secQueueDB = SecondaryQueueDatabase.Open(
                    dbSecFileName, secQueueDBConfig);

                // Close the secondary database.
                secQueueDB.Close();

                // Open the existing secondary database.
                SecondaryDatabaseConfig secDBConfig =
                    new SecondaryQueueDatabaseConfig(
                        primaryDB, null);

                SecondaryDatabase secDB;
                secDB = SecondaryQueueDatabase.Open(
                    dbSecFileName, secDBConfig);

                // Close secondary database.
                secDB.Close();
            }
            catch (DatabaseException)
            {
                throw new TestException();
            }
            finally
            {
                // Close primary database.
                primaryDB.Close();
            }
        }
示例#2
0
        public void OpenSecQueueDBWithinTxn(string className,
                                            string funName, string home, string dbFileName,
                                            string dbSecFileName)
        {
            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 queue database.
            Transaction         openDBTxn = env.BeginTransaction();
            QueueDatabaseConfig dbConfig  =
                new QueueDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env      = env;
            QueueDatabase db = QueueDatabase.Open(
                dbFileName, dbConfig, openDBTxn);

            openDBTxn.Commit();

            // Open a secondary queue database.
            Transaction openSecTxn = env.BeginTransaction();
            SecondaryQueueDatabaseConfig secDBConfig =
                new SecondaryQueueDatabaseConfig(db,
                                                 new SecondaryKeyGenDelegate(SecondaryKeyGen));

            SecondaryQueueDatabaseConfigTest.Config(xmlElem,
                                                    ref secDBConfig, true);
            secDBConfig.Env = env;
            SecondaryQueueDatabase secDB;

            secDB = SecondaryQueueDatabase.Open(
                dbSecFileName, 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;

            secExDB = SecondaryQueueDatabase.Open(
                dbSecFileName, secConfig, secTxn);

            secExDB.Close();
            secTxn.Commit();

            db.Close();
            env.Close();
        }