Skip to content

Commit

Permalink
#98 -- fixed; #66 -- added: insert, delete, select, replace
Browse files Browse the repository at this point in the history
  • Loading branch information
dedok committed Dec 10, 2017
1 parent a050f43 commit b108c1e
Show file tree
Hide file tree
Showing 10 changed files with 772 additions and 122 deletions.
738 changes: 626 additions & 112 deletions src/ngx_http_tnt_module.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ngx_http_tnt_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
#ifndef NGX_HTTP_TNT_VERSION_H
#define NGX_HTTP_TNT_VERSION_H 1

#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5.1-stable"
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.6-beta"

#endif
1 change: 1 addition & 0 deletions src/tp_ext.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
Expand Down
8 changes: 5 additions & 3 deletions t/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ def assert_if_not_error(s, code = None):
if code:
assert(s['error']['code'] == code), 'expected code'

def get_success(url, data, headers):
def get_success(url, data, headers, expand_result = True):
(code, msg) = get(url, data, headers)
assert(code == 200), 'expected 200'
result = get_result(msg)
return result
if expand_result:
result = get_result(msg)
return result
return msg

def get_success_pure(url, data, headers):
(code, msg) = get(url, data, headers)
Expand Down
23 changes: 23 additions & 0 deletions t/ngx_confs/tnt_server_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,28 @@ http {
tnt_pass tnt;
}

##
## DML tests
##
location /insert {
tnt_insert 512 "index=%n&string=%s&float=%f&double=%d&bool=%b&int=%n";
tnt_pass tnt;
}

location /delete {
tnt_delete 512 0 "index=%n";
tnt_pass tnt;
}

location /select {
tnt_select 512 0 0 100 ge "index=%n";
tnt_pass tnt;
}

location /replace {
tnt_replace 512 "index=%n&string=%s&float=%f&double=%d&bool=%b&int=%n";
tnt_pass tnt;
}

}
}
1 change: 1 addition & 0 deletions t/parallel_clients.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ for i in {1..10}; do
./t/v24_features.py &
# ./t/lua.py &
./t/v25_features.py &
./t/v26_features.py &
done

for i in `jobs -p`; do
Expand Down
12 changes: 9 additions & 3 deletions t/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ for i in {1..10}; do
# echo "[-] $WORK_DIR/lua.py failed" && exit 1
# )
$WORK_DIR/v25_features.py 1> /dev/null || (
echo "[-] $WORK_DIR/v24_features.py failed" && exit 1
echo "[-] $WORK_DIR/v25_features.py failed" && exit 1
)
$WORK_DIR/v26_features.py 1> /dev/null || (
echo "[-] $WORK_DIR/v26_features.py failed" && exit 1
)
done

Expand All @@ -52,8 +55,11 @@ for i in {1..3}; do
# echo "[-] $WORK_DIR/lua.py failed" && exit 1
# )` &
$WORK_DIR/v25_features.py 1> /dev/null || (
echo "[-] $WORK_DIR/v24_features.py failed" && exit 1
)
echo "[-] $WORK_DIR/v25_features.py failed" && exit 1
) &
$WORK_DIR/v26_features.py 1> /dev/null || (
echo "[-] $WORK_DIR/v26_features.py failed" && exit 1
) &
clients_pids="$clients_pids $!"
done
for job in $clients_pids; do
Expand Down
22 changes: 22 additions & 0 deletions t/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
json = require('json')
yaml = require('yaml')
os = require('os')
fiber = require('fiber')

function echo_1(a)
return {a}
Expand Down Expand Up @@ -176,6 +177,17 @@ function method_3(req)
return req
end

-- Issue -- https://github.com/tarantool/nginx_upstream_module/issues/98
function error_if_escaped(req)
print (yaml.encode(req))
local get_arg = req.args.getArg
if get_arg == 'a+b' then
error (string.format('regression, it should have +, getArg = %s',
req.args.getArg))
end
return true
end

-- CFG
box.cfg {
log_level = 5,
Expand All @@ -186,3 +198,13 @@ box.cfg {
box.once('gr', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

local t = box.schema.space.create('t', {if_not_exists=true})
t:create_index('pk', {if_not_exists=true})
--print (yaml.encode(box.space.t.index))
--fiber.create(function()
-- while true do
-- print (yaml.encode(box.space.t:select{}))
-- fiber.sleep(1.5)
-- end
--end)
76 changes: 76 additions & 0 deletions t/v26_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/python
# -_- encoding: utf8 -_-

import sys
import time
sys.path.append('./t')
from http_utils import *



print ('[+] basic insert')

result = get_success(BASE_URL + '/delete', {'index': 1}, None, False)
assert 'result' in result and 'id' in result, 'expected: result and id'
result = get_success(BASE_URL + '/delete', {'index': 2}, None, False)
assert 'result' in result and 'id' in result, 'expected: result and id'

# Format - "index=%u&string=%s&float=%f&double=%d&bool=%b&int=%i";

insert_1 = {
'index': 1,
'string': 'some big string',
'float': 2.1,
'double': 3.1,
'bool': True,
'int': -1000
}
result = get_success(BASE_URL + '/insert', insert_1, None)
assert [ v for v in insert_1.values() ] == result, "Expected != result"

insert_2 = {
'index': 2,
'string': 'the new big and random string',
'float': 20.1,
'double': 30.1,
'bool': False,
'int': -2
}
result = get_success(BASE_URL + '/insert', insert_2, None)
assert [ v for v in insert_2.values() ] == result, "Expected != result"
print ('[+] OK')


print ('[+] basic select')
result = get_success(BASE_URL + '/select', {
'index': 0
}, None, False)
assert [ v for v in insert_1.values() ] == result['result'][0], \
"Expected != result"
assert [ v for v in insert_2.values() ] == result['result'][1], \
"Expected != result"
print ('[+] OK')


print ('[+] basic replace')
insert_1['int'] = 1000000
result = get_success(BASE_URL + '/replace', insert_1, None)
assert [ v for v in insert_1.values() ] == result, \
"Expected != result"
print ('[+] OK')


print ('[+] basic delete')
result = get_success(BASE_URL + '/delete', {'index': 1}, None)
assert [ v for v in insert_1.values() ] == result, \
"Expected != result"
result = get_success(BASE_URL + '/delete', {'index': 2}, None)
assert [ v for v in insert_2.values() ] == result, \
"Expected != result"
print ('[+] OK')


print ('[+] https://github.com/tarantool/nginx_upstream_module/issues/98')
result = get_success(BASE_URL + '/error_if_escaped', {'getArg': 'a b'}, None)
assert result == True, 'Expected True'
print ('[+] OK')
11 changes: 8 additions & 3 deletions third_party/tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ tp_replace(struct tp *p, uint32_t space);
* tp_sz(&req, "key");
*/
static inline char *
tp_delete(struct tp *p, uint32_t space);
tp_delete(struct tp *p, uint32_t space, uint32_t index);

/**
* Create an update request.
Expand Down Expand Up @@ -1073,18 +1073,23 @@ tp_replace(struct tp *p, uint32_t space)
* tp_sz(&req, "key");
*/
static inline char *
tp_delete(struct tp *p, uint32_t space)
tp_delete(struct tp *p, uint32_t space, uint32_t index)
{
int hsz = tpi_sizeof_header(TP_DELETE);
int sz = mp_sizeof_map(2) +
int sz = mp_sizeof_map(3) +
mp_sizeof_uint(TP_SPACE) +
mp_sizeof_uint(space) +
mp_sizeof_uint(TP_INDEX) +
mp_sizeof_uint(index) +
mp_sizeof_uint(TP_KEY);
if (tpunlikely(tp_ensure(p, hsz + sz) == -1))
return NULL;
char *h = tpi_encode_header(p, TP_DELETE);
h = mp_encode_map(h, 3);
h = mp_encode_uint(h, TP_SPACE);
h = mp_encode_uint(h, space);
h = mp_encode_uint(h, TP_INDEX);
h = mp_encode_uint(h, index);
h = mp_encode_uint(h, TP_KEY);
return tp_add(p, hsz + sz);
}
Expand Down

0 comments on commit b108c1e

Please sign in to comment.