diff options
author | Don Anderson <dda@mongodb.com> | 2016-07-13 23:09:02 -0400 |
---|---|---|
committer | Alex Gorrod <alexander.gorrod@mongodb.com> | 2016-07-14 13:09:02 +1000 |
commit | 55f4584c9f3616571b77bf3876cae8c9ae0b1f93 (patch) | |
tree | 231837c84da6ddc6d59ccdc51fe72ee3dd8f04e3 /test | |
parent | 2c5343e7b9c81167fc0b8e3e14b2395d55afa5a8 (diff) | |
download | mongo-55f4584c9f3616571b77bf3876cae8c9ae0b1f93.tar.gz |
WT-2765 wt dump: indices need to be shown in the dump output (#2873)
Add a 'simple_index' set of helper functions that create a simple
table with one index. Modify dump and jsondump tests to use the
new functions.
Diffstat (limited to 'test')
-rw-r--r-- | test/suite/helper.py | 43 | ||||
-rw-r--r-- | test/suite/test_dump.py | 6 | ||||
-rw-r--r-- | test/suite/test_jsondump01.py | 45 |
3 files changed, 81 insertions, 13 deletions
diff --git a/test/suite/helper.py b/test/suite/helper.py index f85d708880f..9f34b566b3c 100644 --- a/test/suite/helper.py +++ b/test/suite/helper.py @@ -179,6 +179,49 @@ def simple_populate_check(self, uri, rows): simple_populate_check_cursor(self, cursor, rows) cursor.close() +# population of a simple object, with a single index +# uri: object +# config: prefix of the session.create configuration string (defaults +# to string value formats) +# rows: entries to insert +def simple_index_populate(self, uri, config, rows): + self.pr('simple_index_populate: ' + uri + ' with ' + str(rows) + ' rows') + self.session.create(uri, 'value_format=S,columns=(key0,value0),' + config) + indxname = 'index:' + uri.split(":")[1] + self.session.create(indxname + ':index1', 'columns=(value0,key0)') + cursor = self.session.open_cursor(uri, None) + for i in range(1, rows + 1): + cursor[key_populate(cursor, i)] = value_populate(cursor, i) + cursor.close() + +def simple_index_populate_check_cursor(self, cursor, rows): + i = 0 + for key,val in cursor: + i += 1 + self.assertEqual(key, key_populate(cursor, i)) + if cursor.value_format == '8t' and val == 0: # deleted + continue + self.assertEqual(val, value_populate(cursor, i)) + self.assertEqual(i, rows) + +def simple_index_populate_check(self, uri, rows): + self.pr('simple_index_populate_check: ' + uri) + + # Check values in the main table. + cursor = self.session.open_cursor(uri, None) + simple_index_populate_check_cursor(self, cursor, rows) + + # Check values in the index. + indxname = 'index:' + uri.split(":")[1] + idxcursor = self.session.open_cursor(indxname + ':index1') + for i in range(1, rows + 1): + k = key_populate(cursor, i) + v = value_populate(cursor, i) + ik = (v,k) # The index key is columns=(v,k). + self.assertEqual(v, idxcursor[ik]) + idxcursor.close() + cursor.close() + # Return the value stored in a complex object. def complex_value_populate(cursor, i): return [str(i) + ': abcdefghijklmnopqrstuvwxyz'[0:i%26], diff --git a/test/suite/test_dump.py b/test/suite/test_dump.py index 85196174c1b..cac95589137 100644 --- a/test/suite/test_dump.py +++ b/test/suite/test_dump.py @@ -30,7 +30,8 @@ import os, shutil import wiredtiger, wttest from helper import \ complex_populate, complex_populate_check, \ - simple_populate, simple_populate_check + simple_populate, simple_populate_check, \ + simple_index_populate, simple_index_populate_check from suite_subprocess import suite_subprocess from wtscenario import multiply_scenarios, number_scenarios @@ -64,6 +65,9 @@ class test_dump(wttest.WiredTigerTestCase, suite_subprocess): ('table-simple', dict(uri='table:', config='', lsm=False, populate=simple_populate, populate_check=simple_populate_check)), + ('table-index', dict(uri='table:', config='', lsm=False, + populate=simple_index_populate, + populate_check=simple_index_populate_check)), ('table-simple-lsm', dict(uri='table:', config='type=lsm', lsm=True, populate=simple_populate, populate_check=simple_populate_check)), diff --git a/test/suite/test_jsondump01.py b/test/suite/test_jsondump01.py index 10262edc777..a6d134e3a9d 100644 --- a/test/suite/test_jsondump01.py +++ b/test/suite/test_jsondump01.py @@ -29,8 +29,10 @@ import os, json import wiredtiger, wttest from helper import \ - complex_populate, complex_populate_check_cursor,\ - simple_populate, simple_populate_check_cursor + complex_populate, complex_populate_check, complex_populate_check_cursor,\ + simple_populate, simple_populate_check, simple_populate_check_cursor, \ + simple_index_populate, simple_index_populate_check, \ + simple_index_populate_check_cursor, compare_files from suite_subprocess import suite_subprocess from wtscenario import multiply_scenarios, number_scenarios @@ -79,22 +81,32 @@ class test_jsondump01(wttest.WiredTigerTestCase, suite_subprocess): types = [ ('file', dict(uri='file:', config='', lsm=False, populate=simple_populate, - populate_check=simple_populate_check_cursor)), + populate_check=simple_populate_check, + populate_check_cursor=simple_populate_check_cursor)), ('lsm', dict(uri='lsm:', config='', lsm=True, populate=simple_populate, - populate_check=simple_populate_check_cursor)), + populate_check=simple_populate_check, + populate_check_cursor=simple_populate_check_cursor)), ('table-simple', dict(uri='table:', config='', lsm=False, populate=simple_populate, - populate_check=simple_populate_check_cursor)), + populate_check=simple_populate_check, + populate_check_cursor=simple_populate_check_cursor)), + ('table-index', dict(uri='table:', config='', lsm=False, + populate=simple_index_populate, + populate_check=simple_index_populate_check, + populate_check_cursor=simple_index_populate_check_cursor)), ('table-simple-lsm', dict(uri='table:', config='type=lsm', lsm=True, populate=simple_populate, - populate_check=simple_populate_check_cursor)), + populate_check=simple_populate_check, + populate_check_cursor=simple_populate_check_cursor)), ('table-complex', dict(uri='table:', config='', lsm=False, populate=complex_populate, - populate_check=complex_populate_check_cursor)), + populate_check=complex_populate_check, + populate_check_cursor=complex_populate_check_cursor)), ('table-complex-lsm', dict(uri='table:', config='type=lsm', lsm=True, populate=complex_populate, - populate_check=complex_populate_check_cursor)) + populate_check=complex_populate_check, + populate_check_cursor=complex_populate_check_cursor)) ] scenarios = number_scenarios( multiply_scenarios('.', types, keyfmt)) @@ -132,7 +144,7 @@ class test_jsondump01(wttest.WiredTigerTestCase, suite_subprocess): cursor = self.session.open_cursor(uri, None) fake = FakeCursor(cursor.key_format, cursor.value_format, data) cursor.close() - self.populate_check(self, fake, self.nentries) + self.populate_check_cursor(self, fake, self.nentries) # Dump using util, re-load using python's JSON, and do a content comparison. def test_jsonload_util(self): @@ -153,9 +165,18 @@ class test_jsondump01(wttest.WiredTigerTestCase, suite_subprocess): loadcmd.append('-a') self.runWt(loadcmd) - # check the contents of the data we read. - cursor = self.session.open_cursor(uri2, None) - self.populate_check(self, cursor, self.nentries) + # Check the contents of the data we read. + self.populate_check(self, uri2, self.nentries) + + # Reload into the original uri, and dump into another file. + self.session.drop(uri, None) + self.session.drop(uri2, None) + self.runWt(['load', '-jf', 'jsondump.out']) + self.runWt(['dump', '-j', uri], outfilename='jsondump2.out') + + # Compare the two outputs, and check the content again. + compare_files(self, 'jsondump.out', 'jsondump2.out') + self.populate_check(self, uri, self.nentries) if __name__ == '__main__': wttest.run() |