public void PutRecordCase1(QueueDatabase db, Transaction txn) { byte[] bigArray = new byte[4000]; for (int i = 1; i <= 100; i++) { if (txn == null) { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes(i))); } else { db.Put(new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(BitConverter.GetBytes(i)), txn); } } DatabaseEntry key = new DatabaseEntry(BitConverter.GetBytes((int)100)); for (int i = 100; i <= 500; i++) { if (txn == null) { db.Put(key, new DatabaseEntry(bigArray)); } else { db.Put(key, new DatabaseEntry(bigArray), txn); } } }
public void TestDeleteMultiple() { testName = "TestDeleteMultiple"; SetUpTest(true); QueueDatabaseConfig dbConfig = new QueueDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.ExtentSize = 1024; dbConfig.Length = 270; QueueDatabase db = QueueDatabase.Open(testHome + "/" + testName + ".db", dbConfig); List <uint> rList = new List <uint>(); List <DatabaseEntry> kList = new List <DatabaseEntry>(); List <DatabaseEntry> vList = new List <DatabaseEntry>(); DatabaseEntry key, data; for (uint i = 1; i <= 100; i++) { key = new DatabaseEntry(BitConverter.GetBytes(i)); data = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes( "data" + i.ToString() + Configuration.RandomString(256))); rList.Add(i); kList.Add(key); vList.Add(data); db.Put(key, data); } // Bulk delete all records with recno in rList. db.Delete(new MultipleDatabaseEntry(rList)); Cursor cursor = db.Cursor(); Assert.IsFalse(cursor.MoveFirst()); /* * Bulk insert records whose key bulk buffer is * constructed by recno lists, then delete all. */ db.Put(new MultipleDatabaseEntry(rList), new MultipleDatabaseEntry(vList, false)); Assert.IsTrue(cursor.MoveFirst()); db.Delete(new MultipleDatabaseEntry(kList, true)); Assert.IsFalse(cursor.MoveFirst()); /* * Bulk insert records whose key bulk buffer is * constructed by DatabaseEntry lists, then delete all. */ db.Put(new MultipleDatabaseEntry(kList, true), new MultipleDatabaseEntry(vList, false)); Assert.IsTrue(cursor.MoveFirst()); db.Delete(new MultipleDatabaseEntry(kList, true)); Assert.IsFalse(cursor.MoveFirst()); cursor.Close(); db.Close(); }
public void TestPutToQueue() { KeyValuePair <DatabaseEntry, DatabaseEntry> pair; testName = "TestPutQueue"; testHome = testFixtureHome + "/" + testName; string queueDBFileName = testHome + "/" + testName + ".db"; Configuration.ClearDir(testHome); QueueDatabaseConfig queueConfig = new QueueDatabaseConfig(); queueConfig.Length = 512; queueConfig.Creation = CreatePolicy.ALWAYS; using (QueueDatabase queueDB = QueueDatabase.Open( queueDBFileName, queueConfig)) { DatabaseEntry key = new DatabaseEntry(); key.Data = BitConverter.GetBytes((int)100); DatabaseEntry data = new DatabaseEntry( BitConverter.GetBytes((int)1)); queueDB.Put(key, data); pair = queueDB.GetBoth(key, data); } }
public void TestDeleteMultipleKey() { testName = "TestDeleteMultipleKey"; SetUpTest(true); QueueDatabaseConfig dbConfig = new QueueDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.ExtentSize = 1024; dbConfig.Length = 520; QueueDatabase db = QueueDatabase.Open(testHome + "/" + testName + ".db", dbConfig); List <KeyValuePair <DatabaseEntry, DatabaseEntry> > pList = new List <KeyValuePair <DatabaseEntry, DatabaseEntry> >(); DatabaseEntry key, data; for (uint i = 1; i <= 100; i++) { key = new DatabaseEntry( BitConverter.GetBytes(i)); data = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes( "data" + i.ToString() + Configuration.RandomString(512))); pList.Add(new KeyValuePair < DatabaseEntry, DatabaseEntry>(key, data)); db.Put(key, data); } // Create key/value pair bulk buffer and delete all. db.Delete(new MultipleKeyDatabaseEntry(pList, true)); // Verify that the database is empty. Assert.AreEqual(0, db.Truncate()); db.Close(); }
public void TestPutMultiple() { testName = "TestPutMultiple"; SetUpTest(true); QueueDatabaseConfig dbConfig = new QueueDatabaseConfig(); dbConfig.Creation = CreatePolicy.IF_NEEDED; dbConfig.ExtentSize = 1024; dbConfig.Length = 520; dbConfig.PadByte = 0; QueueDatabase db = QueueDatabase.Open(testHome + "/" + testName + ".db", dbConfig); List <uint> kList = new List <uint>(); List <DatabaseEntry> vList = new List <DatabaseEntry>(); DatabaseEntry key, data; for (uint i = 1; i <= 9; i++) { key = new DatabaseEntry(BitConverter.GetBytes(i)); data = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes("data" + i + Configuration.RandomString(512))); kList.Add(i); vList.Add(data); } // Create bulk buffer for recno based keys. MultipleDatabaseEntry kBuff = new MultipleDatabaseEntry(kList); Assert.IsTrue(kBuff.Recno); int val = 0; foreach (DatabaseEntry dbt in kBuff) { Assert.AreEqual( BitConverter.GetBytes(kList[val]), dbt.Data); val++; } Assert.AreEqual(9, val); // Create bulk buffer for data. MultipleDatabaseEntry vBuff = new MultipleDatabaseEntry(vList, false); /* * Create recno bulk buffer from another recno bulk * buffer. */ MultipleDatabaseEntry kBuff1 = new MultipleDatabaseEntry(kBuff.Data, kBuff.Recno); val = 0; foreach (DatabaseEntry dbt in kBuff1) { Assert.AreEqual( BitConverter.GetBytes(kList[val]), dbt.Data); val++; } Assert.AreEqual(9, val); // Bulk insert to database with key and value buffers. db.Put(kBuff, vBuff); Cursor cursor = db.Cursor(); KeyValuePair <DatabaseEntry, DatabaseEntry> pair; val = 0; while (cursor.MoveNext()) { pair = cursor.Current; Assert.AreEqual( BitConverter.GetBytes(kList[val]), pair.Key.Data); for (int i = 0; i < 520; i++) { if (i < vList[val].Data.Length) { Assert.AreEqual(vList[val].Data[i], pair.Value.Data[i]); } else { // The pad byte is 0. Assert.AreEqual(0, pair.Value.Data[i]); } } Assert.IsFalse(cursor.MoveNextDuplicate()); val++; } Assert.AreEqual(9, val); cursor.Close(); db.Close(); }