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
|
#!/usr/bin/env python
#
# Public Domain 2016-2016 MongoDB, Inc.
# Public Domain 2008-2016 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.
#
# test_readonly03.py
# Readonly: Test connection readonly mode with modifying methods. Confirm
# all return ENOTSUP.
#
import os, sys, wiredtiger, wttest
from suite_subprocess import suite_subprocess
from wtdataset import SimpleDataSet
class test_readonly03(wttest.WiredTigerTestCase, suite_subprocess):
uri = 'table:test_readonly03'
uri2 = 'table:test_readonly03_2'
create = True
conn_params = 'create,log=(enabled),'
conn_params_rd = 'readonly=true'
session_ops = [ 'create', 'compact', 'drop', 'log_flush', 'log_printf',
'rebalance', 'rename', 'salvage', 'truncate', 'upgrade', ]
cursor_ops = [ 'insert', 'remove', 'update', ]
def setUpConnectionOpen(self, dir):
self.home = dir
if self.create:
conn_cfg = self.conn_params
else:
conn_cfg = self.conn_params_rd
conn = self.wiredtiger_open(dir, conn_cfg)
self.create = False
return conn
def test_readonly(self):
create_params = 'key_format=i,value_format=i'
entries = 10
# Create a database and a table.
SimpleDataSet(self, self.uri, entries, key_format='i',
value_format='i').populate()
#
# Now close and reopen. Note that the connection function
# above will reopen it readonly.
self.reopen_conn()
msg = '/Unsupported/'
c = self.session.open_cursor(self.uri, None, None)
for op in self.cursor_ops:
c.set_key(1)
c.set_value(1)
if op == 'insert':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: c.insert(), msg)
elif op == 'remove':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: c.remove(), msg)
elif op == 'update':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: c.update(), msg)
else:
self.fail('Unknown cursor operation: ' + op)
c.close()
for op in self.session_ops:
if op == 'create':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.create(self.uri2, create_params),
msg)
elif op == 'compact':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.compact(self.uri, None), msg)
elif op == 'drop':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.drop(self.uri, None), msg)
elif op == 'log_flush':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.log_flush(None), msg)
elif op == 'log_printf':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.log_printf("test"), msg)
elif op == 'rebalance':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.rebalance(self.uri, None), msg)
elif op == 'rename':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.rename(self.uri, self.uri2, None), msg)
elif op == 'salvage':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.salvage(self.uri, None), msg)
elif op == 'truncate':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.truncate(self.uri, None, None, None),
msg)
elif op == 'upgrade':
self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
lambda: self.session.upgrade(self.uri, None), msg)
else:
self.fail('Unknown session method: ' + op)
if __name__ == '__main__':
wttest.run()
|