From 77d59324651e1790c6045eb4caa76c6f91f8ac2d Mon Sep 17 00:00:00 2001 From: Jingyu Zhou Date: Thu, 20 Jun 2019 14:14:09 -0700 Subject: [PATCH] Add a transaction size limit test --- bindings/python/tests/size_limit.py | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 bindings/python/tests/size_limit.py diff --git a/bindings/python/tests/size_limit.py b/bindings/python/tests/size_limit.py new file mode 100644 index 0000000000..1abc2ec431 --- /dev/null +++ b/bindings/python/tests/size_limit.py @@ -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) \ No newline at end of file