コード例 #1
0
async def test_cache_group_get_batch_jsonrpc_responses(
        steemd_requests_and_responses):
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()

    cache_group = CacheGroup(caches)

    req, resp = steemd_requests_and_responses
    req = JussiJSONRPCRequest.from_request(dummy_request, 0, req)
    resp['jsonrpc'] = '2.0'
    batch_req = [req, req, req]
    batch_resp = [resp, resp, resp]
    key = jsonrpc_cache_key(req)
    assert await cache_group.get(key) is None
    await cache_group.set('last_irreversible_block_num', 15_000_000)
    await cache_group.cache_jsonrpc_response(batch_req, batch_resp)
    assert await cache_group.get(key) == resp
    assert await cache_group.get_batch_jsonrpc_responses(batch_req
                                                         ) == batch_resp
コード例 #2
0
async def test_cache_group_multi_get():
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()
    cache_group = CacheGroup(caches)

    keys = [str(i) for i in range(len(caches))]
    values = [str(i) for i in range(len(caches))]
    await cache_group.multi_set(zip(keys, values, [None for key in keys]))

    assert await cache_group.multi_get(keys) == values
    assert await caches[0].multi_get(keys) == values
    assert await caches[1].multi_get(keys) == values
    assert await caches[2].multi_get(keys) == values
    assert await caches[3].multi_get(keys) == values

    await cache_group._caches[0].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._caches[1].multi_get(keys) == values
    assert await cache_group._caches[2].multi_get(keys) == values
    assert await cache_group._caches[3].multi_get(keys) == values

    await cache_group._caches[1].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._caches[2].multi_get(keys) == values
    assert await cache_group._caches[3].multi_get(keys) == values

    await cache_group._caches[2].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._caches[3].multi_get(keys) == values
コード例 #3
0
ファイル: test_cache_group.py プロジェクト: G3niusMind/jussi
async def test_cache_group_cache_jsonrpc_response(
        steemd_requests_and_responses):
    caches = [
        CacheGroupItem(SimpleMaxTTLMemoryCache(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache2(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache3(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache4(), True, True, SpeedTier.FAST)
    ]
    for cache_item in caches:
        await cache_item.cache.clear()

    cache_group = CacheGroup(caches)
    req, resp = steemd_requests_and_responses
    req = JussiJSONRPCRequest.from_request(dummy_request, 0, req)
    resp['jsonrpc'] = '2.0'
    key = jsonrpc_cache_key(req)

    assert await cache_group.get(key) is None
    await cache_group.set('last_irreversible_block_num', 15_000_000)
    await cache_group.cache_jsonrpc_response(req, resp)

    for cache_item in caches:
        assert await cache_item.cache.get(key
                                          ) == resp, f'key:{key} urn:{req.urn}'
    assert await cache_group.get(key) == resp, f'key:{key} urn:{req.urn}'
コード例 #4
0
ファイル: test_cache_group.py プロジェクト: G3niusMind/jussi
async def test_cache_group_multi_get():
    caches = [
        CacheGroupItem(SimpleMaxTTLMemoryCache(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache2(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache3(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache4(), True, True, SpeedTier.FAST)
    ]
    for cache_item in caches:
        await cache_item.cache.clear()
    cache_group = CacheGroup(caches)

    keys = [str(i) for i in range(len(caches))]
    values = [str(i) for i in range(len(caches))]
    await cache_group.multi_set(zip(keys, values, [None for key in keys]))

    assert await cache_group.multi_get(keys) == values
    assert await caches[0].cache.multi_get(keys) == values
    assert await caches[1].cache.multi_get(keys) == values
    assert await caches[2].cache.multi_get(keys) == values
    assert await caches[3].cache.multi_get(keys) == values

    await cache_group._read_caches[0].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._read_caches[1].multi_get(keys) == values
    assert await cache_group._read_caches[2].multi_get(keys) == values
    assert await cache_group._read_caches[3].multi_get(keys) == values

    await cache_group._read_caches[1].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._read_caches[2].multi_get(keys) == values
    assert await cache_group._read_caches[3].multi_get(keys) == values

    await cache_group._read_caches[2].clear()
    assert await cache_group.multi_get(keys) == values
    assert await cache_group._read_caches[3].multi_get(keys) == values
コード例 #5
0
async def test_cache_group_set():
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()
    cache_group = CacheGroup(caches)

    await cache_group.set('key', 1)
    for i, cache in enumerate(caches):
        assert await cache.get('key', i)
コード例 #6
0
ファイル: test_cache_group.py プロジェクト: G3niusMind/jussi
async def test_cache_group_set():
    caches = [
        CacheGroupItem(SimpleMaxTTLMemoryCache(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache2(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache3(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache4(), True, True, SpeedTier.FAST)
    ]
    for cache_item in caches:
        await cache_item.cache.clear()
    cache_group = CacheGroup(caches)

    await cache_group.set('key', 1)
    for i, cache_item in enumerate(caches):
        assert await cache_item.cache.get('key', i)
コード例 #7
0
async def test_cache_group_clear():
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()
    cache_group = CacheGroup(caches)

    for cache in caches:
        await cache.set('key', 'value')
    await cache_group.clear()

    assert await cache_group.get('key') is None
コード例 #8
0
ファイル: test_cache_group.py プロジェクト: G3niusMind/jussi
async def test_cache_group_clear():
    caches = [
        CacheGroupItem(SimpleMaxTTLMemoryCache(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache2(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache3(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache4(), True, True, SpeedTier.FAST)
    ]
    for cache_item in caches:
        await cache_item.cache.clear()
    cache_group = CacheGroup(caches)

    for cache_item in caches:
        await cache_item.cache.set('key', 'value')

    await cache_group.clear()

    for cache_item in caches:
        assert await cache_item.cache.get('key') is None
    assert await cache_group.get('key') is None
コード例 #9
0
async def test_cache_group_get_single_jsonrpc_response(
        steemd_requests_and_responses):
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()

    cache_group = CacheGroup(caches)
    req, resp = steemd_requests_and_responses
    resp['jsonrpc'] = '2.0'
    key = jsonrpc_cache_key(req)
    assert await cache_group.get(key) is None
    await cache_group.cache_jsonrpc_response(req, resp, 15_000_000)
    assert await cache_group.get(key) == resp
    assert await cache_group.get_single_jsonrpc_response(req) == resp
    for cache in caches:
        assert await cache.get(key) == resp
コード例 #10
0
async def test_cache_group_multi_set():
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()

    cache_group = CacheGroup(caches)

    keys = [str(i) for i in range(len(caches))]
    values = [str(i) for i in range(len(caches))]
    ttls = [None for i in range(len(caches))]
    triplets = list(zip(keys, values, ttls))
    await cache_group.multi_set(triplets)

    for cache in caches:
        assert await cache.multi_get(keys) == values
        assert await cache_group.multi_get(keys) == values
        await cache.clear()
コード例 #11
0
async def test_cache_group_get():
    caches = [
        SimpleMaxTTLMemoryCache(),
        SimpleMemoryCache2(),
        SimpleMemoryCache3(),
        SimpleMemoryCache4()
    ]
    for cache in caches:
        await cache.clear()
    cache_group = CacheGroup(caches)
    assert caches[0] is not caches[1]

    await cache_group._caches[0].set('key', 0)
    assert await cache_group._caches[0].get('key') == 0

    await cache_group._caches[1].set('key', 1)
    assert await cache_group._caches[0].get('key') == 0
    assert await cache_group._caches[1].get('key') == 1

    await cache_group._caches[2].set('key', 2)
    assert await cache_group._caches[0].get('key') == 0
    assert await cache_group._caches[1].get('key') == 1
    assert await cache_group._caches[2].get('key') == 2

    await cache_group._caches[3].set('key', 3)
    assert await cache_group._caches[0].get('key') == 0
    assert await cache_group._caches[1].get('key') == 1
    assert await cache_group._caches[2].get('key') == 2
    assert await cache_group._caches[3].get('key') == 3

    assert await cache_group.get('key') == 0
    await cache_group._caches[0].delete('key')

    assert await cache_group.get('key') == 1
    await cache_group._caches[1].delete('key')
    assert await cache_group.get('key') == 2
    await cache_group._caches[2].delete('key')
    assert await cache_group.get('key') == 3
コード例 #12
0
ファイル: test_cache_group.py プロジェクト: G3niusMind/jussi
async def test_cache_group_get():
    caches = [
        CacheGroupItem(SimpleMaxTTLMemoryCache(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache2(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache3(), True, True, SpeedTier.FAST),
        CacheGroupItem(SimpleMemoryCache4(), True, True, SpeedTier.FAST)
    ]
    for cache_item in caches:
        await cache_item.cache.clear()
    cache_group = CacheGroup(caches)
    assert caches[0] is not caches[1]

    await cache_group._read_caches[0].set('key', 0)
    assert await cache_group._read_caches[0].get('key') == 0

    await cache_group._read_caches[1].set('key', 1)
    assert await cache_group._read_caches[0].get('key') == 0
    assert await cache_group._read_caches[1].get('key') == 1

    await cache_group._read_caches[2].set('key', 2)
    assert await cache_group._read_caches[0].get('key') == 0
    assert await cache_group._read_caches[1].get('key') == 1
    assert await cache_group._read_caches[2].get('key') == 2

    await cache_group._read_caches[3].set('key', 3)
    assert await cache_group._read_caches[0].get('key') == 0
    assert await cache_group._read_caches[1].get('key') == 1
    assert await cache_group._read_caches[2].get('key') == 2
    assert await cache_group._read_caches[3].get('key') == 3

    assert await cache_group.get('key') == 0
    await cache_group._read_caches[0].delete('key')

    assert await cache_group.get('key') == 1
    await cache_group._read_caches[1].delete('key')
    assert await cache_group.get('key') == 2
    await cache_group._read_caches[2].delete('key')
    assert await cache_group.get('key') == 3