1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 2001-2009 Oracle.  All rights reserved.
4#
5# $Id$
6#
7# TEST	rep071
8# TEST	Test of multiple simultaneous client env handles and
9# TEST	upgrading/downgrading.  Tests use of temp db handle
10# TEST	internally.
11# TEST
12# TEST	Open a master and 2 handles to the same client env.
13# TEST	Run rep_test.
14# TEST	Close master and upgrade client to master using one env handle.
15# TEST	Run rep_test again, and then downgrade back to client.
16#
17proc rep071 { method { niter 10 } { tnum "071" } args } {
18
19	source ./include.tcl
20	global databases_in_memory
21	global repfiles_in_memory
22
23	if { $is_windows9x_test == 1 } {
24		puts "Skipping replication test on Win 9x platform."
25		return
26	}
27
28	# Run for btree only.
29	if { $checking_valid_methods } {
30		set test_methods { btree }
31		return $test_methods
32	}
33	if { [is_btree $method] == 0 } {
34		puts "Rep$tnum: Skipping for method $method."
35		return
36	}
37
38	# We can't open two envs on HP-UX, so just skip the
39	# whole test since that is at the core of it.
40	if { $is_hp_test == 1 } {
41		puts "Rep$tnum: Skipping for HP-UX."
42		return
43	}
44
45	# This test depends on copying logs, so can't be run with
46	# in-memory logging.
47	global mixed_mode_logging
48	if { $mixed_mode_logging > 0 } {
49		puts "Rep$tnum: Skipping for mixed-mode logging."
50		return
51	}
52
53	set args [convert_args $method $args]
54
55	# Set up for on-disk or in-memory databases.
56	set msg "using on-disk databases"
57	if { $databases_in_memory } {
58		set msg "using named in-memory databases"
59		if { [is_queueext $method] } {
60			puts -nonewline "Skipping rep$tnum for method "
61			puts "$method with named in-memory databases."
62			return
63		}
64	}
65
66	set msg2 "and on-disk replication files"
67	if { $repfiles_in_memory } {
68		set msg2 "and in-memory replication files"
69	}
70
71	# Run the body of the test with and without recovery.
72	foreach r $test_recopts {
73		puts "Rep$tnum ($method $r): Replication\
74		    backup and synchronizing $msg $msg2."
75		rep071_sub $method $niter $tnum $r $args
76	}
77}
78
79proc rep071_sub { method niter tnum recargs largs } {
80	global testdir
81	global util_path
82	global databases_in_memory
83	global repfiles_in_memory
84	global rep_verbose
85	global verbose_type
86
87	set verbargs ""
88	if { $rep_verbose == 1 } {
89		set verbargs " -verbose {$verbose_type on} "
90	}
91
92	set repmemargs ""
93	if { $repfiles_in_memory } {
94		set repmemargs "-rep_inmem_files "
95	}
96
97	env_cleanup $testdir
98
99	replsetup $testdir/MSGQUEUEDIR
100
101	set masterdir $testdir/MASTERDIR
102	set clientdir $testdir/CLIENTDIR
103
104	file mkdir $masterdir
105	file mkdir $clientdir
106
107	# Open a master.
108	repladd 1
109	set ma_envcmd "berkdb_env_noerr -create -txn nosync $verbargs \
110	    -home $masterdir -errpfx MASTER $repmemargs \
111	    -rep_transport \[list 1 replsend\]"
112	set masterenv [eval $ma_envcmd $recargs -rep_master]
113
114	# Open a client
115	repladd 2
116	set cl_envcmd "berkdb_env_noerr -create -txn nosync $verbargs \
117	    -home $clientdir -errpfx CLIENT $repmemargs \
118	    -rep_transport \[list 2 replsend\]"
119	set clientenv [eval $cl_envcmd $recargs -rep_client]
120	error_check_good clenv [is_valid_env $clientenv] TRUE
121	#
122	# Open a 2nd client handle to the same client env.
123	# This handle needs to be a full client handle so just
124	# use the same env command for both.
125	#
126	set 2ndclientenv [eval $cl_envcmd -rep_client -errpfx 2ND]
127	error_check_good cl2env [is_valid_env $2ndclientenv] TRUE
128
129	# Bring the clients online by processing the startup messages.
130	set envlist "{$masterenv 1} {$clientenv 2}"
131	process_msgs $envlist
132
133	# Run a modified test001 in the master (and update client).
134	puts "\tRep$tnum.a: Running rep_test in replicated env."
135	eval rep_test $method $masterenv NULL $niter 0 0 0 $largs
136	process_msgs $envlist
137
138	puts "\tRep$tnum.b: Downgrade master and upgrade client."
139	error_check_good master_close [$masterenv rep_start -client] 0
140	error_check_good client_close [$clientenv rep_start -master] 0
141
142	puts "\tRep$tnum.b: Run rep_test."
143	eval rep_test $method $clientenv NULL $niter 0 0 0 $largs
144	process_msgs $envlist
145
146	puts "\tRep$tnum.c: Downgrade back to client and upgrade master"
147	#
148	# The act of upgrading and downgrading an env, with another
149	# handle open had issues with open internal db handles.
150	# So, the existence of the 2nd client env handle is needed
151	# even though we're not doing anything active with that handle.
152	#
153	error_check_good client_close [$clientenv rep_start -client] 0
154	error_check_good master_close [$masterenv rep_start -master] 0
155
156	puts "\tRep$tnum.d: Run rep_test in master."
157	eval rep_test $method $masterenv NULL $niter 0 0 0 $largs
158	process_msgs $envlist
159
160	rep_verify $masterdir $masterenv $clientdir $clientenv
161
162	error_check_good master_close [$masterenv close] 0
163	error_check_good clientenv_close [$clientenv close] 0
164	error_check_good clientenv_close [$2ndclientenv close] 0
165	replclose $testdir/MSGQUEUEDIR
166}
167