def test_sdk_client(self): """ Test SDK Client Calls """ scheme = "couchbase" host = self.master.ip if self.master.ip == "127.0.0.1": scheme = "http" host = "{0}:{1}".format(self.master.ip, self.master.port) client = SDKClient(scheme=scheme, hosts=[host], bucket="default") client.remove("1", quiet=True) client.insert("1", "{1:2}") flag, cas, val = client.get("1") self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.upsert("1", "{1:3}") client.touch("1", ttl=100) flag, cas, val = client.get("1") self.assertTrue(val == "{1:3}", val) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.remove("1", cas=cas) client.incr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 5) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.incr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 25) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.decr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 5) print flag, cas, val client.upsert("key1", "document1") client.upsert("key2", "document2") client.upsert("key3", "document3") set = client.get_multi(["key1", "key2"]) self.log.info(set) client.upsert_multi({"key1": "{1:2}", "key2": "{3:2}"}) set = client.get_multi(["key1", "key2"]) self.log.info(set) client.touch_multi(["key1", "key2"], ttl=200) set = client.get_multi(["key1", "key2"]) self.log.info(set) data = client.observe("key1") self.log.info(data) data = client.observe_multi(["key1", "key2"]) self.log.info(data) stats = client.stats(["key1"]) self.log.info(stats) client.n1ql_request( client.n1ql_query('create primary index on default')).execute() query = client.n1ql_query('select * from default') request = client.n1ql_request(query) obj = request.get_single_result()._jsobj self.log.info(obj) client.close()
def test_sdk_client(self): """ Test SDK Client Calls """ scheme = "couchbase" host=self.master.ip if self.master.ip == "127.0.0.1": scheme = "http" host="{0}:{1}".format(self.master.ip,self.master.port) client = SDKClient(scheme=scheme,hosts = [host], bucket = "default") client.remove("1",quiet=True) client.insert("1","{1:2}") flag, cas, val = client.get("1") self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.upsert("1","{1:3}") client.touch("1",ttl=100) flag, cas, val = client.get("1") self.assertTrue(val == "{1:3}", val) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.remove("1",cas = cas) client.incr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 5) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.incr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 25) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.decr("key", delta=20, initial=5) flag, cas, val = client.get("key") self.assertTrue(val == 5) print flag, cas, val client.upsert("key1","document1") client.upsert("key2","document2") client.upsert("key3","document3") set = client.get_multi(["key1","key2"]) self.log.info(set) client.upsert_multi({"key1":"{1:2}","key2":"{3:2}"}) set = client.get_multi(["key1","key2"]) self.log.info(set) client.touch_multi(["key1","key2"],ttl=200) set = client.get_multi(["key1","key2"]) self.log.info(set) data = client.observe("key1") self.log.info(data) data = client.observe_multi(["key1","key2"]) self.log.info(data) stats = client.stats(["key1"]) self.log.info(stats) client.n1ql_request(client.n1ql_query('create primary index on default')).execute() query = client.n1ql_query('select * from default') request = client.n1ql_request(query) obj = request.get_single_result()._jsobj self.log.info(obj) client.close()
def test_sdk_client(self): """ Test SDK Client Calls """ client = SDKClient(scheme="couchbase",hosts = [self.master], bucket = "default") client.remove("1",quiet=True) client.insert("1","{1:2}") val, flag, cas = client.get("1") self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.upsert("1","{1:3}") client.touch("1",ttl=100) val, flag, cas = client.get("1") self.assertTrue(val == "{1:3}") self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.remove("1",cas = cas) client.incr("key", delta=20, initial=5) val, flag, cas = client.get("key") self.assertTrue(val == 5) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.incr("key", delta=20, initial=5) val, flag, cas = client.get("key") self.assertTrue(val == 25) self.log.info("val={0},flag={1},cas={2}".format(val, flag, cas)) client.decr("key", delta=20, initial=5) val, flag, cas = client.get("key") self.assertTrue(val == 5) print val, flag, cas client.upsert("key1","document1") client.upsert("key2","document2") client.upsert("key3","document3") set = client.get_multi(["key1","key2"]) self.log.info(set) client.upsert_multi({"key1":"{1:2}","key2":"{3:2}"}) set = client.get_multi(["key1","key2","key3"]) self.log.info(set) client.touch_multi(["key1","key2","key3"],ttl=200) set = client.get_multi(["key1","key2","key3"]) self.log.info(set) set = client.get_multi(["key1","key2","key3"],replica=True) self.log.info(set) data = client.observe("key1") self.log.info(data) data = client.observe_multi(["key1","key2"]) self.log.info(data) stats = client.stats(["key1"]) self.log.info(stats) client.close()
def key_not_exists_test(self): client = SDKClient(hosts = [self.master.ip], bucket = "default") KEY_NAME = 'key' for i in range(1500): client.set(KEY_NAME, "x") #For some reason could not get delete to work client.remove(KEY_NAME) rc = client.get(KEY_NAME) #.get is automatically set to quiet for the sdk_client, therefore I look for #none to indicate an error, otherwise the sdk_client spends 10 seconds trying #to retry the commands and is very slow if rc[2] == None: pass else: assert False #cas errors do not sleep the test for 10 seconds, plus we need to check that the correct #error is being thrown try: #For some reason replace instead of cas would not reproduce the bug client.cas(KEY_NAME, "value", cas = 10) except NotFoundError: pass assert True