Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / tcl / txn001.tcl
1 # See the file LICENSE for redistribution information.
2 #
3 # Copyright (c) 1996, 2012 Oracle and/or its affiliates.  All rights reserved.
4 #
5 # $Id$
6 #
7 # TEST  txn001
8 # TEST  Begin, commit, abort testing.
9 proc txn001 { {tnum "001"} { max 1024 } { ntxns 50 } } {
10         source ./include.tcl
11         global txn_curid
12         global txn_maxid
13
14         puts -nonewline "Txn$tnum: Basic begin, commit, abort"
15
16         if { $tnum != "001"} {
17                 puts " (with ID wrap)"
18         } else {
19                 puts ""
20         }
21
22         # Open environment
23         env_cleanup $testdir
24
25         set env [eval {berkdb_env -create -mode 0644 -txn \
26             -txn_max $max -home $testdir}]
27         error_check_good evn_open [is_valid_env $env] TRUE
28         error_check_good txn_id_set \
29             [ $env txn_id_set $txn_curid $txn_maxid ] 0
30         txn001_suba $ntxns $env $tnum
31         txn001_subb $ntxns $env $tnum
32         txn001_subc $ntxns $env $tnum
33         # Close and unlink the file
34         error_check_good env_close:$env [$env close] 0
35 }
36
37 proc txn001_suba { ntxns env tnum } {
38         source ./include.tcl
39
40         # We will create a bunch of transactions and commit them.
41         set txn_list {}
42         set tid_list {}
43         puts "\tTxn$tnum.a: Beginning/Committing $ntxns Transactions in $env"
44         for { set i 0 } { $i < $ntxns } { incr i } {
45                 set txn [$env txn]
46                 error_check_good txn_begin [is_valid_txn $txn $env] TRUE
47
48                 lappend txn_list $txn
49
50                 set tid [$txn id]
51                 error_check_good tid_check [lsearch $tid_list $tid] -1
52
53                 lappend tid_list $tid
54         }
55
56         # Now commit them all
57         foreach t $txn_list {
58                 error_check_good txn_commit:$t [$t commit] 0
59         }
60 }
61
62 proc txn001_subb { ntxns env tnum } {
63         # We will create a bunch of transactions and abort them.
64         set txn_list {}
65         set tid_list {}
66         puts "\tTxn$tnum.b: Beginning/Aborting Transactions"
67         for { set i 0 } { $i < $ntxns } { incr i } {
68                 set txn [$env txn]
69                 error_check_good txn_begin [is_valid_txn $txn $env] TRUE
70
71                 lappend txn_list $txn
72
73                 set tid [$txn id]
74                 error_check_good tid_check [lsearch $tid_list $tid] -1
75
76                 lappend tid_list $tid
77         }
78
79         # Now abort them all
80         foreach t $txn_list {
81                 error_check_good txn_abort:$t [$t abort] 0
82         }
83 }
84
85 proc txn001_subc { ntxns env tnum } {
86         # We will create a bunch of transactions and commit them.
87         set txn_list {}
88         set tid_list {}
89         puts "\tTxn$tnum.c: Beginning/Prepare/Committing Transactions"
90         for { set i 0 } { $i < $ntxns } { incr i } {
91                 set txn [$env txn]
92                 error_check_good txn_begin [is_valid_txn $txn $env] TRUE
93
94                 lappend txn_list $txn
95
96                 set tid [$txn id]
97                 error_check_good tid_check [lsearch $tid_list $tid] -1
98
99                 lappend tid_list $tid
100         }
101
102         # Now prepare them all
103         foreach t $txn_list {
104                 error_check_good txn_prepare:$t \
105                     [$t prepare [make_gid global:$t]] 0
106         }
107
108         # Now commit them all
109         foreach t $txn_list {
110                 error_check_good txn_commit:$t [$t commit] 0
111         }
112
113 }
114