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

View file

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

View file

@ -2,21 +2,73 @@ require 'test_helper'
class TxnTest < Test::Unit::TestCase
# cTxnStat = rb_define_class_under(mBdb,"TxnStat",rb_cObject);
# rb_define_method(cTxnStat,"[]",stat_aref,1);
#
# cTxnStatActive =
# rb_define_class_under(cTxnStat,"Active",rb_cObject);
# rb_define_method(cTxnStatActive,"[]",stat_aref,1);
#
# cTxn = rb_define_class_under(mBdb,"Txn",rb_cObject);
# rb_define_method(cTxn,"commit",txn_commit,1);
# 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
def setup
mkdir File.join(File.dirname(__FILE__), 'tmp')
@env = Bdb::Env.new(0)
env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist.
Bdb::DB_INIT_TXN | # Initialize transactions
Bdb::DB_INIT_LOCK | # Initialize locking.
Bdb::DB_INIT_LOG | # Initialize logging
Bdb::DB_INIT_MPOOL # Initialize the in-memory cache.
@env.open(File.join(File.dirname(__FILE__), 'tmp'), env_flags, 0);
@db = @env.db
@db.open(nil, 'db1.db', nil, Bdb::Db::BTREE, Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, 0)
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