Exemplo n.º 1
0
    def testLargePackets(self):
        cnn = client.connect(host=DB_HOST,
                             user=DB_USER,
                             password=DB_PASSWD,
                             db=DB_DB)

        cnn.query("truncate tbltest")

        c = cnn.buffer.capacity

        blob = '0123456789'
        while 1:
            cnn.query(
                "insert into tbltest (test_id, test_blob) values (%d, '%s')" %
                (len(blob), blob))
            if len(blob) > (c * 2): break
            blob = blob * 2

        rs = cnn.query("select test_id, test_blob from tbltest")
        for row in rs:
            self.assertEquals(row[0], len(row[1]))
            self.assertEquals(blob[:row[0]], row[1])
        rs.close()

        #reread, second time, oversize packet is already present
        rs = cnn.query("select test_id, test_blob from tbltest")
        for row in rs:
            self.assertEquals(row[0], len(row[1]))
            self.assertEquals(blob[:row[0]], row[1])
        rs.close()
        cnn.close()

        #have a very low max packet size for oversize packets
        #and check that exception is thrown when trying to read larger packets
        from geventmysql import _mysql
        _mysql.MAX_PACKET_SIZE = 1024 * 4

        cnn = client.connect(host=DB_HOST,
                             user=DB_USER,
                             password=DB_PASSWD,
                             db=DB_DB)

        try:
            rs = cnn.query("select test_id, test_blob from tbltest")
            for row in rs:
                self.assertEquals(row[0], len(row[1]))
                self.assertEquals(blob[:row[0]], row[1])
            self.fail()
        except PacketReadError:
            pass
        finally:
            try:
                rs.close()
            except:
                pass
            cnn.close()
Exemplo n.º 2
0
    def testLargePackets(self):
        cnn = client.connect(host = DB_HOST, user = DB_USER,
                             password = DB_PASSWD, db = DB_DB)


        cnn.query("truncate tbltest")

        c = cnn.buffer.capacity

        blob = '0123456789'
        while 1:
            cnn.query("insert into tbltest (test_id, test_blob) values (%d, '%s')" % (len(blob), blob))
            if len(blob) > (c * 2): break
            blob = blob * 2

        rs = cnn.query("select test_id, test_blob from tbltest")
        for row in rs:
            self.assertEquals(row[0], len(row[1]))
            self.assertEquals(blob[:row[0]], row[1])
        rs.close()

        #reread, second time, oversize packet is already present
        rs = cnn.query("select test_id, test_blob from tbltest")
        for row in rs:
            self.assertEquals(row[0], len(row[1]))
            self.assertEquals(blob[:row[0]], row[1])
        rs.close()
        cnn.close()

        #have a very low max packet size for oversize packets
        #and check that exception is thrown when trying to read larger packets
        from geventmysql import _mysql
        _mysql.MAX_PACKET_SIZE = 1024 * 4

        cnn = client.connect(host = DB_HOST, user = DB_USER,
                             password = DB_PASSWD, db = DB_DB)

        try:
            rs = cnn.query("select test_id, test_blob from tbltest")
            for row in rs:
                self.assertEquals(row[0], len(row[1]))
                self.assertEquals(blob[:row[0]], row[1])
            self.fail()
        except PacketReadError:
            pass
        finally:
            try:
                rs.close()
            except:
                pass
            cnn.close()
Exemplo n.º 3
0
    def testMySQLTimeout(self):
        cnn = client.connect(host=DB_HOST,
                             user=DB_USER,
                             password=DB_PASSWD,
                             db=DB_DB)

        rs = cnn.query("select sleep(2)")
        list(rs)
        rs.close()

        from gevent import Timeout

        start = time.time()
        try:

            def delay():
                cnn.query("select sleep(4)")
                self.fail('expected timeout')

            gevent.with_timeout(2, delay)
        except Timeout:
            end = time.time()
            self.assertAlmostEqual(2.0, end - start, places=1)

        cnn.close()
Exemplo n.º 4
0
    def testMySQLClient2(self):
        cnn = client.connect(host=DB_HOST,
                             user=DB_USER,
                             password=DB_PASSWD,
                             db=DB_DB)

        cnn.query("truncate tbltest")

        for i in range(10):
            self.assertEquals(
                (1, 0),
                cnn.query(
                    "insert into tbltest (test_id, test_string) values (%d, 'test%d')"
                    % (i, i)))

        rs = cnn.query("select test_id, test_string from tbltest")

        #trying to close it now would give an error, e.g. we always need to read
        #the result from the database otherwise connection would be in wrong stat
        try:
            rs.close()
            self.fail('expected exception')
        except client.ClientProgrammingError:
            pass

        for i, row in enumerate(rs):
            self.assertEquals((i, 'test%d' % i), row)

        rs.close()
        cnn.close()
Exemplo n.º 5
0
    def testConnectNoDb(self):
        cnn = client.connect(host = DB_HOST, user = DB_USER, password = DB_PASSWD)

        rs = cnn.query("select 1")

        self.assertEqual([(1,)], list(rs))

        rs.close()
        cnn.close()
Exemplo n.º 6
0
    def testConnectNoDb(self):
        cnn = client.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWD)

        rs = cnn.query("select 1")

        self.assertEqual([(1, )], list(rs))

        rs.close()
        cnn.close()
Exemplo n.º 7
0
    def testMySQLTimeout(self):
        cnn = client.connect(host = DB_HOST, user = DB_USER,
                             password = DB_PASSWD, db = DB_DB)

        rs = cnn.query("select sleep(2)")
        list(rs)
        rs.close()

        from gevent import Timeout

        start = time.time()
        try:
            def delay():
                cnn.query("select sleep(4)")
                self.fail('expected timeout')
            gevent.with_timeout(2, delay)
        except Timeout:
            end = time.time()
            self.assertAlmostEqual(2.0, end - start, places = 1)

        cnn.close()
Exemplo n.º 8
0
    def testMySQLClient2(self):
        cnn = client.connect(host = DB_HOST, user = DB_USER,
                             password = DB_PASSWD, db = DB_DB)

        cnn.query("truncate tbltest")

        for i in range(10):
            self.assertEquals((1, 0), cnn.query("insert into tbltest (test_id, test_string) values (%d, 'test%d')" % (i, i)))

        rs = cnn.query("select test_id, test_string from tbltest")

        #trying to close it now would give an error, e.g. we always need to read
        #the result from the database otherwise connection would be in wrong stat
        try:
            rs.close()
            self.fail('expected exception')
        except client.ClientProgrammingError:
            pass

        for i, row in enumerate(rs):
            self.assertEquals((i, 'test%d' % i), row)

        rs.close()
        cnn.close()