예제 #1
0
def test_cache():
    ax = DummyA(1, 10)
    bx = DummyB(2, 2)
    cx = DummyC(3, 3)

    assert f(ax, bx, cx) == 50
    assert h(bx, cx) == 5
    assert score(ax)

    assert smache.is_fun_fresh(score, ax) == True
    assert smache.is_fun_fresh(f, ax, bx, cx) == True
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyB.update(0, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == True
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyA.update(1, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == False
    assert smache.is_fun_fresh(h, bx, cx) == True

    DummyB.update(2, {})

    assert smache.is_fun_fresh(score, ax) == False
    assert smache.is_fun_fresh(f, ax, bx, cx) == False
    assert smache.is_fun_fresh(h, bx, cx) == False
def test_serialization():
    ax = DummyA(1, 10)
    bx = DummyB('2', 2)

    fun_serializer = FunctionSerializer()

    a = InMemoryDataSource(DummyA)
    b = InMemoryDataSource(DummyB)
    raw = RawDataSource()

    e = 'smache:functions:' \
        '"tests.integration.test_function_serialization/score"' \
        '~~~1~~~"2"~~~500' \
        '***(dp0\nS\'resolved\'\np1\nI01\ns.'

    computed_fun = ComputedFunction(score, [a, b, raw])

    key = fun_serializer.serialized_fun(computed_fun, ax, bx, 500,
                                        resolved=True)
    assert key == e

    expected_deserialization = (
        "tests.integration.test_function_serialization/score",
        [1, '2', 500],
        {"resolved": True}
    )
    assert fun_serializer.deserialized_fun(key) == expected_deserialization
예제 #3
0
def test_write_through():
    ax = DummyA(1, 'hello')
    bx = DummyB(1, 'world')

    assert hyphen(ax, bx) == 'hello - world'
    assert slash() == 'hello/hihi'

    assert smache.is_fun_fresh(hyphen, ax, bx) == True

    DummyA.update(1, {'value': 'wtf'})

    execute_all_jobs(worker_queue, redis_con)

    assert smache.is_fun_fresh(hyphen, ax, bx) == True

    assert smache.function_cache_value(hyphen, ax, bx) == 'wtf - world'
예제 #4
0
def test_with_raw_value():
    ax = DummyA(1, 10)
    bx = DummyB(2, 2)

    assert with_raw(ax, bx, 1000) == 12000