def make_connargs(self, **overrides): bucket = self.bucket_name if 'bucket' in overrides: bucket = overrides.pop('bucket') if self.protocol.startswith('couchbase'): protocol_format = '{0}/{1}'.format(self.host, bucket) elif self.protocol.startswith('http'): protocol_format = '{0}:{1}/{2}'.format(self.host, self.port, bucket) else: raise CouchbaseError('Unrecognised protocol') connstr = self.protocol + '://' + protocol_format final_options = ClusterInformation.filter_opts(self.__dict__) override_options = ClusterInformation.filter_opts(overrides) for k, v in override_options.items(): overrides.pop(k) final_options[k] = override_options[k] conn_options = '&'.join( (key + "=" + value) for key, value in final_options.items()) connstr += ("?" + conn_options) if conn_options else "" ret = {'password': self.bucket_password, 'connection_string': connstr} ret.update(overrides) return ret
def test_get_ttl(self): self.slowTest() key = self.gen_key('get_ttl') self.cb.delete(key, quiet=True) self.cb.set(key, "a_value") rv = self.cb.get(key, ttl=1) self.assertEqual(rv.value, "a_value") sleep(2) rv = self.cb.get(key, quiet=True) self.assertFalse(rv.success) self.assertEqual(NotFoundError, CouchbaseError.rc_to_exctype(rv.rc))
def _make_exc(self, rc, res=None): cls = CouchbaseError.rc_to_exctype(rc) exc = cls("") exc.rc = rc exc.all_results = self._cur.res exc.message = "Operational Error" if res: exc.key = res.key exc.result = res return exc
def test_multi_mixed(self): kv_missing = self.gen_kv_dict(amount=3, prefix='multi_missing_mixed') kv_existing = self.gen_kv_dict(amount=3, prefix='multi_existing_mixed') self.cb.delete_multi(list(kv_missing.keys()) + list(kv_existing.keys()), quiet=True) self.cb.set_multi(kv_existing) rvs = self.cb.get_multi(list(kv_existing.keys()) + list(kv_missing.keys()), quiet=True) self.assertFalse(rvs.all_ok) for k, v in kv_missing.items(): self.assertTrue(k in rvs) self.assertFalse(rvs[k].success) self.assertTrue(rvs[k].value is None) self.assertTrue( CouchbaseError.rc_to_exctype(rvs[k].rc) is NotFoundError) for k, v in kv_existing.items(): self.assertTrue(k in rvs) self.assertTrue(rvs[k].success) self.assertEqual(rvs[k].value, kv_existing[k]) self.assertEqual(rvs[k].rc, 0) # Try this again, but without quiet cb_exc = None try: self.cb.get_multi( list(kv_existing.keys()) + list(kv_missing.keys())) except NotFoundError as e: cb_exc = e self.assertTrue(cb_exc) all_res = cb_exc.all_results self.assertTrue(all_res) self.assertFalse(all_res.all_ok) for k, v in kv_existing.items(): self.assertTrue(k in all_res) self.assertTrue(all_res[k].success) self.assertEqual(all_res[k].value, v) self.assertEqual(all_res[k].rc, 0) for k, v in kv_missing.items(): self.assertTrue(k in all_res) self.assertFalse(all_res[k].success) self.assertTrue(all_res[k].value is None) del cb_exc
def test_multi_mixed(self): kv_missing = self.gen_kv_dict(amount=3, prefix='multi_missing_mixed') kv_existing = self.gen_kv_dict(amount=3, prefix='multi_existing_mixed') self.cb.delete_multi(list(kv_missing.keys()) + list(kv_existing.keys()), quiet=True) self.cb.set_multi(kv_existing) rvs = self.cb.get_multi( list(kv_existing.keys()) + list(kv_missing.keys()), quiet=True) self.assertFalse(rvs.all_ok) for k, v in kv_missing.items(): self.assertTrue(k in rvs) self.assertFalse(rvs[k].success) self.assertTrue(rvs[k].value is None) self.assertTrue(CouchbaseError.rc_to_exctype(rvs[k].rc) is NotFoundError) for k, v in kv_existing.items(): self.assertTrue(k in rvs) self.assertTrue(rvs[k].success) self.assertEqual(rvs[k].value, kv_existing[k]) self.assertEqual(rvs[k].rc, 0) # Try this again, but without quiet cb_exc = None try: self.cb.get_multi(list(kv_existing.keys()) + list(kv_missing.keys())) except NotFoundError as e: cb_exc = e self.assertTrue(cb_exc) all_res = cb_exc.all_results self.assertTrue(all_res) self.assertFalse(all_res.all_ok) for k, v in kv_existing.items(): self.assertTrue(k in all_res) self.assertTrue(all_res[k].success) self.assertEqual(all_res[k].value, v) self.assertEqual(all_res[k].rc, 0) for k, v in kv_missing.items(): self.assertTrue(k in all_res) self.assertFalse(all_res[k].success) self.assertTrue(all_res[k].value is None) del cb_exc
def test_get_multi_ttl(self): self.slowTest() kvs = self.gen_kv_dict(amount=2, prefix='get_multi_ttl') self.cb.set_multi(kvs) rvs = self.cb.get_multi(list(kvs.keys()), ttl=1) for k, v in rvs.items(): self.assertEqual(v.value, kvs[k]) sleep(2) rvs = self.cb.get_multi(list(kvs.keys()), quiet=True) for k, v in rvs.items(): self.assertFalse(v.success) self.assertTrue(k in kvs) self.assertEqual(NotFoundError, CouchbaseError.rc_to_exctype(v.rc))