1#!./perl -w 2 3use strict ; 4 5use lib 't' ; 6use BerkeleyDB; 7use util ; 8 9print "1..44\n"; 10 11my $Dfile = "dbhash.tmp"; 12my $home = "./fred" ; 13 14umask(0); 15 16{ 17 # closing a database & an environment in the correct order. 18 my $lex = new LexFile $Dfile ; 19 my %hash ; 20 my $status ; 21 22 ok 1, my $lexD = new LexDir($home); 23 ok 2, my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile, 24 -Flags => DB_CREATE|DB_INIT_TXN| 25 DB_INIT_MPOOL|DB_INIT_LOCK ; 26 27 ok 3, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 28 -Flags => DB_CREATE , 29 -Env => $env; 30 31 ok 4, $db1->db_close() == 0 ; 32 33 eval { $status = $env->db_appexit() ; } ; 34 ok 5, $status == 0 ; 35 ok 6, $@ eq "" ; 36 #print "[$@]\n" ; 37 38} 39 40{ 41 # closing an environment with an open database 42 my $lex = new LexFile $Dfile ; 43 my %hash ; 44 45 ok 7, my $lexD = new LexDir($home); 46 ok 8, my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile, 47 -Flags => DB_CREATE|DB_INIT_TXN| 48 DB_INIT_MPOOL|DB_INIT_LOCK ; 49 50 ok 9, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 51 -Flags => DB_CREATE , 52 -Env => $env; 53 54 eval { $env->db_appexit() ; } ; 55 ok 10, $@ =~ /BerkeleyDB Aborting: attempted to close an environment with 1 open database/ ; 56 #print "[$@]\n" ; 57 58 undef $db1 ; 59 untie %hash ; 60 undef $env ; 61} 62 63{ 64 # closing a transaction & a database 65 my $lex = new LexFile $Dfile ; 66 my %hash ; 67 my $status ; 68 69 ok 11, my $lexD = new LexDir($home); 70 ok 12, my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile, 71 -Flags => DB_CREATE|DB_INIT_TXN| 72 DB_INIT_MPOOL|DB_INIT_LOCK ; 73 74 ok 13, my $txn = $env->txn_begin() ; 75 ok 14, my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 76 -Flags => DB_CREATE , 77 -Env => $env, 78 -Txn => $txn ; 79 80 ok 15, $txn->txn_commit() == 0 ; 81 eval { $status = $db->db_close() ; } ; 82 ok 16, $status == 0 ; 83 ok 17, $@ eq "" ; 84 #print "[$@]\n" ; 85 eval { $status = $env->db_appexit() ; } ; 86 ok 18, $status == 0 ; 87 ok 19, $@ eq "" ; 88 #print "[$@]\n" ; 89} 90 91{ 92 # closing a database with an open transaction 93 my $lex = new LexFile $Dfile ; 94 my %hash ; 95 96 ok 20, my $lexD = new LexDir($home); 97 ok 21, my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile, 98 -Flags => DB_CREATE|DB_INIT_TXN| 99 DB_INIT_MPOOL|DB_INIT_LOCK ; 100 101 ok 22, my $txn = $env->txn_begin() ; 102 ok 23, my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 103 -Flags => DB_CREATE , 104 -Env => $env, 105 -Txn => $txn ; 106 107 eval { $db->db_close() ; } ; 108 ok 24, $@ =~ /BerkeleyDB Aborting: attempted to close a database while a transaction was still open at/ ; 109 #print "[$@]\n" ; 110 $txn->txn_abort(); 111 $db->db_close(); 112} 113 114{ 115 # closing a cursor & a database 116 my $lex = new LexFile $Dfile ; 117 my %hash ; 118 my $status ; 119 ok 25, my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 120 -Flags => DB_CREATE ; 121 ok 26, my $cursor = $db->db_cursor() ; 122 ok 27, $cursor->c_close() == 0 ; 123 eval { $status = $db->db_close() ; } ; 124 ok 28, $status == 0 ; 125 ok 29, $@ eq "" ; 126 #print "[$@]\n" ; 127} 128 129{ 130 # closing a database with an open cursor 131 my $lex = new LexFile $Dfile ; 132 my %hash ; 133 ok 30, my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 134 -Flags => DB_CREATE ; 135 ok 31, my $cursor = $db->db_cursor() ; 136 eval { $db->db_close() ; } ; 137 ok 32, $@ =~ /\QBerkeleyDB Aborting: attempted to close a database with 1 open cursor(s) at/; 138 #print "[$@]\n" ; 139} 140 141{ 142 # closing a transaction & a cursor 143 my $lex = new LexFile $Dfile ; 144 my %hash ; 145 my $status ; 146 my $home = 'fred1'; 147 148 ok 33, my $lexD = new LexDir($home); 149 ok 34, my $env = new BerkeleyDB::Env -Home => $home,@StdErrFile, 150 -Flags => DB_CREATE|DB_INIT_TXN| 151 DB_INIT_MPOOL|DB_INIT_LOCK ; 152 ok 35, my $txn = $env->txn_begin() ; 153 ok 36, my $db = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile, 154 -Flags => DB_CREATE , 155 -Env => $env, 156 -Txn => $txn ; 157 ok 37, my $cursor = $db->db_cursor() ; 158 eval { $status = $cursor->c_close() ; } ; 159 ok 38, $status == 0 ; 160 ok 39, ($status = $txn->txn_commit()) == 0 ; 161 ok 40, $@ eq "" ; 162 eval { $status = $db->db_close() ; } ; 163 ok 41, $status == 0 ; 164 ok 42, $@ eq "" ; 165 #print "[$@]\n" ; 166 eval { $status = $env->db_appexit() ; } ; 167 ok 43, $status == 0 ; 168 ok 44, $@ eq "" ; 169 #print "[$@]\n" ; 170} 171 172