mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-22 09:29:43 +00:00
atomic dual-write tests
refactors so the FakeFile and Verifier classes can be used in multiple tests and adds a helper function to verify data. adds new tests similar to the previous atomic write tests, but this time does a second write in the middle of writing (rather than doing a read in the middle)
This commit is contained in:
parent
9279998aa6
commit
d81e2d40e6
1 changed files with 74 additions and 44 deletions
54
test_s3.py
54
test_s3.py
|
@ -1001,11 +1001,6 @@ def test_100_continue():
|
||||||
status = _simple_http_req_100_cont(s3.main.host, s3.main.port, 'PUT', resource)
|
status = _simple_http_req_100_cont(s3.main.host, s3.main.port, 'PUT', resource)
|
||||||
eq(status, '100')
|
eq(status, '100')
|
||||||
|
|
||||||
def _test_atomic_write(file_size):
|
|
||||||
bucket = get_new_bucket()
|
|
||||||
objname = 'testobj'
|
|
||||||
key = bucket.new_key(objname)
|
|
||||||
|
|
||||||
class FakeFile(object):
|
class FakeFile(object):
|
||||||
def __init__(self, size, char='A', interrupt=None):
|
def __init__(self, size, char='A', interrupt=None):
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
|
@ -1043,26 +1038,33 @@ def _test_atomic_write(file_size):
|
||||||
self.size += size
|
self.size += size
|
||||||
eq(data, self.char*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
|
# create <file_size> file of A's
|
||||||
fp_a = FakeFile(file_size, 'A')
|
fp_a = FakeFile(file_size, 'A')
|
||||||
key.set_contents_from_file(fp_a)
|
key.set_contents_from_file(fp_a)
|
||||||
|
|
||||||
# verify A's
|
# verify A's
|
||||||
fp_a_verify = FakeFileVerifier('A')
|
_verify_atomic_key_data(key, file_size, 'A')
|
||||||
key.get_contents_to_file(fp_a_verify)
|
|
||||||
eq(fp_a_verify.size, file_size)
|
|
||||||
|
|
||||||
# create <file_size> file of B's
|
# create <file_size> file of B's
|
||||||
# but try to verify the file before we finish writing all the B's
|
# but try to verify the file before we finish writing all the B's
|
||||||
fp_b = FakeFile(file_size, 'B',
|
fp_b = FakeFile(file_size, 'B',
|
||||||
lambda: key.get_contents_to_file(FakeFileVerifier())
|
lambda: _verify_atomic_key_data(key, file_size)
|
||||||
)
|
)
|
||||||
key.set_contents_from_file(fp_b)
|
key.set_contents_from_file(fp_b)
|
||||||
|
|
||||||
# verify B's
|
# verify B's
|
||||||
fp_b_verify = FakeFileVerifier('B')
|
_verify_atomic_key_data(key, file_size, 'B')
|
||||||
key.get_contents_to_file(fp_b_verify)
|
|
||||||
eq(fp_b_verify.size, file_size)
|
|
||||||
|
|
||||||
def test_atomic_write_1mb():
|
def test_atomic_write_1mb():
|
||||||
_test_atomic_write(1024*1024)
|
_test_atomic_write(1024*1024)
|
||||||
|
@ -1073,3 +1075,31 @@ def test_atomic_write_4mb():
|
||||||
def test_atomic_write_8mb():
|
def test_atomic_write_8mb():
|
||||||
_test_atomic_write(1024*1024*8)
|
_test_atomic_write(1024*1024*8)
|
||||||
|
|
||||||
|
def _test_atomic_dual_write(file_size):
|
||||||
|
bucket = get_new_bucket()
|
||||||
|
objname = 'testobj'
|
||||||
|
key = bucket.new_key(objname)
|
||||||
|
|
||||||
|
# get a second key object (for the same key)
|
||||||
|
# so both can be writing without interfering
|
||||||
|
key2 = bucket.new_key(objname)
|
||||||
|
|
||||||
|
# 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',
|
||||||
|
lambda: key2.set_contents_from_file(fp_a)
|
||||||
|
)
|
||||||
|
key.set_contents_from_file(fp_b)
|
||||||
|
|
||||||
|
# verify the file
|
||||||
|
_verify_atomic_key_data(key, file_size)
|
||||||
|
|
||||||
|
def test_atomic_dual_write_1mb():
|
||||||
|
_test_atomic_dual_write(1024*1024)
|
||||||
|
|
||||||
|
def test_atomic_dual_write_4mb():
|
||||||
|
_test_atomic_dual_write(1024*1024*4)
|
||||||
|
|
||||||
|
def test_atomic_dual_write_8mb():
|
||||||
|
_test_atomic_dual_write(1024*1024*8)
|
||||||
|
|
Loading…
Reference in a new issue