示例#1
0
        public void PutRecordCase1(HeapDatabase db, Transaction txn)
        {
            byte[]       bigArray = new byte[4000];
            HeapRecordId rid      = new HeapRecordId(2, 0);

            for (int i = 1; i <= 100; i++)
            {
                if (txn == null)
                {
                    rid = db.Append(
                        new DatabaseEntry(BitConverter.GetBytes(i)));
                }
                else
                {
                    rid = db.Append(
                        new DatabaseEntry(BitConverter.GetBytes(i)), txn);
                }
            }
            DatabaseEntry key = new DatabaseEntry(rid.toArray());

            for (int i = 100; i <= 500; i++)
            {
                if (txn == null)
                {
                    db.Put(key, new DatabaseEntry(bigArray));
                }
                else
                {
                    db.Put(key, new DatabaseEntry(bigArray), txn);
                }
            }
        }
示例#2
0
        public void GetCursur(string dbFileName, bool ifConfig)
        {
            HeapDatabaseConfig dbConfig = new HeapDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            HeapDatabase db  = HeapDatabase.Open(dbFileName, dbConfig);
            HeapRecordId rid = db.Append(
                new DatabaseEntry(BitConverter.GetBytes((int)1)));
            Cursor       cursor;
            CursorConfig cursorConfig = new CursorConfig();

            cursorConfig.Priority = CachePriority.HIGH;
            if (ifConfig == false)
            {
                cursor = db.Cursor();
            }
            else
            {
                cursor = db.Cursor(cursorConfig);
            }
            cursor.Add(new KeyValuePair <DatabaseEntry, DatabaseEntry>(
                           new DatabaseEntry(rid.toArray()),
                           new DatabaseEntry(BitConverter.GetBytes((int)2))));
            Cursor dupCursor = cursor.Duplicate(false);

            Assert.IsNull(dupCursor.Current.Key);
            if (ifConfig)
            {
                Assert.AreEqual(CachePriority.HIGH, dupCursor.Priority);
            }
            dupCursor.Close();
            cursor.Close();
            db.Close();
        }
示例#3
0
        public void TestAppendWithoutTxn()
        {
            testName = "TestAppendWithoutTxn";
            SetUpTest(true);
            string heapDBFileName = testHome + "/" + testName + ".db";


            HeapDatabaseConfig heapConfig = new HeapDatabaseConfig();

            heapConfig.Creation = CreatePolicy.ALWAYS;
            HeapDatabase heapDB = HeapDatabase.Open(
                heapDBFileName, heapConfig);

            byte[] byteArr = new byte[4];
            byteArr = BitConverter.GetBytes((int)1);
            DatabaseEntry data = new DatabaseEntry(byteArr);
            HeapRecordId  rid  = heapDB.Append(data);

            // Confirm that the record lives on a page larger than 0.
            Assert.AreNotEqual(0, rid.PageNumber);

            // Confirm that the record exists in the database.
            DatabaseEntry key = new DatabaseEntry(rid.toArray());

            Assert.IsTrue(heapDB.Exists(key));
            heapDB.Close();
        }
示例#4
0
        public void TestPutHeap()
        {
            KeyValuePair <DatabaseEntry, DatabaseEntry> pair;

            testName = "TestPutHeap";
            SetUpTest(true);
            string heapDBFileName = testHome + "/" +
                                    testName + ".db";

            HeapDatabaseConfig heapConfig =
                new HeapDatabaseConfig();

            heapConfig.Creation = CreatePolicy.ALWAYS;
            using (HeapDatabase heapDB = HeapDatabase.Open(
                       heapDBFileName, heapConfig)) {
                DatabaseEntry data = new DatabaseEntry(
                    BitConverter.GetBytes((int)1));
                HeapRecordId  rid = heapDB.Append(data);
                DatabaseEntry key = new DatabaseEntry(rid.toArray());
                data = new DatabaseEntry(BitConverter.GetBytes((int)2));
                heapDB.Put(key, data);
                pair = heapDB.GetBoth(key, data);
            }
        }