Compare commits

...

2 commits

Author SHA1 Message Date
Stephon Striplin
00cfe0dd82 Add close to check for file sizes 2011-08-25 15:02:58 -07:00
Stephon Striplin
d4a77acb71 Add atomic read tests 2011-08-25 14:32:59 -07:00

View file

@ -2076,9 +2076,8 @@ def test_stress_bucket_acls_changes():
_test_bucket_acls_changes_persistent(bucket);
class FakeFile(object):
def __init__(self, size, char='A', interrupt=None):
def __init__(self, char='A', interrupt=None):
self.offset = 0
self.size = size
self.char = char
self.interrupt = interrupt
@ -2088,6 +2087,11 @@ class FakeFile(object):
def tell(self):
return self.offset
class FakeWriteFile(FakeFile):
def __init__(self, size, char='A', interrupt=None):
FakeFile.__init__(self, char, interrupt)
self.size = size
def read(self, size=-1):
if size < 0:
size = self.size - self.offset
@ -2100,6 +2104,61 @@ class FakeFile(object):
return self.char*count
class FakeReadFile(FakeFile):
def __init__(self, size, char='A', interrupt=None):
FakeFile.__init__(self, char, interrupt)
self.interrupted = False
self.size = 0
self.expected_size = size
def write(self, chars):
eq(chars, self.char*len(chars))
self.offset += len(chars)
self.size += len(chars)
# Sneaky! do stuff on the second seek
if not self.interrupted and self.interrupt != None \
and self.offset > 0:
self.interrupt()
self.interrupted = True
def close(self):
eq(self.size, self.expected_size)
def _verify_atomic_key_data(key, size=-1, char=None):
fp_verify = FakeFileVerifier(char)
key.get_contents_to_file(fp_verify)
if size >= 0:
eq(fp_verify.size, size)
def _test_atomic_read(file_size):
bucket = get_new_bucket()
key = bucket.new_key('testobj')
# create object of <file_size> As
fp_a = FakeWriteFile(file_size, 'A')
key.set_contents_from_file(fp_a)
fp_b = FakeWriteFile(file_size, 'B')
fp_a2 = FakeReadFile(file_size, 'A',
lambda: key.set_contents_from_file(fp_b)
)
# read object while writing it to it
key.get_contents_to_file(fp_a2)
fp_a2.close()
_verify_atomic_key_data(key, file_size, 'B')
def test_atomic_read_1mb():
_test_atomic_read(1024*1024)
def test_atomic_read_4mb():
_test_atomic_read(1024*1024*4)
def test_atomic_read_8mb():
_test_atomic_read(1024*1024*8)
class FakeFileVerifier(object):
def __init__(self, char=None):
self.char = char
@ -2112,19 +2171,13 @@ class FakeFileVerifier(object):
self.size += size
eq(data, self.char*size)
def _verify_atomic_key_data(key, size=-1, char=None):
fp_verify = FakeFileVerifier(char)
key.get_contents_to_file(fp_verify)
if size >= 0:
eq(fp_verify.size, size)
def _test_atomic_write(file_size):
bucket = get_new_bucket()
objname = 'testobj'
key = bucket.new_key(objname)
# create <file_size> file of A's
fp_a = FakeFile(file_size, 'A')
fp_a = FakeWriteFile(file_size, 'A')
key.set_contents_from_file(fp_a)
# verify A's
@ -2132,7 +2185,7 @@ def _test_atomic_write(file_size):
# create <file_size> file of B's
# but try to verify the file before we finish writing all the B's
fp_b = FakeFile(file_size, 'B',
fp_b = FakeWriteFile(file_size, 'B',
lambda: _verify_atomic_key_data(key, file_size)
)
key.set_contents_from_file(fp_b)
@ -2160,8 +2213,8 @@ def _test_atomic_dual_write(file_size):
# write <file_size> file of B's
# but before we're done, try to write all A's
fp_a = FakeFile(file_size, 'A')
fp_b = FakeFile(file_size, 'B',
fp_a = FakeWriteFile(file_size, 'A')
fp_b = FakeWriteFile(file_size, 'B',
lambda: key2.set_contents_from_file(fp_a)
)
key.set_contents_from_file(fp_b)