|
| 1 | +local server = require('luatest.server') |
| 2 | +local t = require('luatest') |
| 3 | +local g = t.group() |
| 4 | + |
| 5 | +g.before_all(function(cg) |
| 6 | + cg.server = server:new() |
| 7 | + cg.server:start() |
| 8 | +end) |
| 9 | + |
| 10 | +g.after_all(function(cg) |
| 11 | + cg.server:drop() |
| 12 | +end) |
| 13 | + |
| 14 | +g.after_each(function(cg) |
| 15 | + cg.server:exec(function() |
| 16 | + if box.space.test ~= nil then |
| 17 | + box.space.test:drop() |
| 18 | + end |
| 19 | + end) |
| 20 | +end) |
| 21 | + |
| 22 | +-- MP_EXT of type MP_ARROW, column 'a', value 0. |
| 23 | +local mp_arrow_hex = [[ |
| 24 | + c8011008ffffffff70000000040000009effffff0400010004000000b6ffffff0c0000000400 |
| 25 | + 0000000000000100000004000000daffffff140000000202000004000000f0ffffff40000000 |
| 26 | + 01000000610000000600080004000c0010000400080009000c000c000c000000040000000800 |
| 27 | + 0a000c00040006000800ffffffff88000000040000008affffff040003001000000008000000 |
| 28 | + 0000000000000000acffffff0100000000000000340000000800000000000000020000000000 |
| 29 | + 0000000000000000000000000000000000000000000008000000000000000000000001000000 |
| 30 | + 010000000000000000000000000000000a00140004000c0010000c0014000400060008000c00 |
| 31 | + 00000000000000000000 |
| 32 | +]] |
| 33 | + |
| 34 | +g.test_decode_mp_arrow = function(cg) |
| 35 | + cg.server:exec(function(mp_arrow_hex) |
| 36 | + local msgpack = require('msgpack') |
| 37 | + -- Test invalid extension. |
| 38 | + t.assert_error_msg_equals( |
| 39 | + "Invalid MsgPack - invalid extension", |
| 40 | + msgpack.decode, string.fromhex('c70408deadbeef')) |
| 41 | + -- Test a valid extension. |
| 42 | + local mp_arrow = string.fromhex(mp_arrow_hex:gsub("%s+", "")) |
| 43 | + local decoded, next_pos = msgpack.decode(mp_arrow) |
| 44 | + t.assert_equals(decoded, string.sub(mp_arrow, 5)) |
| 45 | + t.assert_equals(next_pos, 277) |
| 46 | + end, {mp_arrow_hex}) |
| 47 | +end |
| 48 | + |
| 49 | +g.test_space_insert_arrow = function(cg) |
| 50 | + cg.server:exec(function(mp_arrow_hex) |
| 51 | + local msgpack = require('msgpack') |
| 52 | + local s = box.schema.create_space('test') |
| 53 | + |
| 54 | + t.assert_error_msg_equals( |
| 55 | + "Usage: space:insert_arrow(arrow)", |
| 56 | + box.internal.insert_arrow) |
| 57 | + t.assert_error_msg_equals( |
| 58 | + "Usage: space:insert_arrow(arrow)", |
| 59 | + box.internal.insert_arrow, 'not a number', 'string') |
| 60 | + t.assert_error_msg_equals( |
| 61 | + "Usage: space:insert_arrow(arrow)", |
| 62 | + box.internal.insert_arrow, 11, {22}) |
| 63 | + t.assert_error_msg_equals( |
| 64 | + "Use space:insert_arrow(...) instead of " .. |
| 65 | + "space.insert_arrow(...)", |
| 66 | + s.insert_arrow) |
| 67 | + t.assert_error_msg_equals( |
| 68 | + "Space 'xyz' does not exist", |
| 69 | + s.insert_arrow, {id = 1000, name = 'xyz'}) |
| 70 | + t.assert_error_msg_equals( |
| 71 | + "Usage: space:insert_arrow(arrow)", |
| 72 | + s.insert_arrow, s, 22) |
| 73 | + t.assert_error_msg_equals( |
| 74 | + "Arrow decode error: Expected >= 544501618 bytes of remaining " .. |
| 75 | + "data but found 29 bytes in buffer", |
| 76 | + s.insert_arrow, s, 'not a valid arrow data string') |
| 77 | + |
| 78 | + local mp_arrow = string.fromhex(mp_arrow_hex:gsub("%s+", "")) |
| 79 | + local arrow = msgpack.decode(mp_arrow) |
| 80 | + t.assert_error_msg_equals( |
| 81 | + "memtx does not support arrow format", |
| 82 | + s.insert_arrow, s, arrow) |
| 83 | + end, {mp_arrow_hex}) |
| 84 | +end |
0 commit comments