1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 2005,2008 Oracle. All rights reserved. 4# 5# $Id: txn013.tcl,v 12.7 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST txn013 8# TEST Test of txns used in the wrong environment. 9# TEST Set up two envs. Start a txn in one env, and attempt to use it 10# TEST in the other env. Verify we get the appropriate error message. 11proc txn013 { } { 12 source ./include.tcl 13 14 set tnum "013" 15 puts "Txn$tnum: Test use of txns in wrong environment." 16 set testfile FILE.db 17 set key KEY 18 set data DATA 19 20 env_cleanup $testdir 21 22 puts "\tTxn$tnum.a: Create two environments." 23 set env1 [berkdb_env_noerr -create -mode 0644 -txn -home $testdir] 24 file mkdir $testdir/SUBDIR 25 set env2 \ 26 [berkdb_env_noerr -create -mode 0644 -txn -home $testdir/SUBDIR] 27 error_check_good env1 [is_valid_env $env1] TRUE 28 error_check_good env2 [is_valid_env $env2] TRUE 29 30 # Open a database in each environment. 31 puts "\tTxn$tnum.b: Open a database in each environment." 32 set db1 [berkdb_open_noerr \ 33 -env $env1 -create -auto_commit -btree $testfile] 34 set db2 [berkdb_open_noerr \ 35 -env $env2 -create -auto_commit -btree $testfile] 36 37 # Create txns in both environments. 38 puts "\tTxn$tnum.c: Start a transaction in each environment." 39 set txn1 [$env1 txn] 40 set txn2 [$env2 txn] 41 error_check_good txn1_begin [is_valid_txn $txn1 $env1] TRUE 42 error_check_good txn2_begin [is_valid_txn $txn2 $env2] TRUE 43 44 # First do the puts in the correct envs, so we have something 45 # for the gets and deletes. 46 error_check_good txn1_env1 [$db1 put -txn $txn1 $key $data] 0 47 error_check_good txn2_env2 [$db2 put -txn $txn2 $key $data] 0 48 49 puts "\tTxn$tnum.d: Execute db put in wrong environment." 50 set errormsg "from different environments" 51 catch {$db1 put -txn $txn2 $key $data} res 52 error_check_good put_env1txn2 [is_substr $res $errormsg] 1 53 catch {$db2 put -txn $txn1 $key $data} res 54 error_check_good put_env2txn1 [is_substr $res $errormsg] 1 55 56 puts "\tTxn$tnum.e: Execute db get in wrong environment." 57 catch {$db1 get -txn $txn2 $key} res 58 error_check_good get_env1txn2 [is_substr $res $errormsg] 1 59 catch {$db2 get -txn $txn1 $key} res 60 error_check_good get_env2txn1 [is_substr $res $errormsg] 1 61 62 puts "\tTxn$tnum.f: Execute db del in wrong environment." 63 catch {$db1 del -txn $txn2 $key} res 64 error_check_good get_env1txn2 [is_substr $res $errormsg] 1 65 catch {$db2 del -txn $txn1 $key} res 66 error_check_good get_env2txn1 [is_substr $res $errormsg] 1 67 68 # Clean up. 69 error_check_good txn1_commit [$txn1 commit] 0 70 error_check_good txn2_commit [$txn2 commit] 0 71 error_check_good db1_close [$db1 close] 0 72 error_check_good db2_close [$db2 close] 0 73 error_check_good env1_close [$env1 close] 0 74 error_check_good env2_close [$env2 close] 0 75} 76 77