1#!/usr/bin/env python
2#
3# Public Domain 2014-2018 MongoDB, Inc.
4# Public Domain 2008-2014 WiredTiger, Inc.
5#
6# This is free and unencumbered software released into the public domain.
7#
8# Anyone is free to copy, modify, publish, use, compile, sell, or
9# distribute this software, either in source code form or as a compiled
10# binary, for any purpose, commercial or non-commercial, and by any
11# means.
12#
13# In jurisdictions that recognize copyright laws, the author or authors
14# of this software dedicate any and all copyright interest in the
15# software to the public domain. We make this dedication for the benefit
16# of the public at large and to the detriment of our heirs and
17# successors. We intend this dedication to be an overt act of
18# relinquishment in perpetuity of all present and future rights to this
19# software under copyright law.
20#
21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27# OTHER DEALINGS IN THE SOFTWARE.
28#
29# test_txn13.py
30# Test very large log records.  Even with a small log file we should be
31# able to write them.  Expect an error over 4Gb.
32#
33
34#import fnmatch, os, shutil, run, time
35from suite_subprocess import suite_subprocess
36from wtscenario import make_scenarios
37import wiredtiger, wttest
38
39class test_txn13(wttest.WiredTigerTestCase, suite_subprocess):
40    logmax = "100K"
41    tablename = 'test_txn13'
42    uri = 'table:' + tablename
43    nops = 1024
44    create_params = 'key_format=i,value_format=S'
45
46    scenarios = make_scenarios([
47        ('1gb', dict(expect_err=False, valuesize=1048576)),
48        ('2gb', dict(expect_err=False, valuesize=2097152)),
49        ('4gb', dict(expect_err=True, valuesize=4194304))
50    ])
51
52    # Turn on logging for this test.
53    def conn_config(self):
54        return 'log=(archive=false,enabled,file_max=%s)' % self.logmax + \
55            ',cache_size=20G'
56
57    @wttest.longtest('txn tests with huge values')
58    def test_large_values(self):
59        # print "Creating %s with config '%s'" % (self.uri, self.create_params)
60        # print "Running with %d" % (self.valuesize)
61        self.session.create(self.uri, self.create_params)
62        c = self.session.open_cursor(self.uri, None)
63
64        # We want to test very large values.  Generate 'nops' records within
65        # a single transaction.
66        valuepfx = self.valuesize * 'X'
67
68        gotException = False
69        self.session.begin_transaction()
70        for k in range(self.nops):
71            value = valuepfx + str(k)
72            c[k] = value
73
74        if self.expect_err:
75            # EFBIG is expected: File too large
76            msg = '/exceeds the maximum/'
77            self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
78                lambda:self.session.commit_transaction(), msg)
79            gotException = True
80        else:
81            self.session.commit_transaction()
82
83        self.assertTrue(gotException == self.expect_err)
84
85if __name__ == '__main__':
86    wttest.run()
87