1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2004,2008 Oracle.  All rights reserved.
4#
5# $Id: sdb016.tcl,v 12.12 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	sdb016
8# TEST	Creates many in-memory named dbs and puts a small amount of
9# TEST	data in each (many defaults to 100)
10# TEST
11# TEST	Use the first 100 entries from the dictionary as names.
12# TEST	Insert each with entry as name of subdatabase and a partial list
13# TEST	as key/data.  After all are entered, retrieve all; compare output
14# TEST	to original.
15proc sdb016 { method {nentries 100} args } {
16	source ./include.tcl
17
18	set tnum "016"
19	set args [convert_args $method $args]
20	set omethod [convert_method $method]
21
22	if { [is_queueext $method] == 1 } {
23		puts "Subdb$tnum skipping for method $method"
24		return
25	}
26
27	puts "Subdb$tnum: $method ($args) many in-memory named databases"
28
29        # Skip test if given an env - this test needs its own.
30	set eindex [lsearch -exact $args "-env"]
31	if { $eindex != -1 } {
32		incr eindex
33		set env [lindex $args $eindex]
34		puts "\tSubdb$tnum skipping for env $env"
35		return
36	}
37
38	# In-memory dbs never go to disk, so we can't do checksumming.
39	# If the test module sent in the -chksum arg, get rid of it.
40	set chkindex [lsearch -exact $args "-chksum"]
41	if { $chkindex != -1 } {
42		set args [lreplace $args $chkindex $chkindex]
43	}
44
45	env_cleanup $testdir
46
47	# Set up env.  We'll need a big cache.
48	set csize {0 16777216 1}
49	set env [berkdb_env -create \
50	    -cachesize $csize -home $testdir -mode 0644 -txn]
51	error_check_good env_open [is_valid_env $env] TRUE
52
53	set pflags ""
54	set gflags ""
55	set txn ""
56	set fcount 0
57
58	# Here is the loop where we put and get each key/data pair
59	set ndataent 5
60	set fdid [open $dict]
61	puts "\tSubdb$tnum.a: Open $nentries in-memory databases."
62	while { [gets $fdid str] != -1 && $fcount < $nentries } {
63		if { $str == "" } {
64			continue
65		}
66		set subdb $str
67		set db [eval {berkdb_open -create -mode 0644} \
68		    -env $env $args {$omethod "" $subdb}]
69		error_check_good dbopen [is_valid_db $db] TRUE
70		set count 0
71		set did [open $dict]
72		while { [gets $did str] != -1 && $count < $ndataent } {
73			if { [is_record_based $method] == 1 } {
74				global kvals
75
76				set key [expr $count + 1]
77				set kvals($key) [pad_data $method $str]
78			} else {
79				set key $str
80			}
81			set ret [eval {$db put} \
82			    $txn $pflags {$key [chop_data $method $str]}]
83			error_check_good put $ret 0
84			set ret [eval {$db get} $gflags {$key}]
85			error_check_good get $ret [list [list $key \
86			    [pad_data $method $str]]]
87			incr count
88		}
89		close $did
90		error_check_good db_close [$db close] 0
91		incr fcount
92	}
93	close $fdid
94
95	puts "\tSubdb$tnum.b: Clean up."
96	error_check_good env_close [$env close] 0
97}
98
99