summaryrefslogtreecommitdiff
path: root/storage/bdb/test/test061.tcl
blob: 65544e88deb6aaa692fa4548e03bf3439922836e (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# See the file LICENSE for redistribution information.
#
# Copyright (c) 1999-2002
#	Sleepycat Software.  All rights reserved.
#
# $Id: test061.tcl,v 11.18 2002/02/22 15:26:27 sandstro Exp $
#
# TEST	test061
# TEST	Test of txn abort and commit for in-memory databases.
# TEST	a) Put + abort: verify absence of data
# TEST	b) Put + commit: verify presence of data
# TEST	c) Overwrite + abort: verify that data is unchanged
# TEST	d) Overwrite + commit: verify that data has changed
# TEST	e) Delete + abort: verify that data is still present
# TEST	f) Delete + commit: verify that data has been deleted
proc test061 { method args } {
	global alphabet
	global encrypt
	global errorCode
	global passwd
	source ./include.tcl

	#
	# If we are using an env, then skip this test.  It needs its own.
	set eindex [lsearch -exact $args "-env"]
	if { $eindex != -1 } {
		incr eindex
		set env [lindex $args $eindex]
		puts "Test061 skipping for env $env"
		return
	}
	set args [convert_args $method $args]
	set omethod [convert_method $method]
	if { [is_queueext $method] == 1} {
		puts "Test061 skipping for method $method"
		return
	}
	set encargs ""
	set args [split_encargs $args encargs]

	puts "Test061: Transaction abort and commit test for in-memory data."
	puts "Test061: $method $args"

	set key "key"
	set data "data"
	set otherdata "otherdata"
	set txn ""
	set flags ""
	set gflags ""

	if { [is_record_based $method] == 1} {
		set key 1
		set gflags " -recno"
	}

	puts "\tTest061: Create environment and $method database."
	env_cleanup $testdir

	# create environment
	set eflags "-create -txn $encargs -home $testdir"
	set dbenv [eval {berkdb_env} $eflags]
	error_check_good dbenv [is_valid_env $dbenv] TRUE

	# db open -- no file specified, in-memory database
	set flags "-auto_commit -create $args $omethod"
	set db [eval {berkdb_open -env} $dbenv $flags]
	error_check_good dbopen [is_valid_db $db] TRUE

	# Here we go with the six test cases.  Since we need to verify
	# a different thing each time, and since we can't just reuse
	# the same data if we're to test overwrite, we just
	# plow through rather than writing some impenetrable loop code;
	# each of the cases is only a few lines long, anyway.

	puts "\tTest061.a: put/abort"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# put a key
	set ret [eval {$db put} -txn $txn {$key [chop_data $method $data]}]
	error_check_good db_put $ret 0

	# check for existence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret [list [list $key [pad_data $method $data]]]

	# abort
	error_check_good txn_abort [$txn abort] 0

	# check for *non*-existence
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret {}

	puts "\tTest061.b: put/commit"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# put a key
	set ret [eval {$db put} -txn $txn {$key [chop_data $method $data]}]
	error_check_good db_put $ret 0

	# check for existence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret [list [list $key [pad_data $method $data]]]

	# commit
	error_check_good txn_commit [$txn commit] 0

	# check again for existence
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret [list [list $key [pad_data $method $data]]]

	puts "\tTest061.c: overwrite/abort"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# overwrite {key,data} with {key,otherdata}
	set ret [eval {$db put} -txn $txn {$key [chop_data $method $otherdata]}]
	error_check_good db_put $ret 0

	# check for existence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret \
	    [list [list $key [pad_data $method $otherdata]]]

	# abort
	error_check_good txn_abort [$txn abort] 0

	# check that data is unchanged ($data not $otherdata)
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret [list [list $key [pad_data $method $data]]]

	puts "\tTest061.d: overwrite/commit"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# overwrite {key,data} with {key,otherdata}
	set ret [eval {$db put} -txn $txn {$key [chop_data $method $otherdata]}]
	error_check_good db_put $ret 0

	# check for existence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret \
	    [list [list $key [pad_data $method $otherdata]]]

	# commit
	error_check_good txn_commit [$txn commit] 0

	# check that data has changed ($otherdata not $data)
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret \
	    [list [list $key [pad_data $method $otherdata]]]

	puts "\tTest061.e: delete/abort"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# delete
	set ret [eval {$db del} -txn $txn {$key}]
	error_check_good db_put $ret 0

	# check for nonexistence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret {}

	# abort
	error_check_good txn_abort [$txn abort] 0

	# check for existence
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret \
	    [list [list $key [pad_data $method $otherdata]]]

	puts "\tTest061.f: delete/commit"

	# txn_begin
	set txn [$dbenv txn]
	error_check_good txn_begin [is_valid_txn $txn $dbenv] TRUE

	# put a key
	set ret [eval {$db del} -txn $txn {$key}]
	error_check_good db_put $ret 0

	# check for nonexistence
	set ret [eval {$db get} -txn $txn $gflags {$key}]
	error_check_good get $ret {}

	# commit
	error_check_good txn_commit [$txn commit] 0

	# check for continued nonexistence
	set ret [eval {$db get} $gflags {$key}]
	error_check_good get $ret {}

	# We're done; clean up.
	error_check_good db_close [eval {$db close}] 0
	error_check_good env_close [eval {$dbenv close}] 0

	# Now run db_recover and ensure that it runs cleanly.
	set utilflag ""
	if { $encrypt != 0 } {
		set utilflag "-P $passwd"
	}
	puts "\tTest061.g: Running db_recover -h"
	set ret [catch {eval {exec} $util_path/db_recover -h $testdir \
	    $utilflag} res]
	if { $ret != 0 } {
		puts "FAIL: db_recover outputted $res"
	}
	error_check_good db_recover $ret 0

	puts "\tTest061.h: Running db_recover -c -h"
	set ret [catch {eval {exec} $util_path/db_recover -c -h $testdir \
	    $utilflag} res]
	error_check_good db_recover-c $ret 0
}