def _exec_replica_query(self, query): conn = vtclient.VtOCCConnection(self.vtgate_client, 'test_keyspace', '0', 'replica', 30) conn.connect() cursor = conn.cursor() cursor.execute(query, {}) conn.close() return list(cursor)
def _vtdb_conn(self, db_type='master', keyspace='source_keyspace'): global vtgate_protocol if self.vtgate_addrs is None: self.vtgate_addrs = {} conn = vtclient.VtOCCConnection(self.vtgate_client, keyspace, '0', db_type, 30, vtgate_protocol=vtgate_protocol, vtgate_addrs=self.vtgate_addrs) conn.connect() return conn
def _exec_vt_txn(self, query_list=None): if not query_list: return vtdb_conn = vtclient.VtOCCConnection(self.vtgate_client, 'test_keyspace', '0', 'master', 30) vtdb_conn.connect() vtdb_cursor = vtdb_conn.cursor() vtdb_conn.begin() for q in query_list: vtdb_cursor.execute(q, {}) vtdb_conn.commit()
def _vtdb_conn(self, db_type='master', keyspace='source_keyspace'): global client_type vtgate_protocol = None if self.vtgate_addrs is None: self.vtgate_addrs = {} if client_type == TABLET: vtgate_protocol = VTGATE_PROTOCOL_TABLET conn = vtclient.VtOCCConnection(self.vtgate_client, keyspace, '0', db_type, 30, vtgate_protocol=vtgate_protocol, vtgate_addrs=self.vtgate_addrs) conn.connect() return conn
def get_connection(db_type='master', shard_index=0, user=None, password=None): global vtgate_protocol global vtgate_port timeout = 10.0 conn = None shard = shard_names[shard_index] vtgate_addrs = {"_vt": ["localhost:%s" % (vtgate_port),]} vtgate_client = zkocc.ZkOccConnection("localhost:%u" % vtgate_port, "test_nj", 30.0) conn = vtclient.VtOCCConnection(vtgate_client, 'test_keyspace', shard, db_type, timeout, user=user, password=password, vtgate_protocol=vtgate_protocol, vtgate_addrs=vtgate_addrs) conn.connect() return conn
def get_connection(db_type='master', shard_index=0, user=None, password=None): timeout = 10.0 conn = None shard = shard_names[shard_index] vtgate_addrs = { 'vt': [ utils.vtgate.addr(), ] } vtgate_client = zkocc.ZkOccConnection(utils.vtgate.addr(), 'test_nj', 30.0) conn = vtclient.VtOCCConnection(vtgate_client, 'test_keyspace', shard, db_type, timeout, user=user, password=password, vtgate_protocol=vtgate_protocol, vtgate_addrs=vtgate_addrs) conn.connect() return conn
def start_vtocc(klass): klass.user = str(klass.credentials.keys()[0]) klass.password = str(klass.credentials[klass.user][0]) klass.secondary_password = str(klass.credentials[klass.user][1]) klass.vtstderr = open("/tmp/vtocc_stderr.log", "a+") # TODO(szopa): authcredentials klass.process = subprocess.Popen([klass.vtroot +"/bin/vtocc", "-port", str(klass.vtocc_port), "-auth-credentials", klass.credentials_file, "-dbconfig", klass.dbconfig_file], stderr=klass.vtstderr) time.sleep(1) connection = vtclient.VtOCCConnection("localhost:%s" % klass.vtocc_port, klass.dbconfig['keyspace'], klass.dbconfig['shard'], timeout=10, user=klass.user, password=klass.password) connection.dial() cursor = connection.cursor() cursor.execute("create table if not exists connection_test (c int)") connection.begin() cursor.execute("delete from connection_test") cursor.execute("insert into connection_test values (1), (2), (3), (4)") connection.commit()
def _vtdb_conn(self): conn = vtclient.VtOCCConnection(self.vtgate_client, 'test_keyspace', '0', 'master', 30) conn.connect() return conn
def test_vtocc_not_there(self): connection = vtclient.VtOCCConnection("localhost:7777", self.dbconfig['keyspace'], self.dbconfig['shard'], timeout=1, user=self.user, password=self.password) self.assertRaises(dbexceptions.OperationalError, connection.dial)
def setUp(self): self.connection = vtclient.VtOCCConnection(self.vtocc_uri, self.dbconfig['keyspace'], self.dbconfig['shard'], timeout=1, user=self.user, password=self.password) self.connection.dial()