• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/perl/BerkeleyDB/t/
1#!./perl -w
2
3use strict ;
4
5use lib 't' ;
6use BerkeleyDB; 
7use util ;
8
9print "1..58\n";
10
11my $Dfile = "dbhash.tmp";
12
13umask(0);
14
15{
16    # error cases
17
18    my $lex = new LexFile $Dfile ;
19    my %hash ;
20    my $value ;
21
22    my $home = "./fred" ;
23    ok 1, my $lexD = new LexDir($home);
24    ok 2, my $env = new BerkeleyDB::Env -Home => $home, @StdErrFile,
25				     -Flags => DB_CREATE| DB_INIT_MPOOL;
26    eval { $env->txn_begin() ; } ;
27    ok 3, $@ =~ /^BerkeleyDB Aborting: Transaction Manager not enabled at/ ;
28
29    eval { my $txn_mgr = $env->TxnMgr() ; } ;
30    ok 4, $@ =~ /^BerkeleyDB Aborting: Transaction Manager not enabled at/ ;
31    undef $env ;
32
33}
34
35{
36    # transaction - abort works
37
38    my $lex = new LexFile $Dfile ;
39    my %hash ;
40    my $value ;
41
42    my $home = "./fred" ;
43    ok 5, my $lexD = new LexDir($home);
44    ok 6, my $env = new BerkeleyDB::Env -Home => $home, @StdErrFile,
45				     -Flags => DB_CREATE|DB_INIT_TXN|
46					  	DB_INIT_MPOOL|DB_INIT_LOCK ;
47    ok 7, my $txn = $env->txn_begin() ;
48    ok 8, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
49                                      	       	-Flags     => DB_CREATE ,
50					       	-Env 	   => $env,
51					    	-Txn	   => $txn  ;
52
53    
54    ok 9, $txn->txn_commit() == 0 ;
55    ok 10, $txn = $env->txn_begin() ;
56    $db1->Txn($txn);
57
58    # create some data
59    my %data =  (
60		"red"	=> "boat",
61		"green"	=> "house",
62		"blue"	=> "sea",
63		) ;
64
65    my $ret = 0 ;
66    while (my ($k, $v) = each %data) {
67        $ret += $db1->db_put($k, $v) ;
68    }
69    ok 11, $ret == 0 ;
70
71    # should be able to see all the records
72
73    ok 12, my $cursor = $db1->db_cursor() ;
74    my ($k, $v) = ("", "") ;
75    my $count = 0 ;
76    # sequence forwards
77    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
78        ++ $count ;
79    }
80    ok 13, $count == 3 ;
81    undef $cursor ;
82
83    # now abort the transaction
84    ok 14, $txn->txn_abort() == 0 ;
85
86    # there shouldn't be any records in the database
87    $count = 0 ;
88    # sequence forwards
89    ok 15, $cursor = $db1->db_cursor() ;
90    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
91        ++ $count ;
92    }
93    ok 16, $count == 0 ;
94
95    my $stat = $env->txn_stat() ;
96    ok 17, $stat->{'st_naborts'} == 1 ;
97
98    undef $txn ;
99    undef $cursor ;
100    undef $db1 ;
101    undef $env ;
102    untie %hash ;
103}
104
105{
106    # transaction - abort works via txnmgr
107
108    my $lex = new LexFile $Dfile ;
109    my %hash ;
110    my $value ;
111
112    my $home = "./fred" ;
113    ok 18, my $lexD = new LexDir($home);
114    ok 19, my $env = new BerkeleyDB::Env -Home => $home, @StdErrFile,
115				     -Flags => DB_CREATE|DB_INIT_TXN|
116					  	DB_INIT_MPOOL|DB_INIT_LOCK ;
117    ok 20, my $txn_mgr = $env->TxnMgr() ;
118    ok 21, my $txn = $txn_mgr->txn_begin() ;
119    ok 22, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
120                                      	       	-Flags     => DB_CREATE ,
121					       	-Env 	   => $env,
122					    	-Txn	   => $txn  ;
123
124    ok 23, $txn->txn_commit() == 0 ;
125    ok 24, $txn = $env->txn_begin() ;
126    $db1->Txn($txn);
127    
128    # create some data
129    my %data =  (
130		"red"	=> "boat",
131		"green"	=> "house",
132		"blue"	=> "sea",
133		) ;
134
135    my $ret = 0 ;
136    while (my ($k, $v) = each %data) {
137        $ret += $db1->db_put($k, $v) ;
138    }
139    ok 25, $ret == 0 ;
140
141    # should be able to see all the records
142
143    ok 26, my $cursor = $db1->db_cursor() ;
144    my ($k, $v) = ("", "") ;
145    my $count = 0 ;
146    # sequence forwards
147    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
148        ++ $count ;
149    }
150    ok 27, $count == 3 ;
151    undef $cursor ;
152
153    # now abort the transaction
154    ok 28, $txn->txn_abort() == 0 ;
155
156    # there shouldn't be any records in the database
157    $count = 0 ;
158    # sequence forwards
159    ok 29, $cursor = $db1->db_cursor() ;
160    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
161        ++ $count ;
162    }
163    ok 30, $count == 0 ;
164
165    my $stat = $txn_mgr->txn_stat() ;
166    ok 31, $stat->{'st_naborts'} == 1 ;
167
168    undef $txn ;
169    undef $cursor ;
170    undef $db1 ;
171    undef $txn_mgr ;
172    undef $env ;
173    untie %hash ;
174}
175
176{
177    # transaction - commit works
178
179    my $lex = new LexFile $Dfile ;
180    my %hash ;
181    my $value ;
182
183    my $home = "./fred" ;
184    ok 32, my $lexD = new LexDir($home);
185    ok 33, my $env = new BerkeleyDB::Env -Home => $home, @StdErrFile,
186				     -Flags => DB_CREATE|DB_INIT_TXN|
187					  	DB_INIT_MPOOL|DB_INIT_LOCK ;
188    ok 34, my $txn = $env->txn_begin() ;
189    ok 35, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
190                                      	       	-Flags     => DB_CREATE ,
191					       	-Env 	   => $env,
192					    	-Txn	   => $txn  ;
193
194    
195    ok 36, $txn->txn_commit() == 0 ;
196    ok 37, $txn = $env->txn_begin() ;
197    $db1->Txn($txn);
198
199    # create some data
200    my %data =  (
201		"red"	=> "boat",
202		"green"	=> "house",
203		"blue"	=> "sea",
204		) ;
205
206    my $ret = 0 ;
207    while (my ($k, $v) = each %data) {
208        $ret += $db1->db_put($k, $v) ;
209    }
210    ok 38, $ret == 0 ;
211
212    # should be able to see all the records
213
214    ok 39, my $cursor = $db1->db_cursor() ;
215    my ($k, $v) = ("", "") ;
216    my $count = 0 ;
217    # sequence forwards
218    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
219        ++ $count ;
220    }
221    ok 40, $count == 3 ;
222    undef $cursor ;
223
224    # now commit the transaction
225    ok 41, $txn->txn_commit() == 0 ;
226
227    $count = 0 ;
228    # sequence forwards
229    ok 42, $cursor = $db1->db_cursor() ;
230    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
231        ++ $count ;
232    }
233    ok 43, $count == 3 ;
234
235    my $stat = $env->txn_stat() ;
236    ok 44, $stat->{'st_naborts'} == 0 ;
237
238    undef $txn ;
239    undef $cursor ;
240    undef $db1 ;
241    undef $env ;
242    untie %hash ;
243}
244
245{
246    # transaction - commit works via txnmgr
247
248    my $lex = new LexFile $Dfile ;
249    my %hash ;
250    my $value ;
251
252    my $home = "./fred" ;
253    ok 45, my $lexD = new LexDir($home);
254    ok 46, my $env = new BerkeleyDB::Env -Home => $home, @StdErrFile,
255				     -Flags => DB_CREATE|DB_INIT_TXN|
256					  	DB_INIT_MPOOL|DB_INIT_LOCK ;
257    ok 47, my $txn_mgr = $env->TxnMgr() ;
258    ok 48, my $txn = $txn_mgr->txn_begin() ;
259    ok 49, my $db1 = tie %hash, 'BerkeleyDB::Hash', -Filename => $Dfile,
260                                      	       	-Flags     => DB_CREATE ,
261					       	-Env 	   => $env,
262					    	-Txn	   => $txn  ;
263
264    ok 50, $txn->txn_commit() == 0 ;
265    ok 51, $txn = $env->txn_begin() ;
266    $db1->Txn($txn);
267    
268    # create some data
269    my %data =  (
270		"red"	=> "boat",
271		"green"	=> "house",
272		"blue"	=> "sea",
273		) ;
274
275    my $ret = 0 ;
276    while (my ($k, $v) = each %data) {
277        $ret += $db1->db_put($k, $v) ;
278    }
279    ok 52, $ret == 0 ;
280
281    # should be able to see all the records
282
283    ok 53, my $cursor = $db1->db_cursor() ;
284    my ($k, $v) = ("", "") ;
285    my $count = 0 ;
286    # sequence forwards
287    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
288        ++ $count ;
289    }
290    ok 54, $count == 3 ;
291    undef $cursor ;
292
293    # now commit the transaction
294    ok 55, $txn->txn_commit() == 0 ;
295
296    $count = 0 ;
297    # sequence forwards
298    ok 56, $cursor = $db1->db_cursor() ;
299    while ($cursor->c_get($k, $v, DB_NEXT) == 0) {
300        ++ $count ;
301    }
302    ok 57, $count == 3 ;
303
304    my $stat = $txn_mgr->txn_stat() ;
305    ok 58, $stat->{'st_naborts'} == 0 ;
306
307    undef $txn ;
308    undef $cursor ;
309    undef $db1 ;
310    undef $txn_mgr ;
311    undef $env ;
312    untie %hash ;
313}
314
315