summaryrefslogtreecommitdiff
path: root/db/test/txn001.tcl
blob: 26795ca39747b3fdc8a301d7bc947d66f15fc6a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1996-2003
#	Sleepycat Software.  All rights reserved.
#
# $Id: txn001.tcl,v 11.37 2003/01/08 05:54:13 bostic Exp $
#

# TEST	txn001
# TEST	Begin, commit, abort testing.
proc txn001 { {tnum "001"} { max 1024 } { ntxns 50 } } {
	source ./include.tcl
	global txn_curid
	global txn_maxid

	puts -nonewline "Txn$tnum: Basic begin, commit, abort"

	if { $tnum != "001"} {
		puts " (with ID wrap)"
	} else {
		puts ""
	}

	# Open environment
	env_cleanup $testdir

	set env [eval {berkdb_env -create -mode 0644 -txn \
	    -txn_max $max -home $testdir}]
	error_check_good evn_open [is_valid_env $env] TRUE
	error_check_good txn_id_set \
	    [ $env txn_id_set $txn_curid $txn_maxid ] 0
	txn001_suba $ntxns $env $tnum
	txn001_subb $ntxns $env $tnum
	txn001_subc $ntxns $env $tnum
	# Close and unlink the file
	error_check_good env_close:$env [$env close] 0
}

proc txn001_suba { ntxns env tnum } {
	source ./include.tcl

	# We will create a bunch of transactions and commit them.
	set txn_list {}
	set tid_list {}
	puts "\tTxn$tnum.a: Beginning/Committing $ntxns Transactions in $env"
	for { set i 0 } { $i < $ntxns } { incr i } {
		set txn [$env txn]
		error_check_good txn_begin [is_valid_txn $txn $env] TRUE

		lappend txn_list $txn

		set tid [$txn id]
		error_check_good tid_check [lsearch $tid_list $tid] -1

		lappend tid_list $tid
	}

	# Now commit them all
	foreach t $txn_list {
		error_check_good txn_commit:$t [$t commit] 0
	}
}

proc txn001_subb { ntxns env tnum } {
	# We will create a bunch of transactions and abort them.
	set txn_list {}
	set tid_list {}
	puts "\tTxn$tnum.b: Beginning/Aborting Transactions"
	for { set i 0 } { $i < $ntxns } { incr i } {
		set txn [$env txn]
		error_check_good txn_begin [is_valid_txn $txn $env] TRUE

		lappend txn_list $txn

		set tid [$txn id]
		error_check_good tid_check [lsearch $tid_list $tid] -1

		lappend tid_list $tid
	}

	# Now abort them all
	foreach t $txn_list {
		error_check_good txn_abort:$t [$t abort] 0
	}
}

proc txn001_subc { ntxns env tnum } {
	# We will create a bunch of transactions and commit them.
	set txn_list {}
	set tid_list {}
	puts "\tTxn$tnum.c: Beginning/Prepare/Committing Transactions"
	for { set i 0 } { $i < $ntxns } { incr i } {
		set txn [$env txn]
		error_check_good txn_begin [is_valid_txn $txn $env] TRUE

		lappend txn_list $txn

		set tid [$txn id]
		error_check_good tid_check [lsearch $tid_list $tid] -1

		lappend tid_list $tid
	}

	# Now prepare them all
	foreach t $txn_list {
		error_check_good txn_prepare:$t \
		    [$t prepare [make_gid global:$t]] 0
	}

	# Now commit them all
	foreach t $txn_list {
		error_check_good txn_commit:$t [$t commit] 0
	}

}