summaryrefslogtreecommitdiff
path: root/test/suite/test_config04.py
blob: bdbff2f6d9fe4dab20ba65426ba3c9c68586a1c4 (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
#!/usr/bin/env python
#
# Copyright (c) 2008-2012 WiredTiger, Inc.
#	All rights reserved.
#
# See the file LICENSE for redistribution information.
#
# test_config04.py
# 	Individually test config options
#

import unittest
import wiredtiger
from wiredtiger import WiredTigerError
import wttest
import os

class test_config04(wttest.WiredTigerTestCase):
    table_name1 = 'test_config04'
    nentries = 100

    K = 1024
    M = K * K
    G = K * M
    T = K * G

    # Each test needs to set up its connection in its own way,
    # so override these methods to do nothing
    def setUpConnectionOpen(self, dir):
        return None

    def setUpSessionOpen(self, conn):
        return None

    def populate_and_check(self):
        """
        Create entries, and read back in a cursor: key=string, value=string
        """
        create_args = 'key_format=S,value_format=S'
        self.session.create("table:" + self.table_name1, create_args)
        cursor = self.session.open_cursor('table:' + self.table_name1, None, None)
        for i in range(0, self.nentries):
            cursor.set_key(str(1000000 + i))
            cursor.set_value('value' + str(i))
            cursor.insert()
        i = 0
        cursor.reset()
        for key, value in cursor:
            self.assertEqual(key, str(1000000 + i))
            self.assertEqual(value, ('value' + str(i)))
            i += 1
        self.assertEqual(i, self.nentries)
        cursor.close(None)

    def common_test(self, configextra):
        """
        Call wiredtiger_open and run a simple test.
        configextra are any extra configuration strings needed on the open.
        """
        configarg = 'create'
        if configextra != None:
            configarg += ',' + configextra
        self.conn = wiredtiger.wiredtiger_open('.', configarg)
        self.session = self.conn.open_session(None)
        self.populate_and_check()

    def common_cache_size_test(self, sizestr, size):
        self.common_test('cache_size=' + sizestr)
        cursor = self.session.open_cursor('statistics:', None, None)
        cursor.set_key(wiredtiger.stat.cache_bytes_max)
        self.assertEqual(cursor.search(), 0)
        got_cache = cursor.get_values()[2]
        self.assertEqual(got_cache, size)

    def test_bad_config(self):
        self.assertRaises(WiredTigerError, lambda:
            wiredtiger.wiredtiger_open('.', 'not_valid,another_bad=10'))

    def test_cache_size_number(self):
        # Use a number without multipliers
        # 1M is the minimum, we'll ask for 1025 * 1024
        cache_size_str = str(1025 * 1024)
        self.common_cache_size_test(cache_size_str, 1025*self.K)

    def test_cache_size_K(self):
        # Kilobyte sizing test
        # 1M is the minimum, so ask for that using K notation.
        self.common_cache_size_test('1024K', 1024*self.K)

    def test_cache_size_M(self):
        # Megabyte sizing test
        self.common_cache_size_test('30M', 30*self.M)

    def test_cache_size_G(self):
        # Gigabyte sizing test
        # We are specifying the maximum the cache can grow,
        # not the initial cache amount, so small tests like
        # this can still run on smaller machines.
        self.common_cache_size_test('7G', 7*self.G)

    def test_cache_size_T(self):
        # Terabyte sizing test
        # We are specifying the maximum the cache can grow,
        # not the initial cache amount, so small tests like
        # this can still run on smaller machines.
        self.common_cache_size_test('2T', 2*self.T)

    def test_cache_too_small(self):
        self.assertRaises(WiredTigerError, lambda:
            wiredtiger.wiredtiger_open('.', 'create,cache_size=900000'))

    def test_cache_too_large(self):
        T11 = 11 * self.T  # 11 Terabytes
        self.assertRaises(WiredTigerError, lambda:
            wiredtiger.wiredtiger_open('.', 'create,cache_size=' + str(T11)))

    def test_eviction(self):
        self.common_test('eviction_target=84,eviction_trigger=94')
        # Note

    def test_eviction_bad(self):
        self.assertRaises(WiredTigerError, lambda:
            wiredtiger.wiredtiger_open('.', 'create,eviction_target=91,' +
                                       'eviction_trigger=81'))

    def test_eviction_bad2(self):
        self.assertRaises(WiredTigerError, lambda:
            wiredtiger.wiredtiger_open('.', 'create,eviction_target=86,' +
                                       'eviction_trigger=86'))

    def test_hazard_max(self):
        # Note: There isn't any direct way to know that this was set.
        self.common_test('hazard_max=50')

    def test_session_max(self):
        # Note: There isn't any direct way to know that this was set,
        # but we'll have a separate functionality test to test for
        # this indirectly.
        self.common_test('session_max=99')

    def test_multiprocess(self):
        self.common_test('multiprocess')
        # TODO: how do we verify that it was set?

    def test_error_prefix(self):
        self.common_test('error_prefix="MyOwnPrefix"')
        # TODO: how do we verify that it was set?

    def test_logging(self):
        # Note: this will have functional tests in the future.
        self.common_test('logging')

    def test_transactional(self):
        # Note: this will have functional tests in the future.
        self.common_test('transactional')

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