Exemple #1
0
def test_cas_put_get():
    """
    Test: `get(put(x)) == x` with random buffer content
    """
    cas = CAS(ioctx_cas)

    data_in = random_bytes(99)

    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name))
Exemple #2
0
def test_cas_put_get():
    """
    Test: `get(put(x)) == x` with random buffer content
    """
    cas = CAS(ioctx_cas)

    data_in = random_bytes(99)

    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name))
Exemple #3
0
def test_chunker_partial_read_past_size():
    """
    Test: partial reads past *file* size
    """

    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO("\x00" * chunker.chunk_size)
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    buf = chunker.read(obj_name, chunker.chunk_size, chunker.chunk_size, version)

    eq_buffer(buf, "")
Exemple #4
0
def test_chunker_put_get_multiple_fraction():
    """
    Test: read(write(x)) = x for x spread over multiple chunks. With partially filled chunks
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO(random_bytes(int(chunker.chunk_size*1.5)))
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    data_out = StringIO()
    chunker.read_full(obj_name, data_out, version)

    eq_buffer(data_in.getvalue(), data_out.getvalue())
Exemple #5
0
def test_chunker_put_get_single():
    """
    Test: read(write(x)) = x for x filling only a single chunk
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO(random_bytes(42))
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    data_out = StringIO()
    chunker.read_full(obj_name, data_out, version)

    eq_buffer(data_in.getvalue(), data_out.getvalue())
Exemple #6
0
def test_chunker_put_get_multiple_fraction():
    """
    Test: read(write(x)) = x for x spread over multiple chunks. With partially filled chunks
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO(random_bytes(int(chunker.chunk_size * 1.5)))
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    data_out = StringIO()
    chunker.read_full(obj_name, data_out, version)

    eq_buffer(data_in.getvalue(), data_out.getvalue())
Exemple #7
0
def test_chunker_put_get_single():
    """
    Test: read(write(x)) = x for x filling only a single chunk
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO(random_bytes(42))
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    data_out = StringIO()
    chunker.read_full(obj_name, data_out, version)

    eq_buffer(data_in.getvalue(), data_out.getvalue())
Exemple #8
0
def test_chunker_partial_read_past_size():
    """
    Test: partial reads past *file* size
    """

    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO("\x00" * chunker.chunk_size)
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    buf = chunker.read(obj_name, chunker.chunk_size, chunker.chunk_size,
                       version)

    eq_buffer(buf, "")
Exemple #9
0
def test_chunker_partial_read():
    """
    Test: partial reads using chunker.read with different input and weird extents
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO("\x00" * chunker.chunk_size +
                       "\xFF" * chunker.chunk_size)
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    middle = chunker.chunk_size / 2

    buf = chunker.read(obj_name, chunker.chunk_size, middle, version)

    eq(len(buf), chunker.chunk_size)
    eq_buffer("\x00" * (chunker.chunk_size/2) +
              "\xFF" * (chunker.chunk_size/2), buf)
Exemple #10
0
def test_chunker_partial_read():
    """
    Test: partial reads using chunker.read with different input and weird extents
    """
    cas = CAS(ioctx_cas)
    chunker = Chunker(cas, ioctx_index)

    data_in = StringIO("\x00" * chunker.chunk_size +
                       "\xFF" * chunker.chunk_size)
    obj_name = random_id()

    version = chunker.write_full(obj_name, data_in)

    middle = chunker.chunk_size / 2

    buf = chunker.read(obj_name, chunker.chunk_size, middle, version)

    eq(len(buf), chunker.chunk_size)
    eq_buffer(
        "\x00" * (chunker.chunk_size / 2) + "\xFF" * (chunker.chunk_size / 2),
        buf)
Exemple #11
0
def compressed_cas_put_get(cas):
    """
    Test Utility: `get(put(x)) == x` for given `cas` and x in `{random, 1s, 0s}`
    """
    data_in = random_bytes(8*1024**2)
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=8*1024**2))
    cas.down(obj_name)

    data_in = "\xFF" * 11*1024**2
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=11*1024**2))
    cas.down(obj_name)

    data_in = "\x00" * 42
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name))
    cas.down(obj_name)
Exemple #12
0
def compressed_cas_put_get(cas):
    """
    Test Utility: `get(put(x)) == x` for given `cas` and x in `{random, 1s, 0s}`
    """
    data_in = random_bytes(8 * 1024**2)
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=8 * 1024**2))
    cas.down(obj_name)

    data_in = "\xFF" * 11 * 1024**2
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=11 * 1024**2))
    cas.down(obj_name)

    data_in = "\x00" * 42
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name))
    cas.down(obj_name)
Exemple #13
0
def test_mixed_compression():
    """
    Test: Uncompressed put and compressed put afterwards does not change object
    except reference counter
    """

    # Put uncompressed data and then put new objects with compression turned on
    # CAS must not create new objects, but rather increment their reference counter

    cas = CAS(ioctx_cas, compression="no")
    data_in = "\xFF" * 11*1024**2
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=11*1024**2))

    for compression in Compressor.supported():
        ccas = CAS(ioctx_cas, compression=compression)
        tmp_obj_name = ccas.put(data_in)
        eq_buffer(data_in, ccas.get(tmp_obj_name, size=11*1024**2))

    eq_buffer(data_in, cas.get(obj_name, size=11*1024**2))

    info = cas.info(obj_name)
    eq("no", info["cas.meta.compression"])
    eq(len(Compressor.supported()) + 1, info["cas.refcount"])
Exemple #14
0
def test_mixed_compression():
    """
    Test: Uncompressed put and compressed put afterwards does not change object
    except reference counter
    """

    # Put uncompressed data and then put new objects with compression turned on
    # CAS must not create new objects, but rather increment their reference counter

    cas = CAS(ioctx_cas, compression="no")
    data_in = "\xFF" * 11 * 1024**2
    obj_name = cas.put(data_in)
    eq_buffer(data_in, cas.get(obj_name, size=11 * 1024**2))

    for compression in Compressor.supported():
        ccas = CAS(ioctx_cas, compression=compression)
        tmp_obj_name = ccas.put(data_in)
        eq_buffer(data_in, ccas.get(tmp_obj_name, size=11 * 1024**2))

    eq_buffer(data_in, cas.get(obj_name, size=11 * 1024**2))

    info = cas.info(obj_name)
    eq("no", info["cas.meta.compression"])
    eq(len(Compressor.supported()) + 1, info["cas.refcount"])