Txn tests

This commit is contained in:
mattbauer 2008-12-30 16:30:03 -06:00
parent d30f0f3f80
commit c2cda84957
3 changed files with 70 additions and 16 deletions

View file

@ -512,6 +512,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
dbh->db=NULL; dbh->db=NULL;
dbh->aproc=Qnil; dbh->aproc=Qnil;
if ( dbh->env ) { if ( dbh->env ) {
if ( RTEST(ruby_debug) )
rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"db_close! removing",obj); rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"db_close! removing",obj);
rb_ary_delete(dbh->env->adb,obj); rb_ary_delete(dbh->env->adb,obj);
dbh->env = NULL; dbh->env = NULL;

View file

@ -30,6 +30,7 @@ class EnvTest < Test::Unit::TestCase
db = env.db db = env.db
assert_equal db, env.list_dbs.first assert_equal db, env.list_dbs.first
db.close(0)
end end
def test_set_and_get_timeout def test_set_and_get_timeout

View file

@ -2,21 +2,73 @@ require 'test_helper'
class TxnTest < Test::Unit::TestCase class TxnTest < Test::Unit::TestCase
# cTxnStat = rb_define_class_under(mBdb,"TxnStat",rb_cObject); def setup
# rb_define_method(cTxnStat,"[]",stat_aref,1); mkdir File.join(File.dirname(__FILE__), 'tmp')
# @env = Bdb::Env.new(0)
# cTxnStatActive = env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist.
# rb_define_class_under(cTxnStat,"Active",rb_cObject); Bdb::DB_INIT_TXN | # Initialize transactions
# rb_define_method(cTxnStatActive,"[]",stat_aref,1); Bdb::DB_INIT_LOCK | # Initialize locking.
# Bdb::DB_INIT_LOG | # Initialize logging
# cTxn = rb_define_class_under(mBdb,"Txn",rb_cObject); Bdb::DB_INIT_MPOOL # Initialize the in-memory cache.
# rb_define_method(cTxn,"commit",txn_commit,1); @env.open(File.join(File.dirname(__FILE__), 'tmp'), env_flags, 0);
# rb_define_method(cTxn,"abort",txn_abort,0);
# rb_define_method(cTxn,"discard",txn_discard,0);
# rb_define_method(cTxn,"tid",txn_id,0);
# rb_define_method(cTxn,"set_timeout",txn_set_timeout,2);
def test_x
@db = @env.db
@db.open(nil, 'db1.db', nil, Bdb::Db::BTREE, Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, 0)
end end
def teardown
@db.close(0)
@env.close
rm_rf File.join(File.dirname(__FILE__), 'tmp')
end
def test_commit
txn = @env.txn_begin(nil, 0)
@db.put(txn, 'key', 'value', 0)
txn.commit(0)
assert_equal 'value', @db.get(nil, 'key', nil, 0)
end
def test_abort
txn = @env.txn_begin(nil, 0)
@db.put(txn, 'key', 'value', 0)
txn.abort
assert_nil @db.get(nil, 'key', nil, 0)
end
def test_id
txn = @env.txn_begin(nil, 0)
@db.put(txn, 'key', 'value', 0)
assert txn.tid
txn.commit(0)
assert_equal 'value', @db.get(nil, 'key', nil, 0)
end
def test_timeout
txn = @env.txn_begin(nil, 0)
txn.set_timeout(10, Bdb::DB_SET_TXN_TIMEOUT)
@db.put(txn, 'key', 'value', 0)
txn.commit(0)
assert_equal 'value', @db.get(nil, 'key', nil, 0)
end
def test_stat
txn = @env.txn_begin(nil, 0)
@db.put(txn, 'key', 'value', 0)
txn.commit(0)
txn_stat = @env.txn_stat(0)
assert txn_stat
assert txn_stat['st_ncommits'] > 0
assert_equal 'value', @db.get(nil, 'key', nil, 0)
end
def test_stat_active
txn = @env.txn_begin(nil, 0)
@db.put(txn, 'key', 'value', 0)
txn_stat = @env.txn_stat(0)
txn.commit(0)
assert_equal 1, txn_stat['st_txnarray'].length
assert_equal 'value', @db.get(nil, 'key', nil, 0)
end
end end