def test_cozydb_cozycursor_does_not_retry_delete(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('delete from table1 where id=%s', (100, ), retry=1) cursor1.connection.rollback()
def test_cozydb_cozycursor_does_not_retry_delete(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('delete from table1 where id=%s', (100, ), retry=1) cursor1.connection.rollback()
def test_cozydb_cozycursor_retry_select(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('select 1', retry=1) eq_(cursor1.fetchone(), (1,)) err_msg = 'Thread id did not change after re-connect, it should be' ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
def test_cozydb_cozycursor_force_retry(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('update table1 set rank=%s where id=%s', (1, 1), retry=1, force_retry=True) cursor1.connection.rollback()
def test_cozydb_cozycursor_does_not_retry_insert(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('insert into table1 (name, rank) values (%s, %s)', ('name4', 4), retry=1) cursor1.connection.rollback()
def test_cozydb_cozycursor_retry_select(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('select 1', retry=1) eq_(cursor1.fetchone(), (1, )) err_msg = 'Thread id did not change after re-connect, it should be' ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
def test_cozydb_cozycursor_force_retry(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('update table1 set rank=%s where id=%s', (1, 1), retry=1, force_retry=True) cursor1.connection.rollback()
def test_cozydb_cozycursor_does_not_retry_insert(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) cursor1.execute('insert into table1 (name, rank) values (%s, %s)', ('name4', 4), retry=1) cursor1.connection.rollback()
def test_cozydb_cozycursor_reconnect(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) try: cursor1.execute('select 1') except MySQLdb.OperationalError: pass else: ok_(False, '%r connection did not break, it should be' % cursor1) cursor1.execute('select 1') eq_(cursor1.fetchone(), (1,)) err_msg = 'Thread id did not change after re-connect, it should be' ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
def test_cozydb_cozycursor_reconnect(self): cursor1 = CozyCursor(**self.db_args) thread_id1 = cursor1.connection.thread_id() # Kill connection of cursor1, test re-connect ability then cursor2 = CozyCursor(**self.db_args) cursor2.execute('kill %d' % thread_id1) # wait MySQL server for disconnecting killed connection time.sleep(0.02) try: cursor1.execute('select 1') except MySQLdb.OperationalError: pass else: ok_(False, '%r connection did not break, it should be' % cursor1) cursor1.execute('select 1') eq_(cursor1.fetchone(), (1, )) err_msg = 'Thread id did not change after re-connect, it should be' ok_(thread_id1 != cursor1.connection.thread_id(), err_msg)
def test_cozydb_cozycursor_fetchall_dict(self): cursor = CozyCursor(**self.db_args) cursor.execute('select 1 as name') eq_(cursor.fetchall(as_dict=True), ({'name': 1},))
def test_cozydb_cozycursor(self): cursor = CozyCursor(**self.db_args) cursor.execute('select 1') eq_(cursor.fetchone(), (1,))
def test_cozydb_cozycursor_fetchall_dict(self): cursor = CozyCursor(**self.db_args) cursor.execute('select 1 as name') eq_(cursor.fetchall(as_dict=True), ({'name': 1}, ))
def test_cozydb_cozycursor(self): cursor = CozyCursor(**self.db_args) cursor.execute('select 1') eq_(cursor.fetchone(), (1, ))