Пример #1
0
def memcached_multi():
    """Generate keys that will go onto different servers"""
    DB_SETTINGS = memcached_settings()
    db_servers = ['%s:%s' % (s['host'], s['port']) for s in DB_SETTINGS]

    clients = [memcache.Client([s]) for s in db_servers]
    client_all = memcache.Client(db_servers)
    num_servers = len(db_servers)

    for try_num in range(10 * num_servers):
        multi_dict = {}
        for i in range(num_servers):
            random_chars = (random.choice(string.ascii_uppercase)
                            for _ in range(10))
            key_candidate = ''.join(random_chars)
            multi_dict[key_candidate] = key_candidate

        client_all.set_multi(multi_dict)

        server_hit = [False] * num_servers

        for key in multi_dict.keys():
            for i in range(num_servers):
                if clients[i].get(key):
                    server_hit[i] = True

        if all(server_hit):
            break
    else:
        assert False, "memcached_multi failed to map keys to multiple servers."

    return multi_dict
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from testing_support.db_settings import memcached_settings
import bmemcached

from newrelic.api.background_task import background_task
from newrelic.api.transaction import set_background_task

from testing_support.fixtures import validate_transaction_metrics
from testing_support.db_settings import memcached_settings

DB_SETTINGS = memcached_settings()[0]

MEMCACHED_HOST = DB_SETTINGS['host']
MEMCACHED_PORT = DB_SETTINGS['port']
MEMCACHED_NAMESPACE = str(os.getpid())
MEMCACHED_ADDR = '%s:%s' % (MEMCACHED_HOST, MEMCACHED_PORT)

_test_bt_set_get_delete_scoped_metrics = [
    ('Datastore/operation/Memcached/set', 1),
    ('Datastore/operation/Memcached/get', 1),
    ('Datastore/operation/Memcached/delete', 1)
]

_test_bt_set_get_delete_rollup_metrics = [
    ('Datastore/all', 3), ('Datastore/allOther', 3),
    ('Datastore/Memcached/all', 3), ('Datastore/Memcached/allOther', 3),
Пример #3
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import memcache

from newrelic.api.background_task import background_task

from testing_support.fixtures import (validate_transaction_metrics,
                                      override_application_settings)
from testing_support.db_settings import memcached_settings
from testing_support.util import instance_hostname

DB_MULTIPLE_SETTINGS = memcached_settings()

# Settings

_enable_instance_settings = {
    'datastore_tracer.instance_reporting.enabled': True,
}
_disable_instance_settings = {
    'datastore_tracer.instance_reporting.enabled': False,
}

# Metrics

_base_scoped_metrics = (
    ('Datastore/operation/Memcached/get_multi', 1),
    ('Datastore/operation/Memcached/set_multi', 1),