示例#1
0
def create_db_connector(use_gevent):
    global _db_connector

    if use_gevent:
        from couchbase import experimental

        experimental.enable()
        from gcouchbase.connection import GConnection

        _db_connector = GConnection
    else:
        from couchbase import Couchbase

        _db_connector = Couchbase.connect

    return _db_connector
#
try:
    import asyncio
except ImportError:
    import trollius

    asyncio = trollius

import argparse
from time import time


from couchbase.user_constants import FMT_BYTES
from couchbase.experimental import enable

enable()
from acouchbase.bucket import Bucket

ap = argparse.ArgumentParser()

ap.add_argument(
    "-t",
    "--threads",
    default=4,
    type=int,
    help="Number of threads to spawn. 0 means no threads " "but workload will still run in the main thread",
)

ap.add_argument(
    "-d", "--delay", default=0, type=float, help="Number of seconds to wait between each op. " "may be a fraction"
)
示例#3
0
import random
from hashlib import md5

from couchbase import experimental
from twisted.internet import reactor
from txcouchbase.connection import Connection

from logger import logger

experimental.enable()


class SmallIterator:

    FIXED_KEY_WIDTH = 12
    RND_FIELD_SIZE = 16

    def __iter__(self):
        return self

    def _id(self, i):
        return '{}'.format(i).zfill(self.FIXED_KEY_WIDTH)

    def _key(self, _id):
        return 'AB_{}_0'.format(_id)

    def _field(self, _id):
        _id = _id.encode('utf-8')
        data = md5(_id).hexdigest()[:16]
        return {'pn': str(_id), 'nam': 'ViberPhone_{}'.format(data)}
示例#4
0
from urllib import parse

import pkg_resources

from spring.cbgen_helpers import backoff, quiet, timeit

cb_version = pkg_resources.get_distribution("couchbase").version
if cb_version[0] == '2':
    from couchbase import experimental, subdocument
    from couchbase.bucket import Bucket
    from couchbase.n1ql import N1QLQuery
    from couchbase.views.params import ViewQuery
    from txcouchbase.connection import Connection as TxConnection
    experimental.enable()


class CBAsyncGen:

    TIMEOUT = 120  # seconds

    def __init__(self, **kwargs):
        self.client = TxConnection(quiet=True, **kwargs)
        self.client.timeout = self.TIMEOUT

    def create(self,
               key: str,
               doc: dict,
               persist_to: int = 0,
               replicate_to: int = 0,
               ttl: int = 0):
        return self.client.upsert(key,
示例#5
0
import asyncio
import unittest

from couchbase.experimental import enable
enable()
from fixtures import asynct, AioTestCase
from couchbase.n1ql import N1QLQuery
from couchbase.exceptions import CouchbaseError


class CouchbaseBeerTest(AioTestCase):
    def setUp(self):
        try:
            return super(CouchbaseBeerTest, self).setUp(bucket='beer-sample')
        except CouchbaseError:
            raise SkipTest("Need 'beer-sample' bucket for this")

    @asynct
    @asyncio.coroutine
    def test_get_data(self):
        beer_bucket = self.cb
        yield from (beer_bucket.connect() or asyncio.sleep(0.01))

        data = yield from beer_bucket.get('21st_amendment_brewery_cafe')
        self.assertEqual("21st Amendment Brewery Cafe", data.value["name"])

    @asynct
    @asyncio.coroutine
    def test_query(self):
        beer_bucket = self.cb
import asyncio
import unittest

from couchbase.experimental import enable; enable()
from fixtures import asynct, AioTestCase
from couchbase.n1ql import N1QLQuery



class CouchbaseBeerTest(AioTestCase):

    def make_connection(self):
        try:
            return super().make_connection(bucket='beer-sample')
        except CouchbaseError:
            raise SkipTest("Need 'beer-sample' bucket for this")

    @asynct
    @asyncio.coroutine
    def test_get_data(self):
        beer_bucket = self.cb
        yield from (beer_bucket.connect() or asyncio.sleep(0.01))

        data = yield from beer_bucket.get('21st_amendment_brewery_cafe')
        self.assertEqual("21st Amendment Brewery Cafe", data.value["name"])

    @asynct
    @asyncio.coroutine
    def test_query(self):
        beer_bucket = self.cb
示例#7
0
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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 argparse
from time import time

from twisted.internet import reactor

from couchbase import experimental
experimental.enable() # Enable experimental features on import

from txcouchbase.connection import Connection, TxAsyncConnection
from couchbase.connection import FMT_BYTES
from couchbase.transcoder import Transcoder

ap = argparse.ArgumentParser()

ap.add_argument('-t', '--threads', default=4, type=int,
                help="Number of threads to spawn. 0 means no threads "
                "but workload will still run in the main thread")

ap.add_argument('-d', '--delay', default=0, type=float,
                help="Number of seconds to wait between each op. "
                "may be a fraction")