Beispiel #1
0
async def test_cache_group_cache_batch_jsonrpc_responses():
    batch_req = [jsonrpc_from_request(dummy_request, _id, {
        "id": _id, "jsonrpc": "2.0", "method": "get_block",
        "params": [_id]
    }) for _id in range(1, 10)]

    batch_resp = [{'id': _id, "jsonrpc": "2.0", 'result': {
        "previous": "0000000000000000000000000000000000000000",
        "timestamp": "2018-09-04T16:36:27",
        "witness": "dpay",
        "transaction_merkle_root": "0000000000000000000000000000000000000000",
        "extensions": [],
        "witness_signature": "201522e89ede4eea643486772bb7cf5fd59224f0de226840124651dcb7a22251d772e1a8a953d7218eddf83618351f33ec401007713070b435253d44a3ad937db2",
        "transactions": [],
        "block_id": "000000011b5056ef5b610531031204f173aef7a8",
        "signing_key": "DWB88FC9nDFczSTfVxrzHvVe8ZuvajLHKikfJYWiKkNvrUebBovzF",
        "transaction_ids": []}} for _id in range(1, 10)]

    caches = [
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST),
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST),
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST)
    ]
    cache_group = CacheGroup(caches)

    keys = [jsonrpc_cache_key(req) for req in batch_req]
    await cache_group.set('last_irreversible_block_num', 15_000_000, 180)
    await cache_group.cache_batch_jsonrpc_response(batch_req, batch_resp)

    for i, key in enumerate(keys):
        assert cache_group._memory_cache.gets(key) == batch_resp[i]
        assert await caches[0].cache.get(key) == batch_resp[i]
        assert await caches[1].cache.get(key) == batch_resp[i]
        assert await caches[2].cache.get(key) == batch_resp[i]
        assert await cache_group.get(key) == batch_resp[i]
Beispiel #2
0
def cache_get_batch(loop, caches, cached, jrpc_batch_req, expected):
    for cache in caches:
        loop.run_until_complete(cache.clear())

    for item in cached:
        if 'id' in cached:
            del cached['id']
        key = jsonrpc_cache_key(item)
        for cache in caches:
            loop.run_until_complete(cache.set(key, item, ttl=None))

    results = loop.run_until_complete(cache_get_batch(caches, jrpc_batch_req))
    assert results == expected
Beispiel #3
0
async def test_cache_group_get_single_jsonrpc_response(
        dpayd_request_and_response):
    caches = [
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST),
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST),
        CacheGroupItem(build_mocked_cache(), True, True, SpeedTier.FAST)
    ]
    cache_group = CacheGroup(caches)

    cache_group = CacheGroup(caches)
    req, resp = dpayd_request_and_response
    req = jsonrpc_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, 180)
    await cache_group.cache_single_jsonrpc_response(req, resp)
    assert await cache_group.get(key) == resp
    assert await cache_group.get_single_jsonrpc_response(req) == resp
    cache_group._memory_cache.clears()
    assert await cache_group.get_single_jsonrpc_response(req) == resp

    for cache_item in caches:
        assert await cache_item.cache.get(key) == resp
Beispiel #4
0
def test_cache_key(urn_test_requests):
    jsonrpc_request, urn, url, ttl, timeout, jefferson_request = urn_test_requests
    result = jsonrpc_cache_key(jefferson_request)
    assert result == urn
Beispiel #5
0
def test_cache_group_x_jefferson_cache_key(dpayd_request_and_response):
    req, resp = dpayd_request_and_response
    req = jsonrpc_from_request(dummy_request, 0, req)
    batch_req = [req, req, req]
    assert jsonrpc_cache_key(req) == CacheGroup.x_jefferson_cache_key(req)
    assert CacheGroup.x_jefferson_cache_key(batch_req) == 'batch'