1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2005,2008 Oracle.  All rights reserved.
4#
5# $Id: env014.tcl,v 12.7 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	env014
8# TEST
9# TEST	Make sure that attempts to open an environment with
10# TEST	incompatible flags (e.g. replication without transactions)
11# TEST	fail with the appropriate messages.
12# TEST
13# TEST	A new thread of control joining an env automatically
14# TEST	initializes the same subsystems as the original env.
15# TEST	Make sure that the attempt to change subsystems when
16# TEST	joining an env fails with the appropriate messages.
17
18proc env014 { } {
19	source ./include.tcl
20
21	set tnum "014"
22	puts "Env$tnum: Environment subsystem initialization and env joins."
23	env_cleanup $testdir
24
25	# Open an env with -recover but not -create; should fail.
26	puts "\tEnv$tnum.a: Open env with -recover but not -create."
27	catch {set env [berkdb_env_noerr -recover -txn -home $testdir]} ret
28	error_check_good recover_wo_create \
29	    [is_substr $ret "requires the create flag"] 1
30
31	# Open an env with -recover but not -txn; should fail.
32	puts "\tEnv$tnum.b: Open env with -recover but not -txn."
33	catch {set env [berkdb_env_noerr -create -recover -home $testdir]} ret
34	error_check_good recover_wo_txn \
35	    [is_substr $ret "requires transaction support"] 1
36
37	# Open an env with -replication but not -lock; should fail.
38	puts "\tEnv$tnum.c: Open env with -rep but not -lock."
39	catch {set env\
40	    [berkdb_env_noerr -create -rep_master -home $testdir]} ret
41	error_check_good rep_wo_lock \
42	    [is_substr $ret "requires locking support"] 1
43
44	# Open an env with -replication but not -txn; should fail.
45	puts "\tEnv$tnum.d: Open env with -rep but not -txn."
46	catch {set env\
47	    [berkdb_env_noerr -create -rep_master -lock -home $testdir]} ret
48	error_check_good rep_wo_txn \
49	    [is_substr $ret "requires transaction support"] 1
50
51	# Skip remainder of test for HP-UX; HP-UX does not allow
52	# opening a second handle on an environment.
53	if { $is_hp_test == 1 } {
54		puts "Skipping remainder of env$tnum for HP-UX."
55		return
56	}
57
58	# Join -txn env with -cdb; should fail.
59	puts "\tEnv$tnum.e: Join -txn env with -cdb."
60	set env [berkdb_env_noerr -create -home $testdir -txn]
61	error_check_good env_open [is_valid_env $env] TRUE
62
63	catch {set env2 [berkdb_env_noerr -home $testdir -cdb]} ret
64	error_check_good txn+cdb [is_substr $ret "incompatible"] 1
65	error_check_good env_close [$env close] 0
66	error_check_good env_remove [berkdb envremove -force -home $testdir] 0
67
68	# Join -cdb env with -txn; should fail.
69	puts "\tEnv$tnum.f: Join -cdb env with -txn."
70	set env [berkdb_env_noerr -create -home $testdir -cdb]
71	error_check_good env_open [is_valid_env $env] TRUE
72
73	catch {set env2 [berkdb_env_noerr -home $testdir -txn]} ret
74	error_check_good cdb+txn [is_substr $ret "incompatible"] 1
75	error_check_good env_close [$env close] 0
76	error_check_good env_remove [berkdb envremove -force -home $testdir] 0
77
78	# Open an env with -txn.  Join the env, and start a txn.
79	puts "\tEnv$tnum.g: Join -txn env, and start a txn."
80	set env [berkdb_env_noerr -create -home $testdir -txn]
81	error_check_good env_open [is_valid_env $env] TRUE
82	set env2 [berkdb_env_noerr -home $testdir]
83	error_check_good env2_open [is_valid_env $env2] TRUE
84
85	set txn [$env2 txn]
86	error_check_good env2_txn [is_valid_txn $txn $env2] TRUE
87	error_check_good txn_commit [$txn commit] 0
88
89	error_check_good env2_close [$env2 close] 0
90	error_check_good env_close [$env close] 0
91	error_check_good env_remove [berkdb envremove -force -home $testdir] 0
92
93	# Join -txn env with -lock; should succeed and use txns.
94	puts "\tEnv$tnum.h: Join -txn env with -lock, and start a txn."
95	set env [berkdb_env_noerr -create -home $testdir -txn]
96	error_check_good env_open [is_valid_env $env] TRUE
97	set env2 [berkdb_env_noerr -home $testdir -lock]
98	error_check_good env2_open [is_valid_env $env2] TRUE
99
100	set txn [$env2 txn]
101	error_check_good env2_txn [is_valid_txn $txn $env2] TRUE
102	error_check_good txn_commit [$txn commit] 0
103
104	error_check_good env2_close [$env2 close] 0
105	error_check_good env_close [$env close] 0
106	error_check_good env_remove [berkdb envremove -force -home $testdir] 0
107
108  	# Join plain vanilla env with -txn; should fail.
109	puts "\tEnv$tnum.i: Join plain vanilla env with -txn."
110	set env [berkdb_env_noerr -create -home $testdir]
111	error_check_good env_open [is_valid_env $env] TRUE
112	catch {set env2 [berkdb_env_noerr -home $testdir -txn]} ret
113	error_check_good ds+txn [is_substr $ret "incompatible"] 1
114
115	error_check_good env_close [$env close] 0
116	error_check_good env_remove [berkdb envremove -force -home $testdir] 0
117}
118