~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/rep002.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# See the file LICENSE for redistribution information.
2
 
#
3
 
# Copyright (c) 2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  rep002
9
 
# TEST  Basic replication election test.
10
 
# TEST
11
 
# TEST  Run a modified version of test001 in a replicated master environment;
12
 
# TEST  hold an election among a group of clients to make sure they select
13
 
# TEST  a proper master from amongst themselves, in various scenarios.
14
 
 
15
 
proc rep002 { method { niter 10 } { nclients 3 } { tnum "02" } args } {
16
 
        source ./include.tcl
17
 
        global elect_timeout
18
 
 
19
 
        set elect_timeout 1000000
20
 
 
21
 
        if { [is_record_based $method] == 1 } {
22
 
                puts "Rep002: Skipping for method $method."
23
 
                return
24
 
        }
25
 
 
26
 
        env_cleanup $testdir
27
 
 
28
 
        set qdir $testdir/MSGQUEUEDIR
29
 
        replsetup $qdir
30
 
 
31
 
        set masterdir $testdir/MASTERDIR
32
 
        file mkdir $masterdir
33
 
 
34
 
        for { set i 0 } { $i < $nclients } { incr i } {
35
 
                set clientdir($i) $testdir/CLIENTDIR.$i
36
 
                file mkdir $clientdir($i)
37
 
        }
38
 
 
39
 
        puts "Rep0$tnum: Replication election test with $nclients clients."
40
 
 
41
 
        # Open a master.
42
 
        repladd 1
43
 
        set env_cmd(M) "berkdb_env -create -log_max 1000000 -home \
44
 
            $masterdir -txn -rep_master -rep_transport \[list 1 replsend\]"
45
 
        set masterenv [eval $env_cmd(M)]
46
 
        error_check_good master_env [is_valid_env $masterenv] TRUE
47
 
 
48
 
        # Open the clients.
49
 
        for { set i 0 } { $i < $nclients } { incr i } {
50
 
                set envid [expr $i + 2]
51
 
                repladd $envid
52
 
                set env_cmd($i) "berkdb_env -create -home $clientdir($i) \
53
 
                    -txn -rep_client -rep_transport \[list $envid replsend\]"
54
 
                set clientenv($i) [eval $env_cmd($i)]
55
 
                error_check_good \
56
 
                    client_env($i) [is_valid_env $clientenv($i)] TRUE
57
 
        }
58
 
 
59
 
        # Run a modified test001 in the master.
60
 
        puts "\tRep0$tnum.a: Running test001 in replicated env."
61
 
        eval test001 $method $niter 0 $tnum 0 -env $masterenv $args
62
 
 
63
 
        # Loop, processing first the master's messages, then the client's,
64
 
        # until both queues are empty.
65
 
        while { 1 } {
66
 
                set nproced 0
67
 
 
68
 
                incr nproced [replprocessqueue $masterenv 1]
69
 
 
70
 
                for { set i 0 } { $i < $nclients } { incr i } {         
71
 
                        set envid [expr $i + 2]
72
 
                        incr nproced [replprocessqueue $clientenv($i) $envid]
73
 
                }
74
 
 
75
 
                if { $nproced == 0 } {
76
 
                        break
77
 
                }
78
 
        }
79
 
 
80
 
        # Verify the database in the client dir.
81
 
        for { set i 0 } { $i < $nclients } { incr i } {
82
 
                puts "\tRep0$tnum.b: Verifying contents of client database $i."
83
 
                set testdir [get_home $masterenv]
84
 
                set t1 $testdir/t1
85
 
                set t2 $testdir/t2
86
 
                set t3 $testdir/t3
87
 
                open_and_dump_file test0$tnum.db $clientenv($i) $testdir/t1 \
88
 
                    test001.check dump_file_direction "-first" "-next"
89
 
 
90
 
                if { [string compare [convert_method $method] -recno] != 0 } {
91
 
                        filesort $t1 $t3
92
 
                }
93
 
                error_check_good diff_files($t2,$t3) [filecmp $t2 $t3] 0
94
 
 
95
 
                verify_dir $clientdir($i) "\tRep0$tnum.c: " 0 0 1
96
 
        }
97
 
 
98
 
        # Start an election in the first client.
99
 
        puts "\tRep0$tnum.d: Starting election without dead master."
100
 
 
101
 
        set elect_pipe(0) [start_election \
102
 
            $qdir $env_cmd(0) [expr $nclients + 1] 20 $elect_timeout]
103
 
 
104
 
        tclsleep 1
105
 
 
106
 
        # We want to verify all the clients but the one that declared an 
107
 
        # election get the election message.
108
 
        # We also want to verify that the master declares the election
109
 
        # over by fiat, even if everyone uses a lower priority than 20.
110
 
        # Loop and process all messages, keeping track of which 
111
 
        # sites got a HOLDELECTION and checking that the returned newmaster, 
112
 
        # if any, is 1 (the master's replication ID).
113
 
        set got_hold_elect(M) 0
114
 
        for { set i 0 } { $i < $nclients } { incr i } { 
115
 
                set got_hold_elect($i) 0 
116
 
        }
117
 
        while { 1 } {
118
 
                set nproced 0
119
 
                set he 0
120
 
                set nm 0
121
 
                
122
 
 
123
 
                incr nproced [replprocessqueue $masterenv 1 0 he nm]
124
 
 
125
 
                if { $he == 1 } {
126
 
                        set elect_pipe(M) [start_election $qdir \
127
 
                            $env_cmd(M) [expr $nclients + 1] 0 $elect_timeout]
128
 
                        set got_hold_elect(M) 1
129
 
                }
130
 
                if { $nm != 0 } {
131
 
                        error_check_good newmaster_is_master $nm 1
132
 
                }
133
 
 
134
 
                for { set i 0 } { $i < $nclients } { incr i } {         
135
 
                        set he 0
136
 
                        set envid [expr $i + 2]
137
 
                        incr nproced \
138
 
                            [replprocessqueue $clientenv($i) $envid 0 he nm]
139
 
                        if { $he == 1 } {
140
 
                                # error_check_bad client(0)_in_elect $i 0
141
 
                                set elect_pipe(M) [start_election $qdir \
142
 
                                    $env_cmd($i) [expr $nclients + 1] 0 \
143
 
                                    $elect_timeout]
144
 
                                set got_hold_elect($i) 1
145
 
                        }
146
 
                        if { $nm != 0 } {
147
 
                                error_check_good newmaster_is_master $nm 1
148
 
                        }
149
 
                }
150
 
 
151
 
                if { $nproced == 0 } {
152
 
                        break
153
 
                }
154
 
        }
155
 
 
156
 
        error_check_good got_hold_elect(master) $got_hold_elect(M) 0
157
 
        unset got_hold_elect(M)
158
 
        # error_check_good got_hold_elect(0) $got_hold_elect(0) 0
159
 
        unset got_hold_elect(0)
160
 
        for { set i 1 } { $i < $nclients } { incr i } { 
161
 
                error_check_good got_hold_elect($i) $got_hold_elect($i) 1
162
 
                unset got_hold_elect($i)
163
 
        }
164
 
 
165
 
        cleanup_elections
166
 
 
167
 
        # We need multiple clients to proceed from here.
168
 
        if { $nclients < 2 } {
169
 
                puts "\tRep0$tnum: Skipping for less than two clients."
170
 
                error_check_good masterenv_close [$masterenv close] 0
171
 
                for { set i 0 } { $i < $nclients } { incr i } {
172
 
                        error_check_good clientenv_close($i) \
173
 
                            [$clientenv($i) close] 0
174
 
                }
175
 
                return
176
 
        }
177
 
 
178
 
        # Make sure all the clients are synced up and ready to be good
179
 
        # voting citizens.
180
 
        error_check_good master_flush [$masterenv rep_flush] 0
181
 
        while { 1 } {
182
 
                set nproced 0
183
 
                incr nproced [replprocessqueue $masterenv 1 0]
184
 
                for { set i 0 } { $i < $nclients } { incr i } {
185
 
                        incr nproced [replprocessqueue $clientenv($i) \
186
 
                            [expr $i + 2] 0]
187
 
                }
188
 
 
189
 
                if { $nproced == 0 } {
190
 
                        break
191
 
                }
192
 
        }
193
 
 
194
 
        # Now hold another election in the first client, this time with
195
 
        # a dead master.
196
 
        puts "\tRep0$tnum.e: Starting election with dead master."
197
 
        error_check_good masterenv_close [$masterenv close] 0
198
 
 
199
 
        for { set i 0 } { $i < $nclients } { incr i } {
200
 
                replclear [expr $i + 2]
201
 
        }
202
 
 
203
 
        set elect_pipe(0) [start_election \
204
 
            $qdir $env_cmd(0) [expr $nclients + 1] 20 $elect_timeout]
205
 
 
206
 
        tclsleep 1
207
 
 
208
 
        # Process messages, and verify that the client with the highest
209
 
        # priority--client #1--wins.
210
 
        set got_newmaster 0
211
 
        set tries 10
212
 
        while { 1 } {
213
 
                set nproced 0
214
 
                set he 0
215
 
                set nm 0
216
 
                
217
 
                for { set i 0 } { $i < $nclients } { incr i } {         
218
 
                        set he 0
219
 
                        set envid [expr $i + 2]
220
 
                        incr nproced \
221
 
                            [replprocessqueue $clientenv($i) $envid 0 he nm]
222
 
                        if { $he == 1 } {
223
 
 
224
 
                                # Client #1 has priority 100;  everyone else
225
 
                                # has priority 10.
226
 
                                if { $i == 1 } {
227
 
                                        set pri 100
228
 
                                } else {
229
 
                                        set pri 10
230
 
                                }
231
 
                                # error_check_bad client(0)_in_elect $i 0
232
 
                                set elect_pipe(M) [start_election $qdir \
233
 
                                    $env_cmd($i) [expr $nclients + 1] $pri \
234
 
                                    $elect_timeout]
235
 
                                set got_hold_elect($i) 1
236
 
                        }
237
 
                        if { $nm != 0 } {
238
 
                                error_check_good newmaster_is_master $nm \
239
 
                                    [expr 1 + 2]
240
 
                                set got_newmaster $nm
241
 
 
242
 
                                # If this env is the new master, it needs to
243
 
                                # configure itself as such--this is a different
244
 
                                # env handle from the one that performed the
245
 
                                # election.
246
 
                                if { $nm == $envid } {
247
 
                                        error_check_good make_master($i) \
248
 
                                            [$clientenv($i) rep_start -master] \
249
 
                                            0
250
 
                                }
251
 
                        }
252
 
                }
253
 
 
254
 
                # We need to wait around to make doubly sure that the
255
 
                # election has finished...
256
 
                if { $nproced == 0 } {
257
 
                        incr tries -1
258
 
                        if { $tries == 0 } {
259
 
                                break
260
 
                        } else {
261
 
                                tclsleep 1
262
 
                        }
263
 
                }
264
 
        }
265
 
 
266
 
        # Verify that client #1 is actually the winner.
267
 
        error_check_good "client 1 wins" $got_newmaster [expr 1 + 2]
268
 
 
269
 
        cleanup_elections
270
 
 
271
 
        for { set i 0 } { $i < $nclients } { incr i } {
272
 
                error_check_good clientenv_close($i) [$clientenv($i) close] 0
273
 
        }
274
 
 
275
 
        replclose $testdir/MSGQUEUEDIR
276
 
}
277
 
 
278
 
proc reptwo { args } { eval rep002 $args }