mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 09:58:50 +08:00
tweaks to fix some places where python format rewrite looked kind of bad
This commit is contained in:
parent
899cb63952
commit
e104c21160
@ -336,8 +336,8 @@ class TestRunner(object):
|
||||
for i, error in enumerate(errors):
|
||||
util.get_logger().error(' %d. %s' % (i + 1, error))
|
||||
|
||||
log_message = '\nTest with seed %d and concurrency %d had %d incorrect result(s) and %d error(s) at API version %d' % (
|
||||
self.args.seed, self.args.concurrency, num_incorrect, num_errors, self.args.api_version)
|
||||
log_message = '\nTest with seed %d and concurrency %d had %d incorrect result(s) and %d error(s) at API version %d' %\
|
||||
(self.args.seed, self.args.concurrency, num_incorrect, num_errors, self.args.api_version)
|
||||
if num_errors == 0 and (num_incorrect == 0 or has_filtered_error):
|
||||
util.get_logger().info(log_message)
|
||||
if has_filtered_error:
|
||||
|
@ -347,6 +347,7 @@ class DirectoryTest(Test):
|
||||
ResultSpecification(self.subspace_log, ordering_index=0)
|
||||
]
|
||||
|
||||
|
||||
# Utility functions
|
||||
|
||||
|
||||
|
@ -118,7 +118,7 @@ class RandomGenerator(object):
|
||||
smaller_size = random.randint(1, len(to_add))
|
||||
tuples.append(to_add[:smaller_size])
|
||||
else:
|
||||
non_empty = filter(lambda i_x: (isinstance(i_x[1], list) or isinstance(i_x[1], tuple)) and len(i_x[1]) > 0, enumerate(to_add))
|
||||
non_empty = filter(lambda (_, x): (isinstance(x, list) or isinstance(x, tuple)) and len(x) > 0, enumerate(to_add))
|
||||
if len(non_empty) > 0 and random.random() < 0.25:
|
||||
# Add a smaller list to test prefixes of nested structures.
|
||||
idx, choice = random.choice(non_empty)
|
||||
|
@ -44,9 +44,8 @@ def initialize_logger_level(logging_level):
|
||||
def get_logger():
|
||||
return logging.getLogger('foundationdb.bindingtester')
|
||||
|
||||
|
||||
# Attempts to get the name associated with a process termination signal
|
||||
|
||||
|
||||
def signal_number_to_name(signal_num):
|
||||
name = []
|
||||
for key in signal.__dict__.keys():
|
||||
@ -65,11 +64,10 @@ def import_subclasses(filename, module_path):
|
||||
continue
|
||||
__import__('%s.%s' % (module_path, os.path.splitext(fn)[0]))
|
||||
|
||||
|
||||
# Attempts to unpack a subspace
|
||||
# This throws an exception if the subspace cannot be unpacked as a tuple
|
||||
# As a result, the binding tester cannot use subspaces that have non-tuple raw prefixes
|
||||
|
||||
|
||||
def subspace_to_tuple(subspace):
|
||||
try:
|
||||
return fdb.tuple.unpack(subspace.key())
|
||||
|
@ -1222,14 +1222,13 @@ else:
|
||||
raise Exception("Platform (%s) %s is not supported by the FoundationDB API!" % (sys.platform, platform.system()))
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
|
||||
# Preferred installation: The C API library or a symbolic link to the
|
||||
# library should be in the same directory as this module.
|
||||
# Failing that, a file named $(capi_name).pth should be in the same directory,
|
||||
# and a relative path to the library (including filename)
|
||||
# Failing that, we try to load the C API library without qualification, and
|
||||
# the library should be on the platform's dynamic library search path
|
||||
|
||||
|
||||
def read_pth_file():
|
||||
pth_file = os.path.join(this_dir, capi_name + '.pth')
|
||||
if not os.path.exists(pth_file):
|
||||
|
@ -59,10 +59,9 @@ def _find_terminator(v, pos):
|
||||
return pos
|
||||
pos += 2
|
||||
|
||||
|
||||
# If encoding and sign bit is 1 (negative), flip all of the bits. Otherwise, just flip sign.
|
||||
# If decoding and sign bit is 0 (negative), flip all of the bits. Otherwise, just flip sign.
|
||||
|
||||
|
||||
def _float_adjust(v, encode):
|
||||
if encode and six.indexbytes(v, 0) & 0x80 != 0x00:
|
||||
return b''.join(map(lambda x: six.int2byte(x ^ 0xff), six.iterbytes(v)))
|
||||
@ -368,14 +367,13 @@ def _encode(value, nested=False):
|
||||
else:
|
||||
raise ValueError("Unsupported data type: " + str(type(value)))
|
||||
|
||||
|
||||
# packs the tuple possibly for versionstamp operations and returns the position of the
|
||||
# incomplete versionstamp
|
||||
# * if there are no incomplete versionstamp members, this returns the packed tuple and -1
|
||||
# * if there is exactly one incomplete versionstamp member, it returns the tuple with the
|
||||
# two extra version bytes and the position of the version start
|
||||
# * if there is more than one incomplete versionstamp member, it throws an error
|
||||
|
||||
|
||||
def _pack_maybe_with_versionstamp(t, prefix=None):
|
||||
if not isinstance(t, tuple):
|
||||
raise Exception("fdbtuple pack() expects a tuple, got a " + str(type(t)))
|
||||
@ -392,27 +390,24 @@ def _pack_maybe_with_versionstamp(t, prefix=None):
|
||||
|
||||
return b''.join(bytes_list), version_pos
|
||||
|
||||
|
||||
# packs the specified tuple into a key
|
||||
|
||||
|
||||
def pack(t, prefix=None):
|
||||
res, version_pos = _pack_maybe_with_versionstamp(t, prefix)
|
||||
if version_pos >= 0:
|
||||
raise ValueError("Incomplete versionstamp included in vanilla tuple pack")
|
||||
return res
|
||||
|
||||
|
||||
# packs the specified tuple into a key for versionstamp operations
|
||||
|
||||
|
||||
def pack_with_versionstamp(t, prefix=None):
|
||||
res, version_pos = _pack_maybe_with_versionstamp(t, prefix)
|
||||
if version_pos < 0:
|
||||
raise ValueError("No incomplete versionstamp included in tuple pack with versionstamp")
|
||||
return res
|
||||
|
||||
|
||||
# unpacks the specified key into a tuple
|
||||
|
||||
|
||||
def unpack(key, prefix_len=0):
|
||||
pos = prefix_len
|
||||
res = []
|
||||
@ -421,9 +416,8 @@ def unpack(key, prefix_len=0):
|
||||
res.append(r)
|
||||
return tuple(res)
|
||||
|
||||
|
||||
# determines if there is at least one incomplete versionstamp in a tuple
|
||||
|
||||
|
||||
def has_incomplete_versionstamp(t):
|
||||
def _elem_has_incomplete(item):
|
||||
if item is None:
|
||||
@ -532,9 +526,8 @@ def _compare_values(value1, value2):
|
||||
# Booleans, UUIDs, integers, and Versionstamps can just use standard comparison.
|
||||
return -1 if value1 < value2 else 0 if value1 == value2 else 1
|
||||
|
||||
|
||||
# compare element by element and return -1 if t1 < t2 or 1 if t1 > t2 or 0 if t1 == t2
|
||||
|
||||
|
||||
def compare(t1, t2):
|
||||
i = 0
|
||||
while i < len(t1) and i < len(t2):
|
||||
|
@ -284,7 +284,7 @@ class Tester:
|
||||
|
||||
# print("Stack is %r" % self.stack)
|
||||
# if op != "PUSH" and op != "SWAP":
|
||||
# print("%d. Instruction is %s" % (idx, op))
|
||||
# print("%d. Instruction is %s" % (idx, op))
|
||||
|
||||
isDatabase = op.endswith(six.u('_DATABASE'))
|
||||
isSnapshot = op.endswith(six.u('_SNAPSHOT'))
|
||||
|
@ -41,6 +41,7 @@ import fdb.tuple
|
||||
|
||||
fdb.api_version(22)
|
||||
|
||||
|
||||
###################################
|
||||
# This defines a Subspace of keys #
|
||||
###################################
|
||||
@ -67,6 +68,7 @@ class Subspace (object):
|
||||
p = fdb.tuple.range(tuple)
|
||||
return slice(self.rawPrefix + p.start, self.rawPrefix + p.stop)
|
||||
|
||||
|
||||
#########
|
||||
# Queue #
|
||||
#########
|
||||
@ -282,6 +284,7 @@ class Queue:
|
||||
except fdb.FDBError as e:
|
||||
tr.on_error(e.code).wait()
|
||||
|
||||
|
||||
##################
|
||||
# Internal tests #
|
||||
##################
|
||||
@ -308,13 +311,13 @@ def queue_test(db):
|
||||
queue.clear(db)
|
||||
print 'Empty? %s' % queue.empty(db)
|
||||
|
||||
|
||||
######################
|
||||
# Queue sample usage #
|
||||
######################
|
||||
|
||||
|
||||
# caution: modifies the database!
|
||||
|
||||
|
||||
def queue_single_client_example(db):
|
||||
queue = Queue(Subspace(('queue_example',)), False)
|
||||
queue.clear(db)
|
||||
|
@ -31,6 +31,7 @@ import threading
|
||||
|
||||
fdb.api_version(22)
|
||||
|
||||
|
||||
###################################
|
||||
# This defines a Subspace of keys #
|
||||
###################################
|
||||
@ -57,6 +58,7 @@ class Subspace (object):
|
||||
p = fdb.tuple.range(tuple)
|
||||
return slice(self.rawPrefix + p.start, self.rawPrefix + p.stop)
|
||||
|
||||
|
||||
########################
|
||||
# _ImplicitTransaction #
|
||||
########################
|
||||
@ -86,6 +88,7 @@ class _ImplicitTransaction:
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.vector.local.tr = self.initialValue
|
||||
|
||||
|
||||
##########
|
||||
# Vector #
|
||||
##########
|
||||
@ -387,6 +390,7 @@ class Vector:
|
||||
# internal tests #
|
||||
##################
|
||||
|
||||
|
||||
# caution: modifies the database!
|
||||
@fdb.transactional
|
||||
def vector_test(tr):
|
||||
@ -509,6 +513,7 @@ def vector_test(tr):
|
||||
_print_vector(vector, tr)
|
||||
print 'Size:', vector.size()
|
||||
|
||||
|
||||
##############################
|
||||
# Vector sample usage #
|
||||
##############################
|
||||
@ -516,9 +521,8 @@ def vector_test(tr):
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
# caution: modifies the database!
|
||||
|
||||
|
||||
@fdb.transactional
|
||||
def vector_example(tr):
|
||||
vector = Vector(Subspace(('my_vector',)), 0)
|
||||
|
@ -206,9 +206,9 @@ def _post_message_internal(tr, feed, contents):
|
||||
# update the watchers on the feed to mark those inboxes as stale
|
||||
# prefix = fdb.tuple_to_key(key_for_feed(feed), 'watchers')
|
||||
# for k,v in tr.get_range_startswith(prefix):
|
||||
# stale_inbox = fdb.key_to_tuple(k)[3]
|
||||
# tr[key_for_inbox_stale_feed(stale_inbox, feed)] = ''
|
||||
# del tr[k]
|
||||
# stale_inbox = fdb.key_to_tuple(k)[3]
|
||||
# tr[key_for_inbox_stale_feed(stale_inbox, feed)] = ''
|
||||
# del tr[k]
|
||||
|
||||
return True
|
||||
|
||||
|
@ -52,6 +52,6 @@ print 'done'
|
||||
|
||||
# @fdb.transactional
|
||||
# def done(tr):
|
||||
# tr['/done/%d' % args.userStart] = 'done'
|
||||
# tr['/done/%d' % args.userStart] = 'done'
|
||||
#
|
||||
# done(db)
|
||||
|
@ -57,6 +57,6 @@ print 'done'
|
||||
|
||||
# @fdb.transactional
|
||||
# def done(tr):
|
||||
# tr['/done/%d' % args.userStart] = 'done'
|
||||
# tr['/done/%d' % args.userStart] = 'done'
|
||||
#
|
||||
# done(db)
|
||||
|
@ -33,6 +33,7 @@ def clear_subspace(tr, subspace):
|
||||
multi = fdb.Subspace(('M',))
|
||||
clear_subspace(db, multi)
|
||||
|
||||
|
||||
# Multimaps with multiset values
|
||||
|
||||
|
||||
|
@ -34,9 +34,8 @@ import fdb
|
||||
import fdb.tuple
|
||||
fdb.api_version(400)
|
||||
|
||||
|
||||
# A class that mimics some of the operations of the FoundationDB key-value store
|
||||
|
||||
|
||||
class KeyValueStore():
|
||||
|
||||
# Uses a simple dictionary to store key-value pairs
|
||||
@ -554,9 +553,9 @@ class PythonCorrectness(PythonTest):
|
||||
self.result.add_error('transaction.clear resulted in incorrect database')
|
||||
|
||||
# for key in clearedKeys:
|
||||
# print 'clearing key ' + key
|
||||
# print 'clearing key ' + key
|
||||
# else:
|
||||
# print 'successful compare'
|
||||
# print 'successful compare'
|
||||
|
||||
# Fill the database back up with data
|
||||
self.correctnessSet(db, store, data, maxKeysPerTransaction)
|
||||
|
Loading…
x
Reference in New Issue
Block a user