Exemple #1
0
    def test_simple_transcoder(self):
        tc = Transcoder()
        self.cb.transcoder = tc

        key = self.gen_key("simple_transcoder")
        obj_values = ({}, [], -1, None, False, True)
        for curval in obj_values:
            self.cb.set(key, curval)
            ret = self.cb.get(key)
            self.assertEqual(ret.value, curval)
Exemple #2
0
    def test_pycbc295(self):
        # Test that we ignore the legacy flags and use the common flags
        # instead
        custom_tc = MangledTranscoder()
        orig_tc = Transcoder()

        c = self.make_connection()
        c.transcoder = custom_tc
        custom_tc._op_next['encode_value'] = (json.dumps({
            'Hello': 'World'
        }).encode('utf8'), 0x02000001)
        key = self.gen_key('pycbc295')
        c.upsert(key, 'whatevs')
        c.transcoder = orig_tc
        rv = c.get(key)
        self.assertIsInstance(rv.value, (dict, ))
Exemple #3
0
                type=int,
                help="Duration of run (in seconds)")
ap.add_argument('-T',
                '--transcoder',
                default=False,
                action='store_true',
                help="Use the Transcoder object rather than built-in "
                "conversion routines")

ap.add_argument('--ksize', default=12, type=int, help="Key size to use")

ap.add_argument('--vsize', default=128, type=int, help="Value size to use")

options = ap.parse_args()
DO_UNLOCK_GIL = options.threads > 0
TC = Transcoder()


class Worker(Thread):
    def __init__(self):
        self.delay = options.delay
        self.key = 'K' * options.ksize
        self.value = b'V' * options.vsize
        self.wait_time = 0
        self.opcount = 0
        self.cb = Connection(bucket='default',
                             host=options.hostname,
                             unlock_gil=DO_UNLOCK_GIL)

        if options.transcoder:
            self.cb.transcoder = TC
Exemple #4
0
 def __init__(self):
     self._tc = Transcoder()
     self._op_next = {}
            self._schedule_raw()

    def stop(self):
        self._do_stop = True

global_begin = time()
runners = []
clients = []
kwargs = {
    'bucket': options.bucket,
    'host': options.hostname,
    'password': options.password,
    'unlock_gil': False
}
if options.transcoder:
    kwargs['transcoder'] = Transcoder()

for _ in range(options.clients):
    if options.deferreds:
        cb = Connection(**kwargs)
    else:
        cb = TxAsyncConnection(**kwargs)

    clients.append(cb)
    d = cb.connect()

    def _on_connected(unused, client):
        for _ in range(options.threads):
            r = Runner(client)
            runners.append(r)
    d.addCallback(_on_connected, cb)