Skip to content

Commit b108c1e

Browse files
committed
#98 -- fixed; #66 -- added: insert, delete, select, replace
1 parent a050f43 commit b108c1e

File tree

10 files changed

+772
-122
lines changed

10 files changed

+772
-122
lines changed

src/ngx_http_tnt_module.c

Lines changed: 626 additions & 112 deletions
Large diffs are not rendered by default.

src/ngx_http_tnt_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
#ifndef NGX_HTTP_TNT_VERSION_H
3434
#define NGX_HTTP_TNT_VERSION_H 1
3535

36-
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5.1-stable"
36+
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.6-beta"
3737

3838
#endif

src/tp_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Redistribution and use in source and binary forms, with or
34
* without modification, are permitted provided that the following

t/http_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ def assert_if_not_error(s, code = None):
194194
if code:
195195
assert(s['error']['code'] == code), 'expected code'
196196

197-
def get_success(url, data, headers):
197+
def get_success(url, data, headers, expand_result = True):
198198
(code, msg) = get(url, data, headers)
199199
assert(code == 200), 'expected 200'
200-
result = get_result(msg)
201-
return result
200+
if expand_result:
201+
result = get_result(msg)
202+
return result
203+
return msg
202204

203205
def get_success_pure(url, data, headers):
204206
(code, msg) = get(url, data, headers)

t/ngx_confs/tnt_server_test.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,28 @@ http {
306306
tnt_pass tnt;
307307
}
308308

309+
##
310+
## DML tests
311+
##
312+
location /insert {
313+
tnt_insert 512 "index=%n&string=%s&float=%f&double=%d&bool=%b&int=%n";
314+
tnt_pass tnt;
315+
}
316+
317+
location /delete {
318+
tnt_delete 512 0 "index=%n";
319+
tnt_pass tnt;
320+
}
321+
322+
location /select {
323+
tnt_select 512 0 0 100 ge "index=%n";
324+
tnt_pass tnt;
325+
}
326+
327+
location /replace {
328+
tnt_replace 512 "index=%n&string=%s&float=%f&double=%d&bool=%b&int=%n";
329+
tnt_pass tnt;
330+
}
331+
309332
}
310333
}

t/parallel_clients.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ for i in {1..10}; do
77
./t/v24_features.py &
88
# ./t/lua.py &
99
./t/v25_features.py &
10+
./t/v26_features.py &
1011
done
1112

1213
for i in `jobs -p`; do

t/run_all.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ for i in {1..10}; do
2626
# echo "[-] $WORK_DIR/lua.py failed" && exit 1
2727
# )
2828
$WORK_DIR/v25_features.py 1> /dev/null || (
29-
echo "[-] $WORK_DIR/v24_features.py failed" && exit 1
29+
echo "[-] $WORK_DIR/v25_features.py failed" && exit 1
30+
)
31+
$WORK_DIR/v26_features.py 1> /dev/null || (
32+
echo "[-] $WORK_DIR/v26_features.py failed" && exit 1
3033
)
3134
done
3235

@@ -52,8 +55,11 @@ for i in {1..3}; do
5255
# echo "[-] $WORK_DIR/lua.py failed" && exit 1
5356
# )` &
5457
$WORK_DIR/v25_features.py 1> /dev/null || (
55-
echo "[-] $WORK_DIR/v24_features.py failed" && exit 1
56-
)
58+
echo "[-] $WORK_DIR/v25_features.py failed" && exit 1
59+
) &
60+
$WORK_DIR/v26_features.py 1> /dev/null || (
61+
echo "[-] $WORK_DIR/v26_features.py failed" && exit 1
62+
) &
5763
clients_pids="$clients_pids $!"
5864
done
5965
for job in $clients_pids; do

t/test.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
json = require('json')
44
yaml = require('yaml')
55
os = require('os')
6+
fiber = require('fiber')
67

78
function echo_1(a)
89
return {a}
@@ -176,6 +177,17 @@ function method_3(req)
176177
return req
177178
end
178179

180+
-- Issue -- https://github.com/tarantool/nginx_upstream_module/issues/98
181+
function error_if_escaped(req)
182+
print (yaml.encode(req))
183+
local get_arg = req.args.getArg
184+
if get_arg == 'a+b' then
185+
error (string.format('regression, it should have +, getArg = %s',
186+
req.args.getArg))
187+
end
188+
return true
189+
end
190+
179191
-- CFG
180192
box.cfg {
181193
log_level = 5,
@@ -186,3 +198,13 @@ box.cfg {
186198
box.once('gr', function()
187199
box.schema.user.grant('guest', 'read,write,execute', 'universe')
188200
end)
201+
202+
local t = box.schema.space.create('t', {if_not_exists=true})
203+
t:create_index('pk', {if_not_exists=true})
204+
--print (yaml.encode(box.space.t.index))
205+
--fiber.create(function()
206+
-- while true do
207+
-- print (yaml.encode(box.space.t:select{}))
208+
-- fiber.sleep(1.5)
209+
-- end
210+
--end)

t/v26_features.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python
2+
# -_- encoding: utf8 -_-
3+
4+
import sys
5+
import time
6+
sys.path.append('./t')
7+
from http_utils import *
8+
9+
10+
11+
print ('[+] basic insert')
12+
13+
result = get_success(BASE_URL + '/delete', {'index': 1}, None, False)
14+
assert 'result' in result and 'id' in result, 'expected: result and id'
15+
result = get_success(BASE_URL + '/delete', {'index': 2}, None, False)
16+
assert 'result' in result and 'id' in result, 'expected: result and id'
17+
18+
# Format - "index=%u&string=%s&float=%f&double=%d&bool=%b&int=%i";
19+
20+
insert_1 = {
21+
'index': 1,
22+
'string': 'some big string',
23+
'float': 2.1,
24+
'double': 3.1,
25+
'bool': True,
26+
'int': -1000
27+
}
28+
result = get_success(BASE_URL + '/insert', insert_1, None)
29+
assert [ v for v in insert_1.values() ] == result, "Expected != result"
30+
31+
insert_2 = {
32+
'index': 2,
33+
'string': 'the new big and random string',
34+
'float': 20.1,
35+
'double': 30.1,
36+
'bool': False,
37+
'int': -2
38+
}
39+
result = get_success(BASE_URL + '/insert', insert_2, None)
40+
assert [ v for v in insert_2.values() ] == result, "Expected != result"
41+
print ('[+] OK')
42+
43+
44+
print ('[+] basic select')
45+
result = get_success(BASE_URL + '/select', {
46+
'index': 0
47+
}, None, False)
48+
assert [ v for v in insert_1.values() ] == result['result'][0], \
49+
"Expected != result"
50+
assert [ v for v in insert_2.values() ] == result['result'][1], \
51+
"Expected != result"
52+
print ('[+] OK')
53+
54+
55+
print ('[+] basic replace')
56+
insert_1['int'] = 1000000
57+
result = get_success(BASE_URL + '/replace', insert_1, None)
58+
assert [ v for v in insert_1.values() ] == result, \
59+
"Expected != result"
60+
print ('[+] OK')
61+
62+
63+
print ('[+] basic delete')
64+
result = get_success(BASE_URL + '/delete', {'index': 1}, None)
65+
assert [ v for v in insert_1.values() ] == result, \
66+
"Expected != result"
67+
result = get_success(BASE_URL + '/delete', {'index': 2}, None)
68+
assert [ v for v in insert_2.values() ] == result, \
69+
"Expected != result"
70+
print ('[+] OK')
71+
72+
73+
print ('[+] https://github.com/tarantool/nginx_upstream_module/issues/98')
74+
result = get_success(BASE_URL + '/error_if_escaped', {'getArg': 'a b'}, None)
75+
assert result == True, 'Expected True'
76+
print ('[+] OK')

third_party/tp.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ tp_replace(struct tp *p, uint32_t space);
365365
* tp_sz(&req, "key");
366366
*/
367367
static inline char *
368-
tp_delete(struct tp *p, uint32_t space);
368+
tp_delete(struct tp *p, uint32_t space, uint32_t index);
369369

370370
/**
371371
* Create an update request.
@@ -1073,18 +1073,23 @@ tp_replace(struct tp *p, uint32_t space)
10731073
* tp_sz(&req, "key");
10741074
*/
10751075
static inline char *
1076-
tp_delete(struct tp *p, uint32_t space)
1076+
tp_delete(struct tp *p, uint32_t space, uint32_t index)
10771077
{
10781078
int hsz = tpi_sizeof_header(TP_DELETE);
1079-
int sz = mp_sizeof_map(2) +
1079+
int sz = mp_sizeof_map(3) +
10801080
mp_sizeof_uint(TP_SPACE) +
10811081
mp_sizeof_uint(space) +
1082+
mp_sizeof_uint(TP_INDEX) +
1083+
mp_sizeof_uint(index) +
10821084
mp_sizeof_uint(TP_KEY);
10831085
if (tpunlikely(tp_ensure(p, hsz + sz) == -1))
10841086
return NULL;
10851087
char *h = tpi_encode_header(p, TP_DELETE);
1088+
h = mp_encode_map(h, 3);
10861089
h = mp_encode_uint(h, TP_SPACE);
10871090
h = mp_encode_uint(h, space);
1091+
h = mp_encode_uint(h, TP_INDEX);
1092+
h = mp_encode_uint(h, index);
10881093
h = mp_encode_uint(h, TP_KEY);
10891094
return tp_add(p, hsz + sz);
10901095
}

0 commit comments

Comments
 (0)