Exemplo n.º 1
0
        public void TestKeyExistException()
        {
            testName = "TestKeyExistException";
            SetUpTest(true);
            string dbFileName = testHome + "/" + testName + ".db";

            HashDatabaseConfig hashConfig = new HashDatabaseConfig();

            hashConfig.Creation   = CreatePolicy.ALWAYS;
            hashConfig.Duplicates = DuplicatesPolicy.SORTED;
            HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);

            // Put the same record into db twice.
            DatabaseEntry key, data;

            key  = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));
            try
            {
                hashDB.PutNoDuplicate(key, data);
                hashDB.PutNoDuplicate(key, data);
            }
            catch (KeyExistException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                hashDB.Close();
            }
        }
Exemplo n.º 2
0
        public void TestPutNoDuplicate()
        {
            testName = "TestPutNoDuplicate";
            SetUpTest(true);
            string dbFileName = testHome + "/" + testName + ".db";

            HashDatabaseConfig hashConfig =
                new HashDatabaseConfig();

            hashConfig.Creation   = CreatePolicy.ALWAYS;
            hashConfig.Duplicates = DuplicatesPolicy.SORTED;
            hashConfig.TableSize  = 20;
            HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);

            DatabaseEntry key, data;

            for (int i = 1; i <= 10; i++)
            {
                key  = new DatabaseEntry(BitConverter.GetBytes(i));
                data = new DatabaseEntry(BitConverter.GetBytes(i));
                hashDB.PutNoDuplicate(key, data);
            }

            Assert.IsTrue(hashDB.Exists(
                              new DatabaseEntry(BitConverter.GetBytes((int)5))));

            hashDB.Close();
        }
Exemplo n.º 3
0
        public void TestPutNoDuplicateWithUnsortedDuplicate()
        {
            testName = "TestPutNoDuplicateWithUnsortedDuplicate";
            SetUpTest(true);
            string dbFileName = testHome + "/" + testName + ".db";

            HashDatabaseConfig hashConfig = new HashDatabaseConfig();

            hashConfig.Creation    = CreatePolicy.ALWAYS;
            hashConfig.Duplicates  = DuplicatesPolicy.UNSORTED;
            hashConfig.ErrorPrefix = testName;

            HashDatabase  hashDB = HashDatabase.Open(dbFileName, hashConfig);
            DatabaseEntry key, data;

            key  = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));
            data = new DatabaseEntry(ASCIIEncoding.ASCII.GetBytes("1"));

            try
            {
                hashDB.PutNoDuplicate(key, data);
            }
            catch (DatabaseException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                hashDB.Close();
            }
        }
Exemplo n.º 4
0
        public void TestPutNoDuplicateWithTxn()
        {
            testName = "TestPutNoDuplicateWithTxn";
            testHome = testFixtureHome + "/" + testName;

            Configuration.ClearDir(testHome);

            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create     = true;
            envConfig.UseLogging = true;
            envConfig.UseMPool   = true;
            envConfig.UseTxns    = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);

            // Open a hash database within a transaction.
            Transaction        txn      = env.BeginTransaction();
            HashDatabaseConfig dbConfig = new HashDatabaseConfig();

            dbConfig.Creation   = CreatePolicy.IF_NEEDED;
            dbConfig.Duplicates = DuplicatesPolicy.SORTED;
            dbConfig.Env        = env;
            HashDatabase db = HashDatabase.Open(testName + ".db", dbConfig, txn);

            DatabaseEntry dbt = new DatabaseEntry(BitConverter.GetBytes((int)100));

            db.PutNoDuplicate(dbt, dbt, txn);
            try
            {
                db.PutNoDuplicate(dbt, dbt, txn);
            }
            catch (KeyExistException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                // Close all.
                db.Close();
                txn.Commit();
                env.Close();
            }
        }