summaryrefslogtreecommitdiff
path: root/test/suite/test_util13.py
blob: 222f42cd7f1cff62b9c823fc020328bbb48f1d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
#
# Public Domain 2014-2016 MongoDB, Inc.
# Public Domain 2008-2014 WiredTiger, Inc.
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

import os, re, string
from suite_subprocess import suite_subprocess
import itertools, wiredtiger, wttest

from helper import complex_populate_cgconfig, complex_populate_cgconfig_lsm
from helper import simple_populate
from helper import complex_populate_check, simple_populate_check
from wtscenario import multiply_scenarios, number_scenarios

# test_util13.py
#    Utilities: wt dump, as well as the dump cursor
#    Test that dump and load retain table configuration information.
#
class test_util13(wttest.WiredTigerTestCase, suite_subprocess):
    """
    Test wt dump.  We check for specific output and preservation of
    non-default table create parameters.
    """

    pfx = 'test_util13'
    nentries = 100
    dir = "dump_dir"
    #
    # Select table configuration settings that are not the default.
    #
    types = [
        ('file-simple', dict(uri='file:' + pfx, pop=simple_populate,
            populate_check=simple_populate_check,
            table_config='prefix_compression_min=3', cfg='')),
        ('lsm-simple', dict(uri='lsm:' + pfx, pop=simple_populate,
            populate_check=simple_populate_check,
            table_config='lsm=(bloom_bit_count=29)',
            cfg='bloom_bit_count=29')),
        ('table-simple', dict(uri='table:' + pfx, pop=simple_populate,
            populate_check=simple_populate_check,
            table_config='split_pct=50', cfg='')),
        ('table-complex',
            dict(uri='table:' + pfx, pop=complex_populate_cgconfig,
            populate_check=complex_populate_check,
            table_config='allocation_size=512B', cfg='')),
        ('table-complex-lsm',
            dict(uri='table:' + pfx, pop=complex_populate_cgconfig_lsm,
            populate_check=complex_populate_check,
            table_config='lsm=(merge_max=5)',
            cfg='merge_max=5')),
    ]

    scenarios = number_scenarios(multiply_scenarios('.', types))

    def compare_config(self, expected_cfg, actual_cfg):
        # Replace '(' characters so configuration groups don't break parsing.
        # If we ever want to look for config groups this will need to change.
        #print "compare_config Actual config "
        #print actual_cfg
        #print "compare_config Expected config "
        #print expected_cfg
        cfg_orig = actual_cfg
        if self.pop != simple_populate:
            #
            # If we have a complex config, strip out the colgroups and
            # columns from the config.  Doing so allows us to keep the
            # split commands below usable because those two items don't
            # have assignments in them.
            #
            nocolgrp = re.sub("colgroups=\((.+?)\),", '', actual_cfg)
            cfg_orig = re.sub("columns=\((.+?)\),", '', nocolgrp)

        #print "Using original config "
        #print cfg_orig
        da = dict(kv.split('=') for kv in
            cfg_orig.strip().replace('(',',').split(','))
        dx = dict(kv.split('=') for kv in
            expected_cfg.strip().replace('(',',').split(','))

        # Check that all items in our expected config subset are in
        # the actual configuration and they match.
        match = all(item in da.items() for item in dx.items())
        if match == False:
            print "MISMATCH:"
            print "Original dict: "
            print da
            print "Expected config: "
            print dx
        return match

    def compare_files(self, expect_subset, dump_out):
        inheader = isconfig = False
        for l1, l2 in zip(open(expect_subset, "rb"), open(dump_out, "rb")):
            if isconfig:
                if not self.compare_config(l1, l2):
                    return False
            if inheader:
                # This works because the expected subset has a format
                # of URI and config lines alternating.
                isconfig = not isconfig
            if l1.strip() == 'Header':
                inheader = True
            if l1.strip() == 'Data':
                break
        return True

    def load_recheck(self, expect_subset, dump_out):
        newdump = "newdump.out"
        os.mkdir(self.dir)
        self.runWt(['-h', self.dir, 'load', '-f', dump_out])
        # Check the contents
        conn = self.wiredtiger_open(self.dir)
        session = conn.open_session()
        cursor = session.open_cursor(self.uri, None, None)
        self.populate_check
        conn.close()
        dumpargs = ["-h"]
        dumpargs.append(self.dir)
        dumpargs.append("dump")
        dumpargs.append(self.uri)
        self.runWt(dumpargs, outfilename=newdump)

        self.assertTrue(self.compare_files(expect_subset, newdump))
        return True

    def test_dump_config(self):
        # The number of btree_entries reported is influenced by the
        # number of column groups and indices.  Each insert will have
        # a multiplied effect.
        self.pop(self, self.uri,
            'key_format=S,value_format=S,' + self.table_config, self.nentries)

        ver = wiredtiger.wiredtiger_version()
        verstring = str(ver[1]) + '.' + str(ver[2]) + '.' + str(ver[3])
        expectfile="expect.out"
        with open(expectfile, "w") as expectout:
            # Note: this output is sensitive to the precise output format
            # generated by wt dump.  If this is likely to change, we should
            # make this test more accommodating.
            expectout.write(
                'WiredTiger Dump (WiredTiger Version ' + verstring + ')\n')
            expectout.write('Format=print\n')
            expectout.write('Header\n')
            expectout.write(self.uri + '\n')
            # Check the config on the colgroup itself for complex tables.
            if self.pop != simple_populate:
                expectout.write('key_format=S\n')
                expectout.write('colgroup:' + self.pfx + ':cgroup1\n')
            if self.cfg == '':
                expectout.write(self.table_config + '\n')
            else:
                expectout.write(self.cfg + '\n')
            expectout.write('Data\n')

        self.pr('calling dump')
        outfile="dump.out"
        dumpargs = ["dump"]
        dumpargs.append(self.uri)
        self.runWt(dumpargs, outfilename=outfile)

        self.assertTrue(self.compare_files(expectfile, outfile))
        self.assertTrue(self.load_recheck(expectfile, outfile))

if __name__ == '__main__':
    wttest.run()