Add a transaction size limit test

This commit is contained in:
Jingyu Zhou 2019-06-20 14:14:09 -07:00
parent 3a63d053e9
commit 77d5932465
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
#!/usr/bin/python
#
# size_limit.py
#
# This source file is part of the FoundationDB open source project
#
# Copyright 2013-2019 Apple Inc. and the FoundationDB project authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import fdb
import sys
fdb.api_version(610)
@fdb.transactional
def setValue(tr, key, value):
tr[key] = value
@fdb.transactional
def setValueWithLimit(tr, key, value, limit):
tr.options.set_size_limit(limit)
tr[key] = value
def run(clusterFile):
db = fdb.open(clusterFile)
db.options.set_transaction_timeout(2000) # 2 seconds
db.options.set_transaction_retry_limit(3)
value = 'a' * 1024
setValue(db, 't1', value)
assert(value == db['t1'])
try:
db.options.set_transaction_size_limit(1000)
setValue(db, 't2', value)
assert(False) # not reached
except fdb.impl.FDBError as e:
assert(e.code == 2101) # Transaction exceeds byte limit (2101)
# clear size limit by setting to a larger value
db.options.set_transaction_size_limit(1000000)
try:
setValueWithLimit(db, 't3', value, 1000)
assert(False) # not reached
except fdb.impl.FDBError as e:
assert(e.code == 2101) # Transaction exceeds byte limit (2101)
# Expect a cluster file as input. This test will write to the FDB cluster, so
# be aware of potential side effects.
if __name__ == '__main__':
clusterFile = sys.argv[1]
run(clusterFile)