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

« back to all changes in this revision

Viewing changes to libdb/test/si004.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) 2001-2002
4
 
#       Sleepycat Software.  All rights reserved.
5
 
#
6
 
# $Id$
7
 
#
8
 
# TEST  sindex004
9
 
# TEST  sindex002 with secondaries created and closed mid-test
10
 
# TEST  Basic cursor-based secondary index put/delete test, with
11
 
# TEST  secondaries created mid-test.
12
 
proc sindex004 { methods {nentries 200} {tnum 4} args } {
13
 
        source ./include.tcl
14
 
        global dict nsecondaries
15
 
 
16
 
        # Primary method/args.
17
 
        set pmethod [lindex $methods 0]
18
 
        set pargs [convert_args $pmethod $args]
19
 
        set pomethod [convert_method $pmethod]
20
 
 
21
 
        # Method/args for all the secondaries.  If only one method
22
 
        # was specified, assume the same method and a standard N
23
 
        # secondaries.
24
 
        set methods [lrange $methods 1 end]
25
 
        if { [llength $methods] == 0 } {
26
 
                for { set i 0 } { $i < $nsecondaries } { incr i } {
27
 
                        lappend methods $pmethod
28
 
                }
29
 
        }
30
 
 
31
 
        set argses [convert_argses $methods $args]
32
 
        set omethods [convert_methods $methods]
33
 
 
34
 
        puts "Sindex00$tnum ($pmethod/$methods) $nentries equal key/data pairs"
35
 
        env_cleanup $testdir
36
 
 
37
 
        set pname "primary00$tnum.db"
38
 
        set snamebase "secondary00$tnum"
39
 
 
40
 
        # Open an environment
41
 
        # XXX if one is not supplied!
42
 
        set env [berkdb_env -create -home $testdir]
43
 
        error_check_good env_open [is_valid_env $env] TRUE
44
 
 
45
 
        # Open the primary.
46
 
        set pdb [eval {berkdb_open -create -env} $env $pomethod $pargs $pname]
47
 
        error_check_good primary_open [is_valid_db $pdb] TRUE
48
 
 
49
 
        puts -nonewline \
50
 
            "\tSindex00$tnum.a: Cursor put (-keyfirst/-keylast) loop ... "
51
 
        set did [open $dict]
52
 
        set pdbc [$pdb cursor]
53
 
        error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
54
 
        for { set n 0 } { [gets $did str] != -1 && $n < $nentries } { incr n } {
55
 
                if { [is_record_based $pmethod] == 1 } {
56
 
                        set key [expr $n + 1]
57
 
                        set datum $str
58
 
                } else {
59
 
                        set key $str
60
 
                        gets $did datum
61
 
                }
62
 
                set ns($key) $n
63
 
                set keys($n) $key
64
 
                set data($n) [pad_data $pmethod $datum]
65
 
 
66
 
                if { $n % 2 == 0 } {
67
 
                        set pflag " -keyfirst "
68
 
                } else {
69
 
                        set pflag " -keylast "
70
 
                }
71
 
 
72
 
                set ret [eval {$pdbc put} $pflag \
73
 
                    {$key [chop_data $pmethod $datum]}]
74
 
                error_check_good put($n) $ret 0
75
 
        }
76
 
        close $did
77
 
        error_check_good pdbc_close [$pdbc close] 0
78
 
 
79
 
        # Open and associate the secondaries
80
 
        set sdbs {}
81
 
        puts "\n\t\topening secondaries."
82
 
        for { set i 0 } { $i < [llength $omethods] } { incr i } {
83
 
                set sdb [eval {berkdb_open -create -env} $env \
84
 
                    [lindex $omethods $i] [lindex $argses $i] $snamebase.$i.db]
85
 
                error_check_good second_open($i) [is_valid_db $sdb] TRUE
86
 
 
87
 
                error_check_good db_associate($i) \
88
 
                    [$pdb associate -create [callback_n $i] $sdb] 0
89
 
                lappend sdbs $sdb
90
 
        }
91
 
        check_secondaries $pdb $sdbs $nentries keys data "Sindex00$tnum.a"
92
 
 
93
 
        puts "\tSindex00$tnum.b: Cursor put overwrite (-current) loop"
94
 
        set pdbc [$pdb cursor]
95
 
        error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
96
 
        for { set dbt [$pdbc get -first] } { [llength $dbt] > 0 } \
97
 
            { set dbt [$pdbc get -next] } {
98
 
                set key [lindex [lindex $dbt 0] 0]
99
 
                set datum [lindex [lindex $dbt 0] 1]
100
 
                set newd $datum.$key
101
 
                set ret [eval {$pdbc put -current} [chop_data $pmethod $newd]]
102
 
                error_check_good put_overwrite($key) $ret 0
103
 
                set data($ns($key)) [pad_data $pmethod $newd]
104
 
        }
105
 
        error_check_good pdbc_close [$pdbc close] 0
106
 
        check_secondaries $pdb $sdbs $nentries keys data "Sindex00$tnum.b"
107
 
 
108
 
        puts -nonewline "\tSindex00$tnum.c:\
109
 
            Secondary c_pget/primary put overwrite loop ... "
110
 
        # We walk the first secondary, then put-overwrite each primary key/data
111
 
        # pair we find.  This doubles as a DBC->c_pget test.
112
 
        set sdb [lindex $sdbs 0]
113
 
        set sdbc [$sdb cursor]
114
 
        error_check_good sdb_cursor [is_valid_cursor $sdbc $sdb] TRUE
115
 
        for { set dbt [$sdbc pget -first] } { [llength $dbt] > 0 } \
116
 
            { set dbt [$sdbc pget -next] } {
117
 
                set pkey [lindex [lindex $dbt 0] 1]
118
 
                set pdatum [lindex [lindex $dbt 0] 2]
119
 
 
120
 
                # Extended entries will be showing up underneath us, in
121
 
                # unpredictable places.  Keep track of which pkeys
122
 
                # we've extended, and don't extend them repeatedly.
123
 
                if { [info exists pkeys_done($pkey)] == 1 } {
124
 
                        continue
125
 
                } else {
126
 
                        set pkeys_done($pkey) 1
127
 
                }
128
 
 
129
 
                set newd $pdatum.[string range $pdatum 0 2]
130
 
                set ret [eval {$pdb put} $pkey [chop_data $pmethod $newd]]
131
 
                error_check_good pdb_put($pkey) $ret 0
132
 
                set data($ns($pkey)) [pad_data $pmethod $newd]
133
 
        }
134
 
        error_check_good sdbc_close [$sdbc close] 0
135
 
 
136
 
        # Close the secondaries again.
137
 
        puts "\n\t\tclosing secondaries."
138
 
        for { set sdb [lindex $sdbs end] } { [string length $sdb] > 0 } \
139
 
            { set sdb [lindex $sdbs end] } {
140
 
                error_check_good second_close($sdb) [$sdb close] 0
141
 
                set sdbs [lrange $sdbs 0 end-1]
142
 
                check_secondaries \
143
 
                    $pdb $sdbs $nentries keys data "Sindex00$tnum.b"
144
 
        }
145
 
 
146
 
        # Delete the second half of the entries through the primary.
147
 
        # We do the second half so we can just pass keys(0 ... n/2)
148
 
        # to check_secondaries.
149
 
        set half [expr $nentries / 2]
150
 
        puts -nonewline "\tSindex00$tnum.d:\
151
 
            Primary cursor delete loop: deleting $half entries ... "
152
 
        set pdbc [$pdb cursor]
153
 
        error_check_good pdb_cursor [is_valid_cursor $pdbc $pdb] TRUE
154
 
        set dbt [$pdbc get -first]
155
 
        for { set i 0 } { [llength $dbt] > 0 && $i < $half } { incr i } {
156
 
                error_check_good pdbc_del [$pdbc del] 0
157
 
                set dbt [$pdbc get -next]
158
 
        }
159
 
        error_check_good pdbc_close [$pdbc close] 0
160
 
 
161
 
        set sdbs {}
162
 
        puts "\n\t\topening secondaries."
163
 
        for { set i 0 } { $i < [llength $omethods] } { incr i } {
164
 
                set sdb [eval {berkdb_open -create -env} $env \
165
 
                    [lindex $omethods $i] [lindex $argses $i] \
166
 
                    $snamebase.r2.$i.db]
167
 
                error_check_good second_open($i) [is_valid_db $sdb] TRUE
168
 
 
169
 
                error_check_good db_associate($i) \
170
 
                    [$pdb associate -create [callback_n $i] $sdb] 0
171
 
                lappend sdbs $sdb
172
 
        }
173
 
        cursor_check_secondaries $pdb $sdbs $half "Sindex00$tnum.d"
174
 
 
175
 
        # Delete half of what's left, through the first secondary.
176
 
        set quar [expr $half / 2]
177
 
        puts "\tSindex00$tnum.e:\
178
 
            Secondary cursor delete loop: deleting $quar entries"
179
 
        set sdb [lindex $sdbs 0]
180
 
        set sdbc [$sdb cursor]
181
 
        set dbt [$sdbc get -first]
182
 
        for { set i 0 } { [llength $dbt] > 0 && $i < $quar } { incr i } {
183
 
                error_check_good sdbc_del [$sdbc del] 0
184
 
                set dbt [$sdbc get -next]
185
 
        }
186
 
        error_check_good sdbc_close [$sdbc close] 0
187
 
        cursor_check_secondaries $pdb $sdbs $quar "Sindex00$tnum.e"
188
 
 
189
 
        foreach sdb $sdbs {
190
 
                error_check_good secondary_close [$sdb close] 0
191
 
        }
192
 
        error_check_good primary_close [$pdb close] 0
193
 
        error_check_good env_close [$env close] 0
194
 
}