コード例 #1
0
 async def test_delete_many_memcached_metric(self, metrics_registry):
     driver = MemcachedDriver()
     driver._client = AsyncMock()
     await driver.delete_all(["foo", "bar"])
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_total", {"type": "delete_many", "error": "none"}
         )
         == 1.0
     )
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "delete_many"}
         )
         > 0
     )
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_total", {"type": "delete", "error": "none"}
         )
         == 2.0
     )
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "delete"}
         )
         > 0
     )
     assert metrics_registry.get_sample_value("guillotina_cache_memcached_delete_all_num_keys_sum") > 0
コード例 #2
0
async def test_delete_all_empty_keys():
    with mock.patch(
            "guillotina.contrib.memcached.driver.watch") as watch_mocked:
        with mock.patch(
                "guillotina.contrib.memcached.driver.MEMCACHED_OPS_DELETE_ALL_NUM_KEYS"
        ) as all_keys:
            driver = MemcachedDriver()
            driver._client = mock.Mock()
            await driver.delete_all([])
            all_keys.observe.assert_not_called()
            watch_mocked.assert_not_called()
コード例 #3
0
async def test_delete_all():
    with mock.patch(
            "guillotina.contrib.memcached.driver.watch") as watch_mocked:
        with mock.patch(
                "guillotina.contrib.memcached.driver.MEMCACHED_OPS_DELETE_ALL_NUM_KEYS"
        ) as all_keys:
            driver = MemcachedDriver()
            driver._client = mock.Mock()
            await driver.delete_all(["foo", "bar"])
            watch_mocked.assert_called()
            all_keys.observe.assert_called_with(2)
            driver._client.delete.assert_has_calls([
                mock.call(safe_key("foo"), noreply=True),
                mock.call(safe_key("bar"), noreply=True)
            ])
コード例 #4
0
async def test_create_client_sets_configured_params(mocked_create_client,
                                                    param, values):
    for value in values:
        settings = {"hosts": MOCK_HOSTS}
        driver = MemcachedDriver()
        await driver._create_client({**settings, **{param: value}})
        assert mocked_create_client.call_args[1][param] == value
コード例 #5
0
 async def test_get_memcached_metric(self, metrics_registry):
     driver = MemcachedDriver()
     driver._client = AsyncMock()
     await driver.get("foo")
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_total", {"type": "get", "error": "none"}
         )
         == 1.0
     )
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "get"}
         )
         > 0
     )
コード例 #6
0
 async def test_connect_metric(self, metrics_registry, event_loop):
     driver = MemcachedDriver()
     driver._client = AsyncMock()
     await driver.initialize(event_loop)
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_total", {"type": "connect", "error": "none"}
         )
         == 1.0
     )
     assert (
         metrics_registry.get_sample_value(
             "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "connect"}
         )
         > 0
     )
コード例 #7
0
async def test_create_client_returns_emcache_client(memcached_container,
                                                    guillotina_main):
    driver = MemcachedDriver()
    assert driver.client is None
    host, port = memcached_container
    settings = {"hosts": [f"{host}:{port}"]}
    client = await driver._create_client(settings)
    assert isinstance(client, emcache.Client)
コード例 #8
0
async def test_create_client_ignores_invalid_params(mocked_create_client):
    settings = {"hosts": MOCK_HOSTS}
    driver = MemcachedDriver()
    await driver._create_client({"foo": "bar", **settings})
    assert mocked_create_client.call_args[1] == {}
コード例 #9
0
async def test_client_is_initialized_with_configured_hosts(
        mocked_create_client):
    settings = {"hosts": MOCK_HOSTS}
    driver = MemcachedDriver()
    await driver._create_client(settings)
    assert len(mocked_create_client.call_args[0][0]) == 1
コード例 #10
0
def includeme(root, settings):
    global _driver
    _driver = MemcachedDriver()