Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / test / tcl / env021.tcl
1 # See the file LICENSE for redistribution information.
2 #
3 # Copyright (c) 2011, 2012 Oracle and/or its affiliates.  All rights reserved.
4 #
5 # $Id$
6 #
7 # TEST    env021
8 # TEST    Test the operations on a transaction in a CDS environment.
9 # TEST    These are the operations we test:
10 # TEST        $txn abort
11 # TEST        $txn commit
12 # TEST        $txn id
13 # TEST        $txn prepare
14 # TEST        $txn setname name
15 # TEST        $txn getname
16 # TEST        $txn discard
17 # TEST        $txn set_timeout
18 # TEST    In these operations, we only support the following:
19 # TEST        $txn id
20 # TEST        $txn commit
21
22 proc env021 { } {
23         source ./include.tcl
24         env_cleanup $testdir
25
26         puts "Env021: Test operations on a transaction in a CDS environment."
27
28         set indx 0
29         puts "\tEnv021.$indx: Test DB_ENV->cdsgroup_begin in\
30             an environment without DB_INIT_CDB configured"
31         file mkdir $testdir/envdir$indx
32         set env1 [berkdb_env_noerr -create -home $testdir/envdir$indx \
33             -lock -log -txn -mode 0644]
34         error_check_good is_valid_env [is_valid_env $env1] TRUE
35         set txn1 [catch {eval $env1 cdsgroup} res]
36         error_check_good env_without_cdb [expr \
37             [is_substr $res "requires"] && [is_substr $res "DB_INIT_CDB"]] 1
38         error_check_good env_close [$env1 close] 0
39
40         set env021parms {
41                 {"abort" "abort" 0}
42                 {"commit" "commit" 1}
43                 {"id" "id" 1}
44                 {"prepare" "prepare env021gid1" 0}
45                 {"setname" "setname env021txn1" 0}
46                 {"getname" "getname" 0}
47                 {"discard" "discard" 0}
48                 {"set_timeout" "set_timeout 1000" 0}
49         }
50
51         foreach param $env021parms {
52                 set testname [lindex $param 0]
53                 set cmd [lindex $param 1]
54                 set success [lindex $param 2]
55                 incr indx
56                 puts "\tEnv021.$indx: Test DB_TXN->$testname"
57                 file mkdir $testdir/envdir$indx
58                 set env1 [berkdb_env_noerr -create -home $testdir/envdir$indx \
59                     -cdb -mode 0644]
60                 error_check_good is_valid_env [is_valid_env $env1] TRUE
61                 set txn1 [$env1 cdsgroup]
62                 error_check_good is_valid_txn [is_valid_txn $txn1 $env1] TRUE
63                 set ret [catch {eval $txn1 $cmd} res]
64                 if {$success} {
65                         error_check_bad "$txn1 $cmd" \
66                             [is_substr $res "CDS groups do not support"] 1
67                 } else {
68                         error_check_good "$txn1 $cmd" \
69                             [is_substr $res "CDS groups do not support"] 1
70                 }
71                 set ret [catch {$txn1 commit} res]
72                 if {$ret} {
73                         error_check_good \
74                             txn_commit [is_substr $res "invalid command name"] 1
75                 }
76                 error_check_good env_close [$env1 close] 0
77         }
78 }
79