예제 #1
0
def test_read_with_assertion(context):
    context.write_full('foo', b'bar')
    rop = context.read_op_create()
    rop.assert_exists()
    rop.read()
    context.read_op_operate('foo', rop)
    assert b'bar' == rop.read_data()
예제 #2
0
def test_read_attr_gt_fail(context):
    context.write_full('foo', b'Hello world!')
    context.set_xattr('foo', 'attr', b'b')

    rop = context.read_op_create()
    rop.cmpxattr('attr', rados.CmpXattrOp.gt, b'a')
    with pytest.raises(rados.Canceled):
        context.read_op_operate('foo', rop)
예제 #3
0
def test_read_attr_cmp_eq_fail(context):
    context.write_full('foo', b'Hello world!')
    context.set_xattr('foo', 'version', b'3.14')

    rop = context.read_op_create()
    rop.cmpxattr('version', rados.CmpXattrOp.eq, b'2.71')
    with pytest.raises(rados.Canceled):
        context.read_op_operate('foo', rop)
예제 #4
0
def test_read_xattrs(context):
    context.set_xattr('foo', 'a', b'b')

    rop = context.read_op_create()
    rop.get_xattrs()
    context.read_op_operate('foo', rop)

    assert {'a': b'b'} == dict(rop.get_xattrs_data())
예제 #5
0
def test_read_attr_gt(context):
    context.write_full('foo', b'Hello world!')
    context.set_xattr('foo', 'attr', b'a')

    rop = context.read_op_create()
    rop.cmpxattr('attr', rados.CmpXattrOp.gt, b'b')
    rop.stat()
    context.read_op_operate('foo', rop)
    assert 12 == rop.size()
예제 #6
0
def test_read_attr_cmp_eq(context):
    context.write_full('foo', b'Hello world!')
    context.set_xattr('foo', 'version', b'3.14')

    rop = context.read_op_create()
    rop.cmpxattr('version', rados.CmpXattrOp.eq, b'3.14')
    rop.stat()
    context.read_op_operate('foo', rop)
    assert 12 == rop.size()
예제 #7
0
def test_read_stat(context):
    context.write_full('foo', b'Hello world!')

    rop = context.read_op_create()
    rop.assert_exists()
    rop.stat()
    context.read_op_operate('foo', rop)
    assert 12 == rop.size()
    diff = datetime.now() - datetime.fromtimestamp(mktime(rop.mtime()))
    assert 5 > diff.total_seconds()
예제 #8
0
def test_read_with_assertion(context):
    try:
        context.remove('foo')
    except rados.ObjectNotFound:
        pass

    rop = context.read_op_create()
    rop.assert_exists()
    rop.read()
    with pytest.raises(rados.ObjectNotFound):
        context.read_op_operate('foo', rop)
예제 #9
0
def test_read_completion(context):
    context.write_full('foo', b'bar')

    rop = context.read_op_create()
    rop.read()

    def complete_cb(completion):
        complete_cb.called = True

    complete_cb.called = False

    com = rados.Completion(context, oncomplete=complete_cb)
    context.aio_read_op_operate('foo', rop, com)

    com.wait_for_complete_and_cb()

    assert complete_cb.called
예제 #10
0
def test_simple_read(context):
    context.write_full('foo', b'bar')
    rop = context.read_op_create()
    rop.read()
    context.read_op_operate('foo', rop)
    assert b'bar' == rop.read_data()