Ejemplo n.º 1
0
    def test_recursive_transaction(self):
        """test recursive transaction"""
        table = self._create_table(('name VARCHAR(10)', ), None)

        connection_holder = Connection(self._context.make_connection())
        query = transaction(self.get_insert_query(table))
        connection_holder.commit = self.count_calls(connection_holder.commit)
        connection_holder.commit.call_count = 0
        self._context.wait(connection_holder.execute(transaction(query)))
        self.assertEqual(1, connection_holder.commit.call_count)
Ejemplo n.º 2
0
    def test_recursive_transaction(self):
        """test recursive transaction"""
        table = self._create_table(('name VARCHAR(10)',), None)

        connection_holder = Connection(self._context.make_connection())
        query = transaction(self.get_insert_query(table))
        connection_holder.commit = self.count_calls(connection_holder.commit)
        connection_holder.commit.call_count = 0
        self._context.wait(connection_holder.execute(transaction(query)))
        self.assertEqual(1, connection_holder.commit.call_count)
Ejemplo n.º 3
0
    def test_commit(self):
        """test transaction commit"""
        table = self._create_table(('name VARCHAR(10)',), None)

        connection = Connection(self._context.make_connection())
        query = self.get_insert_query(table)
        self.assertIs(self._context.wait(connection.execute(transaction(query))), True)

        self._context.wait(connection.rollback())
        cursor = self._context.cursor()
        self._context.wait(cursor.execute("SELECT * FROM %s" % table))
        self.assertEqual([('Evelina',)], cursor.fetchall())
Ejemplo n.º 4
0
    def test_commit(self):
        """test transaction commit"""
        table = self._create_table(('name VARCHAR(10)', ), None)

        connection = Connection(self._context.make_connection())
        query = self.get_insert_query(table)
        self.assertIs(
            self._context.wait(connection.execute(transaction(query))), True)

        self._context.wait(connection.rollback())
        cursor = self._context.cursor()
        self._context.wait(cursor.execute("SELECT * FROM %s" % table))
        self.assertEqual([('Evelina', )], cursor.fetchall())
Ejemplo n.º 5
0
    def test_cluster(self):
        """ test commutator """
        read_connection = Connection(self._context.make_connection())
        write_connection = Connection(self._context.make_connection())
        read_connection.readonly = True
        write_connection.readonly = False
        read_query = self.wrap_query(lambda x: self.assertTrue(x.readonly))
        write_query = transaction(self.wrap_query(lambda x: self.assertFalse(x.readonly)))

        cluster = Cluster(master=write_connection, slave=read_connection)
        self._context.wait(cluster.execute(read_query))
        self._context.wait(cluster.execute(write_query))

        cluster = Cluster(master=None, slave=read_connection)
        self.assertRaisesRegex(Exception, "the operation is not permitted on read-only cluster", cluster.execute, write_query)
Ejemplo n.º 6
0
    def test_transaction_rollback(self):
        """test transaction rollback"""
        table = self._create_table(('name VARCHAR(10)', ), None)

        connection_holder = Connection(self._context.make_connection())
        query = self.get_insert_query(table, Exception('rollback expected!'))
        self.assertRaisesRegex(Exception, 'rollback expected!',
                               self._context.call_and_wait,
                               connection_holder.execute, transaction(query))

        cursor = self._context.cursor()
        self._context.wait(cursor.execute("SELECT * FROM %s" % table))
        self.assertEqual([], cursor.fetchall())
Ejemplo n.º 7
0
    def test_retries(self):
        """test retries"""
        retry_count = 3
        delay = 0.1

        connection = retryable(Connection(self._context.make_connection()),
                               retry_count, delay)
        query = self.make_exception_query(retry_count - 1)
        self._context.wait(connection.execute(query))

        self.assertEqual(retry_count - 1, query.call_count)
        query = self.make_exception_query(retry_count + 1)
        self.assertRaises(Exception, self._context.call_and_wait,
                          connection.execute, query)
Ejemplo n.º 8
0
    def test_cluster(self):
        """ test commutator """
        read_connection = Connection(self._context.make_connection())
        write_connection = Connection(self._context.make_connection())
        read_connection.readonly = True
        write_connection.readonly = False
        read_query = self.wrap_query(lambda x: self.assertTrue(x.readonly))
        write_query = transaction(
            self.wrap_query(lambda x: self.assertFalse(x.readonly)))

        cluster = Cluster(master=write_connection, slave=read_connection)
        self._context.wait(cluster.execute(read_query))
        self._context.wait(cluster.execute(write_query))

        cluster = Cluster(master=None, slave=read_connection)
        self.assertRaisesRegex(
            Exception, "the operation is not permitted on read-only cluster",
            cluster.execute, write_query)