content_by_lua_file directive 테스트 추가

This commit is contained in:
freestrings 2019-08-25 15:43:04 +09:00
parent 422a23ee57
commit 8c24411c3f
5 changed files with 63 additions and 3 deletions

3
lua/.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/*
.vscode
/target/
Cargo.lock
Cargo.lock
docker_example/ab_results/**

View File

@ -1,12 +1,13 @@
lua_package_path '/etc/jsonpath/?.lua;;';
access_log /var/log/nginx_access.log;
error_log /var/log/nginx_error.log info;
server {
listen 80;
server_name localhost;
location / {
location /0 {
default_type text/html;
content_by_lua '
@ -19,6 +20,12 @@ server {
';
}
location /1 {
default_type text/html;
content_by_lua_file /etc/jsonpath/testa.lua;
}
location /example {
root /etc/jsonpath/example;
}

View File

@ -0,0 +1,3 @@
local jsonpath = require("jsonpath")
jsonpath.init("/etc/jsonpath/libjsonpath_lib.so")
ngx.log(ngx.INFO, "loaded libjsonpath_lib.so")

View File

@ -4,12 +4,47 @@
set -v
docker kill jsonpath
docker run -d --rm --name jsonpath \
-v "${PWD}/../../benchmark/example.json":/etc/jsonpath/example/example.json:ro \
-v "${PWD}/../jsonpath.lua":/etc/jsonpath/jsonpath.lua:ro \
-v "${PWD}/testa.lua":/etc/jsonpath/testa.lua:ro \
-v "${PWD}/init.lua":/etc/jsonpath/init.lua:ro \
-v "${PWD}/../target/release/deps/libjsonpath_lib.so":/etc/jsonpath/libjsonpath_lib.so:ro \
-v "${PWD}/default.conf":/etc/nginx/conf.d/default.conf \
-p 8080:80 \
openresty/openresty:bionic
docker exec -it jsonpath bash -c "curl localhost"
paths=(
"$.store.book[*].author"
"$..author"
"$.store.*"
"$.store..price"
"$..book[2]"
"$..book[-2]"
"$..book[0,1]"
"$..book[:2]"
"$..book[1:2]"
"$..book[-2:]"
"$..book[2:]"
"$..book[?(@.isbn)]"
"$.store.book[?(@.price == 10)]"
"$..*"
"$..book[ ?( (@.price < 13 || $.store.bicycle.price < @.price) && @.price <=10 ) ]"
"$.store.book[?( (@.price < 10 || @.price > 10) && @.price > 10 )]"
)
encoded_paths=()
for i in "${!paths[@]}"
do
encoded_paths+=("$(node --eval "console.log(encodeURIComponent('${paths[$i]}'))")")
curl http://localhost:8080/1?path="${encoded_paths[$i]}"
done
for i in "${!encoded_paths[@]}"
do
ab -n 1000 -c 10 http://localhost:8080/1?path="${encoded_paths[$i]}" > ab_results/"${paths[$i]}".txt
done

View File

@ -0,0 +1,14 @@
require("init")
local jsonpath = require("jsonpath")
local args = ngx.req.get_uri_args()
local path = args['path']
if(path == nil or path == '') then
return ngx.exit(400)
end
local template = jsonpath.compile(path)
local data = ngx.location.capture("/example.json")
local result = template(data.body)
ngx.say(result)