1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2004-2009 Oracle. All rights reserved. 4# 5# $Id$ 6# 7# Envscript -- for use with env012, DB_REGISTER test. 8# Usage: envscript testdir testfile putget key data recover failchk wait 9# testdir: directory containing the env we are joining. 10# testfile: file name for database. 11# putget: What to do in the db: put, get, or loop. 12# key: key to store or get 13# data: data to store or get 14# recover: include or omit the -recover flag in opening the env. 15# failchk: include or omit the -failchk flag in opening the env. 2 options 16# here, one with just -failchk and one with both -failchk & -isalive 17# wait: how many seconds to wait before closing env at end of test. 18 19source ./include.tcl 20source $test_path/testutils.tcl 21 22set usage "envscript testdir testfile putget key data recover failchk wait" 23 24# Verify usage 25if { $argc != 8 } { 26 puts stderr "FAIL:[timestamp] Usage: $usage" 27 exit 28} 29 30# Initialize arguments 31set testdir [ lindex $argv 0 ] 32set testfile [ lindex $argv 1 ] 33set putget [lindex $argv 2 ] 34set key [ lindex $argv 3 ] 35set data [ lindex $argv 4 ] 36set recover [ lindex $argv 5 ] 37set failchk [lindex $argv 6 ] 38set wait [ lindex $argv 7 ] 39 40set flag1 {} 41if { $recover == "RECOVER" } { 42 set flag1 " -recover " 43} 44 45set flag2 {} 46if {$failchk == "FAILCHK0" } { 47 set flag2 " -failchk " 48} 49if {$failchk == "FAILCHK1"} { 50 set flag2 " -failchk -isalive my_isalive -reg_timeout 100 " 51} 52 53# Open and register environment. 54if {[catch {eval {berkdb_env} \ 55 -create -home $testdir -txn -register $flag1 $flag2} dbenv]} { 56 puts "FAIL: opening env returned $dbenv" 57} 58error_check_good envopen [is_valid_env $dbenv] TRUE 59 60# Open database, put or get, close database. 61if {[catch {eval {berkdb_open} \ 62 -create -auto_commit -btree -env $dbenv $testfile} db]} { 63 puts "FAIL: opening db returned $db" 64} 65error_check_good dbopen [is_valid_db $db] TRUE 66 67switch $putget { 68 PUT { 69 set txn [$dbenv txn] 70 error_check_good db_put [eval {$db put} -txn $txn $key $data] 0 71 error_check_good txn_commit [$txn commit] 0 72 } 73 GET { 74 set ret [$db get $key] 75 error_check_good db_get [lindex [lindex $ret 0] 1] $data 76 } 77 LOOP { 78 while { 1 } { 79 set txn [$dbenv txn] 80 error_check_good db_put \ 81 [eval {$db put} -txn $txn $key $data] 0 82 error_check_good txn_commit [$txn commit] 0 83 tclsleep 1 84 } 85 } 86 default { 87 puts "FAIL: Unrecognized putget value $putget" 88 } 89} 90 91error_check_good db_close [$db close] 0 92 93# Wait. 94while { $wait > 0 } { 95puts "waiting ... wait is $wait" 96 tclsleep 1 97 incr wait -1 98} 99 100error_check_good env_close [$dbenv close] 0 101