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