Ejemplo n.º 1
0
 def _delete_product_after_sleep(self):
     with get_connection() as conn:
         self._sleep(3)
         self._logger.info(f'Delete product')
         pd.delete_product(conn, self.id)
         product = pd.select_product_by_id(conn, self.id)
         self._logger.info(f'Select Product again and got "{product}"')
Ejemplo n.º 2
0
 def _read_after_sleep(self):
     self._sleep(3)
     with get_connection() as conn:
         #conn.begin()
         for i in range(10):
             self._sleep(1)
             # Actually we can read the row even using FOR UPDATE !?
             product = pd.select_product_by_id(conn, self.id)
             self._logger.info(f'Select Product and got "{product}"')
Ejemplo n.º 3
0
 def _select_sleep_select(self):
     with get_connection() as conn:
         self._begin(conn)
         product = pd.select_product_by_id(conn, self.id)
         self._logger.info(f'Got product "{product}" at the first select')
         self._sleep(5)
         # get None when commited here
         #self._commit(conn)
         product = pd.select_product_by_id(conn, self.id)
         self._logger.info(f'Got product "{product}" before commit')
         # still have product due to REPEATABLE READ
         self._commit(conn)
         product = pd.select_product_by_id(conn, self.id)
         self._logger.info(f'Got product "{product}" after commit')
Ejemplo n.º 4
0
    def _select_sleep_update(self):
        with get_connection() as conn:
            self._begin(conn)
            product = pd.select_product_for_update_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" at select for update')
            self._sleep(5)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" before update')

            pd.update_product_total(conn, self.id, 50)
            self._logger.info(f'Product updated')

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after update')

            self._commit(conn)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after commit')
Ejemplo n.º 5
0
    def _select_sleep_update(self):
        with get_connection() as conn:
            self._begin(conn)
            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" at the first select')
            self._sleep(5)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" before update')

            pd.update_product_total(conn, self.id, 50)
            self._logger.info(f'Product updated')

            # Cannot know the update because it was already deleted
            # Can know the update if the record still exists
            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after update')

            self._commit(conn)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after commit')
Ejemplo n.º 6
0
    def _select_sleep_update(self):
        with get_connection() as conn:
            self._begin(conn)
            # When using for share, another thread will get deadlock exception
            # https://stackoverflow.com/questions/32827650/mysql-innodb-difference-between-for-update-and-lock-in-share-mode
            product = pd.select_product_for_share_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" at select for share')
            self._sleep(5)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" before update')

            pd.update_product_total(conn, self.id, 50)
            self._logger.info(f'Product updated')

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after update')

            self._commit(conn)

            product = pd.select_product_by_id(conn, self.id)
            self._logger.info(f'Got product "{product}" after commit')
Ejemplo n.º 7
0
 def _increment_25(self):
     with get_connection() as conn:
         for i in range(25):
             pd.increment_product(conn, self.id)
             self._logger.info(f'Number {i} increment')