File: test137.tcl

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (218 lines) | stat: -rw-r--r-- 6,173 bytes parent folder | download | duplicates (8)
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
# See the file LICENSE for redistribution information.
#
# Copyright (c) 2011, 2013 Oracle and/or its affiliates.  All rights reserved.
#
# $Id$
#
# TEST	test137
# TEST  Test Automatic Resource Management. [#16188][#20281]
# TEST  Open an environment, and open a database in it.
# TEST  Do some operations in the database, including:
# TEST    insert, dump, delete
# TEST  Close the environment without closing the database.
# TEST  Re-open the database and verify the records are the ones we expected.

proc test137 { method {nentries 1000} {start 0} {skip 0} {use_encrypt 0}
    {tnum "137"} {envtype "ds"} args } {
	source ./include.tcl
	global encrypt
	global has_crypto

	# This test needs its own env.
	set eindex [lsearch -exact $args "-env"]
	if { $eindex != -1 } {
		incr eindex
		set env [lindex $args $eindex]
		puts "Test$tnum skipping for env $env"
		return
	}

	# Skip if use_encrypt and encryption is not supported.
	if { $use_encrypt && $has_crypto == 0 } {
		puts "Skipping test$tnum for non-crypto release."
		return
	}

	# Do not use db encryption flags from the $args -- this test
	# does its own encryption testing at the env level. 
	convert_encrypt $args
	if { $encrypt } {
		puts "Test$tnum skipping DB encryption"
		return
	}

	# We can not specify chksum option to opening db when using
	# an encrypted env.
	set chksum_indx [lsearch -exact $args "-chksum"]
	if { $chksum_indx != -1 && $use_encrypt } {
		puts "Test$tnum skipping DB chksum"
		return
	}

	set encmsg "non-encrypt"
	if { $use_encrypt } {
		set encmsg "encrypt"
	}

	set args [convert_args $method $args]
	set omethod [convert_method $method]

	env_cleanup $testdir
	set env [test137_openenv $envtype $testdir $use_encrypt]
	set envargs  "-env $env"
	set txnenv [string equal $envtype "tds"]
	if { $txnenv == 1 } {
		set nentries 200 
		append args " -auto_commit"
	}

	set testfile test$tnum.db	
	set t1 $testdir/t1
	set t2 $testdir/t2

	puts "Test$tnum: $method \
	    ($envtype,$encmsg,$args) $nentries equal key/data pairs"

	set did [open $dict]
	# The "start" variable determines the record number to start
	# with, if we're using record numbers.  The "skip" variable
	# determines the dictionary entry to start with.
	# In normal use, skip will match start.
	puts "\tTest$tnum: Starting at $start with dictionary entry $skip"
	if { $skip != 0 } {
		for { set count 0 } { $count < $skip } { incr count } {
			gets $did str
		}
	}

	set db [eval {berkdb_open \
	     -create -mode 0644} $envargs $args $omethod $testfile]
	error_check_good dbopen [is_valid_db $db] TRUE

	set txn ""
	if { $txnenv == 1 } {
		set t [$env txn]
		error_check_good txn [is_valid_txn $t $env] TRUE
		set txn "-txn $t"
	}

	puts "\tTest$tnum.a: put loop"
	# Here is the loop where we put and get each key/data pair
	set count 0
	set key_list {}
	set data_list {}
	while { [gets $did str] != -1 && $count < $nentries } {
		if { [is_record_based $method] == 1 } {
			set key [expr $count + 1 + $start]
		} else {
			set key $str
			set str [reverse $str]
		}
		set ret [eval \
		    {$db put} $txn {$key [chop_data $method $str]}]
		error_check_good db_put $ret 0
		lappend key_list $key
		lappend data_list $str
		incr count
	}
	close $did

	puts "\tTest$tnum.b: dump file and close env without closing database"
	dump_file $db $txn $t1 NONE
	if { $txnenv == 1 } {
		error_check_good txn_commit [$t commit] 0
	}
	error_check_good env_close [$env close] 0
	# Clean the tcl handle only.
        catch {$db close -handle_only} res

	puts "\tTest$tnum.c: open the env and database again"
	set env [test137_openenv $envtype $testdir $use_encrypt]
	set envargs  "-env $env"
	set db [eval {berkdb_open \
	     -create -mode 0644} $envargs $args $omethod $testfile]
	error_check_good dbopen [is_valid_db $db] TRUE

	if { $txnenv == 1 } {
		set t [$env txn]
		error_check_good txn [is_valid_txn $t $env] TRUE
		set txn "-txn $t"
	}

	puts "\tTest$tnum.d: dump file and check"
	dump_file $db $txn $t2 NONE
	error_check_good Test$tnum:diff($t1,$t2) \
	    [filecmp $t1 $t2] 0

	puts "\tTest$tnum.e: delete loop"
	# We delete starting from the last record, since for rrecno, if we 
	# delete previous records, the ones after will change their keys.
	for {set i [expr [llength $key_list] - 1]} {$i >= 0} \
	    {incr i -[berkdb random_int 1 5]} {
		set key [lindex $key_list $i]
		set ret [eval $db del $txn {$key}]
		error_check_good db_del $ret 0
	} 

	puts "\tTest$tnum.f:\
	    dump file and close env without closing database again"
	dump_file $db $txn $t1 NONE
	if { $txnenv == 1 } {
		error_check_good txn_commit [$t commit] 0
	}
	error_check_good env_close [$env close -forcesync] 0
        catch {$db close -handle_only} res

	# We remove the environment to make sure the regions files
	# are deleted(including mpool files), so we can verify if
	# the database has been synced during a force-synced env close.
	error_check_good env_remove [berkdb envremove -force -home $testdir] 0

	puts "\tTest$tnum.g: open, dump and check again"
	set env [test137_openenv $envtype $testdir $use_encrypt]
	set envargs  "-env $env"
	set db [eval {berkdb_open \
	     -create -mode 0644} $envargs $args $omethod $testfile]
	error_check_good dbopen [is_valid_db $db] TRUE

	if { $txnenv == 1 } {
		set t [$env txn]
		error_check_good txn [is_valid_txn $t $env] TRUE
		set txn "-txn $t"
	}

	dump_file $db $txn $t2 NONE
	error_check_good Test$tnum:diff($t1,$t2) \
	    [filecmp $t1 $t2] 0

	if { $txnenv == 1 } {
		error_check_good txn_commit [$t commit] 0
	}
	error_check_good db_close [$db close] 0
	error_check_good env_close [$env close] 0
}

proc test137_openenv {envtype testdir use_encrypt} {
	global passwd
	
	set encargs ""
	if {$use_encrypt} {
		set encargs " -encryptaes $passwd "
	}
	switch -exact "$envtype" {
		"ds" {
			set env [eval berkdb_env_noerr -create -mode 0644 \
			    $encargs -home $testdir]
		}
		"cds" {
			set env [eval berkdb_env_noerr -create -mode 0644 \
			    $encargs -cdb -home $testdir]
		}
		"tds" {
			set env [eval berkdb_env_noerr -create -mode 0644 \
			    $encargs -txn -lock -log -thread -home $testdir]
		}
	}
	error_check_good env_open [is_valid_env $env] TRUE
	return $env
}