~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to tests/suite/base/t/failover-mock.lua

  • Committer: jan at mysql
  • Date: 2010-07-22 06:02:56 UTC
  • Revision ID: jan@mysql.com-20100722060256-c4l9eujaqmtosqfz
use "COMMIT SUICIDE" in the mocks directly without using COM_SHUTDOWN

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
-- test if failover works
22
22
--
23
23
-- * this script is started twice to simulate two backends
 
24
-- * one is shutdown in the test with COMMIT SUICIDE
24
25
--
25
26
 
26
 
require("chassis")
27
 
 
28
 
function packet_auth(fields)
29
 
        fields = fields or { }
30
 
        return "\010" ..             -- proto version
31
 
                (fields.version or "5.0.45-proxy") .. -- version
32
 
                "\000" ..             -- term-null
33
 
                "\001\000\000\000" .. -- thread-id
34
 
                "\065\065\065\065" ..
35
 
                "\065\065\065\065" .. -- challenge - part I
36
 
                "\000" ..             -- filler
37
 
                "\001\130" ..         -- server cap (long pass, 4.1 proto)
38
 
                "\008" ..             -- charset
39
 
                "\002\000" ..         -- status
40
 
                ("\000"):rep(13) ..   -- filler
41
 
                "\065\065\065\065"..
42
 
                "\065\065\065\065"..
43
 
                "\065\065\065\065"..
44
 
                "\000"                -- challenge - part II
45
 
end
 
27
require("chassis") -- 
 
28
local proto = require("mysql.proto")
46
29
 
47
30
function connect_server()
48
31
        -- emulate a server
49
32
        proxy.response = {
50
33
                type = proxy.MYSQLD_PACKET_RAW,
51
34
                packets = {
52
 
                        packet_auth()
 
35
                        proto.to_challenge_packet({})
53
36
                }
54
37
        }
55
38
        return proxy.PROXY_SEND_RESULT
63
45
---
64
46
-- 
65
47
function read_query(packet)
66
 
        if packet:byte() == proxy.COM_SHUTDOWN then
67
 
                -- stop the proxy if we are asked to
68
 
                chassis.set_shutdown()
69
 
                proxy.response = {
70
 
                        type = proxy.MYSQLD_PACKET_RAW,
71
 
                        packets = { string.char(254) },
72
 
                }
73
 
                return proxy.PROXY_SEND_RESULT
74
 
        elseif packet:byte() ~= proxy.COM_QUERY then
 
48
        if packet:byte() ~= proxy.COM_QUERY then
75
49
                -- just ACK all non COM_QUERY's
76
50
                proxy.response = {
77
51
                        type = proxy.MYSQLD_PACKET_OK
103
77
                                rows = { { proxy.global.backend_id } }
104
78
                        }
105
79
                }
106
 
 
 
80
        elseif query == 'COMMIT SUICIDE' then
 
81
                -- stop the proxy if we are asked to
 
82
                chassis.set_shutdown()
 
83
                proxy.response = {
 
84
                        type = proxy.MYSQLD_PACKET_OK,
 
85
                        affected_rows = 0,
 
86
                        insert_id = 0
 
87
                }
107
88
        else
108
89
                proxy.response = {
109
90
                        type = proxy.MYSQLD_PACKET_ERR,
110
 
                        errmsg = "(pooling-mock) " .. query
 
91
                        errmsg = "(failover-mock) query not handled: " .. query
111
92
                }
112
93
        end
113
94
        return proxy.PROXY_SEND_RESULT