def test_duplicate_values(lrucache, slabutil):
    "Test insertion of duplicate values in a namespace."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    slabdesc2 = slabutil_make_slab(_NS, slabitems)
    with pytest.raises(ValueError):
        lrucache.insert_slab(slabdesc2)
Esempio n. 2
0
def test_duplicate_values(lrucache, slabutil):
    "Test insertion of duplicate values in a namespace."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    slabdesc2 = slabutil_make_slab(_NS, slabitems)
    with pytest.raises(ValueError):
        lrucache.insert_slab(slabdesc2)
Esempio n. 3
0
def test_namespaces(lrucache, slabutil):
    "Test that different namespaces are distinct."
    values = range(_SLABSZ)
    slabdesc1 = slabutil_make_slab(_NS, zip(map(str, values), values))
    lrucache.insert_slab(slabdesc1)

    slabdesc2 = slabutil_make_slab(
        _NS1, zip(map(str, values), map(lambda x: x * x, values)))
    lrucache.insert_slab(slabdesc2)

    for i in xrange(_SLABSZ):
        st, v1 = lrucache.get(_NS, str(i))
        assert st
        assert v1 == i
        st, v2 = lrucache.get(_NS1, str(i))
        assert st
        assert v2 == i * i
def test_namespaces(lrucache, slabutil):
    "Test that different namespaces are distinct."
    values = range(_SLABSZ)
    slabdesc1 = slabutil_make_slab(_NS, zip(map(str, values), values))
    lrucache.insert_slab(slabdesc1)

    slabdesc2 = slabutil_make_slab(_NS1, zip(map(str, values),
                                             map(lambda x: x*x, values)))
    lrucache.insert_slab(slabdesc2)

    for i in xrange(_SLABSZ):
        st, v1 = lrucache.get(_NS, str(i))
        assert st
        assert v1 == i
        st, v2 = lrucache.get(_NS1, str(i))
        assert st
        assert v2 == i*i
Esempio n. 5
0
def test_duplicate_slabdesc(lrucache, slabutil):
    "Test insertion of a duplicate slab descriptor."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)

    lrucache.insert_slab(slabdesc)
    with pytest.raises(ValueError):
        lrucache.insert_slab(slabdesc)
Esempio n. 6
0
def test_get_nonexistent_element(lrucache, slabutil):
    "Test that a missing keys is shown as not-present."
    values = range(0, _SLABSZ, 2)  # Alternate elements.
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    st, v = lrucache.get(_NS, '1')  # Valid namespace, missing key
    assert not st
    assert v == '1'
Esempio n. 7
0
def test_get_nonexistent(lrucache, slabutil):
    "Test that unknown keys are rejected."
    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    assert lrucache.get(_NS + _NS, '0') is None  # Invalid namespace, valid key
    # Valid namespace, out-of-slab key
    assert lrucache.get(_NS, _SLABSZ + 1) is None
def test_duplicate_slabdesc(lrucache, slabutil):
    "Test insertion of a duplicate slab descriptor."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)

    lrucache.insert_slab(slabdesc)
    with pytest.raises(ValueError):
        lrucache.insert_slab(slabdesc)
def test_get_nonexistent_element(lrucache, slabutil):
    "Test that a missing keys is shown as not-present."
    values = range(0, _SLABSZ, 2) # Alternate elements.
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    st, v = lrucache.get(_NS, '1') # Valid namespace, missing key
    assert not st
    assert v == '1'
def test_get_nonexistent(lrucache, slabutil):
    "Test that unknown keys are rejected."
    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)
    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    assert lrucache.get(_NS+_NS, '0') is None # Invalid namespace, valid key
    # Valid namespace, out-of-slab key
    assert lrucache.get(_NS, _SLABSZ+1) is None
Esempio n. 11
0
def test_get(lrucache, slabutil):
    "Test insert and retrieval of one slab descriptor."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)

    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    for i in xrange(_SLABSZ):
        st, v = lrucache.get(_NS, str(i))
        assert st
        assert v == values[i]
def test_get(lrucache, slabutil):
    "Test insert and retrieval of one slab descriptor."

    values = range(_SLABSZ)
    keys = map(str, values)
    slabitems = zip(keys, values)

    slabdesc = slabutil_make_slab(_NS, slabitems)
    lrucache.insert_slab(slabdesc)

    for i in xrange(_SLABSZ):
        st, v = lrucache.get(_NS, str(i))
        assert st
        assert v == values[i]
Esempio n. 13
0
def test_remove(lrucache, slabutil):
    "Test the remove_slab() method."

    values1 = range(_SLABSZ)
    slabdesc1 = slabutil_make_slab(_NS, zip(map(str, values1), values1))
    lrucache.insert_slab(slabdesc1)

    values2 = range(_SLABSZ, 2 * _SLABSZ)
    slabdesc2 = slabutil_make_slab(_NS, zip(map(str, values2), values2))
    lrucache.insert_slab(slabdesc2)

    # Remove the first slab.
    lrucache.remove_slab(slabdesc1)

    # Items in the original slab should be missing.
    for i in xrange(_SLABSZ):
        st = lrucache.get(_NS, str(i))
        assert st is None

    # Items in the second slab should be present.
    for i in xrange(_SLABSZ, 2 * _SLABSZ):
        st, v = lrucache.get(_NS, str(i))
        assert st
        assert v == i
def test_remove(lrucache, slabutil):
    "Test the remove_slab() method."

    values1 = range(_SLABSZ)
    slabdesc1 = slabutil_make_slab(_NS,  zip(map(str, values1), values1))
    lrucache.insert_slab(slabdesc1)

    values2 = range(_SLABSZ, 2*_SLABSZ)
    slabdesc2 = slabutil_make_slab(_NS,  zip(map(str, values2), values2))
    lrucache.insert_slab(slabdesc2)

    # Remove the first slab.
    lrucache.remove_slab(slabdesc1)

    # Items in the original slab should be missing.
    for i in xrange(_SLABSZ):
        st = lrucache.get(_NS, str(i))
        assert st is None

    # Items in the second slab should be present.
    for i in xrange(_SLABSZ, 2 * _SLABSZ):
        st, v = lrucache.get(_NS, str(i))
        assert st
        assert v == i
Esempio n. 15
0
 def _mkslab(i):
     v = [i * _SLABSZ]
     return slabutil_make_slab(_NS, zip(map(str, v), v))
 def _mkslab(i):
     v = [i * _SLABSZ]
     return slabutil_make_slab(_NS, zip(map(str, v), v))