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(); } }
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(); } }