Skip to content

Commit

Permalink
Refactoring/#18-use-lua-cjson (#27)
Browse files Browse the repository at this point in the history
* Migrate to lua-cjson
  • Loading branch information
kaklakariada authored Mar 23, 2022
1 parent 16698e3 commit 699bf66
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ jobs:
EXASOL_USER=sys EXASOL_PASSWORD=exasol \
busted --run=ci_repeated
- name: Archive repeated tests results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: repeated-test-reports
path: target/luaunit-reports/*
## Deactivated until requirements and coverage are added

Expand Down
1 change: 1 addition & 0 deletions doc/changes/changes_0.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Code name: Initial Release
## Refactoring

* #25: Migrated tests to busted
* #18: Replaced lunajson with cjson

## Documentation

Expand Down
23 changes: 22 additions & 1 deletion doc/developer_guide/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Install the prerequisites like this:
sudo yum install lua lua-devel luarocks openssl-devel lua-luaossl plantuml
```
### Install Runtime and Test Dependencies
### Install Runtime Dependencies
See the [list of dependencies](../../dependencies.md) for details. Install dependencies by executing:
Expand All @@ -37,6 +37,27 @@ openssl=/usr/local/Cellar/[email protected]/1.1.1m/
luarocks install --local --deps-only *.rockspec OPENSSL_DIR=$openssl CRYPTO_DIR=$openssl
```
### Install Test and Build Dependencies
```sh
luarocks install --local busted
```
#### Troubleshooting `lua-cjson` installation
`lua-cjson` is pinned to version `2.1.0` because later versions fail installation with error `undefined symbol: lua_objlen` or `implicit declaration of function 'lua_objlen' is invalid in C99`:
```
lua_cjson.c:743:19: error: implicit declaration of function 'lua_objlen' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
len = lua_objlen(l, -1);
```
To use the latest version you can optionally install it with additional build flags:
```sh
luarocks install lua-cjson --local "CFLAGS=-O3 -Wall -pedantic -DNDEBUG -DLUA_COMPAT_5_3"
```
## Running Tests
You need an Exasol database for running the tests. You can start a Docker instance either manually as described in [docker-db](https://github.com/EXASOL/docker-db) or using the [integration-test-docker-environment](https://github.com/exasol/integration-test-docker-environment).
Expand Down
2 changes: 1 addition & 1 deletion exasol-driver-lua-0.1.0-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = {
"luasocket >= 3.0rc1-2",
"luasec >= 1.0.2-1",
"luaossl >= 20200709-0",
"lunajson >= 1.2.3-1",
"lua-cjson == 2.1.0", -- pinned to prevent "undefined symbol: lua_objlen" in 2.1.0.6
"base64 >= 1.5-3",
"exaerror >= 1.2.2-1",
"remotelog >= 1.1.1-1"
Expand Down
6 changes: 3 additions & 3 deletions src/exasol_websocket.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local M = {}

local lunajson = require("lunajson")
local cjson = require("cjson")
local exaerror = require("exaerror")
-- [impl->dsn~logging-with-remotelog~1]
local log = require("remotelog")
Expand Down Expand Up @@ -54,7 +54,7 @@ local function get_response_error(response)
end

function M:_send_json(payload, ignore_response)
local raw_payload = lunajson.encode(payload)
local raw_payload = cjson.encode(payload)
log.trace("Sending payload '%s'", raw_payload)
local raw_response, err = self.websocket:send_raw(raw_payload, ignore_response)
if ignore_response then return nil, nil end
Expand All @@ -67,7 +67,7 @@ function M:_send_json(payload, ignore_response)
end

log.trace("Received response of %d bytes", #raw_response)
local response = lunajson.decode(raw_response)
local response = cjson.decode(raw_response)
err = get_response_error(response)
if err then
return nil, err
Expand Down

0 comments on commit 699bf66

Please sign in to comment.