Tarantool code examples
The doc/code_snippets folder of a Tarantool documentation repository contains runnable code examples that show how to work with Tarantool:
- The snippets folder contains sample applications that demonstrate how to configure a Tarantool cluster.
- The test folder contains testable Lua examples that show how to work with various Tarantool modules.
Code from these examples is referenced in corresponding documentation sections.
Install the tt CLI utility.
To be able to run tests for samples from test, go to the
doc/code_snippetsfolder and install the following libraries:-
tt rocks install luatest
-
tt rocks install luarapidxml
-
To run applications placed in snippets, follow these steps:
Go to the directory containing samples for a specific feature, for example, snippets/replication.
To run applications placed in instances.enabled, execute the
tt startcommand, for example:$ tt start auto_leader
To test all the examples, go to the doc/code_snippets folder and execute the luatest command:
.rocks/bin/luatest
To test the examples from the specified directory, pass its relative path to the luatest command:
.rocks/bin/luatest test/transactions
To test a specific example with the stdout output enabled, use the luatest command with the -c option, for example:
.rocks/bin/luatest -c test/http_client/get_test.lua
Note that the HTTP client samples (placed in test/http_client) use the httpbin service.
You can run httpbin locally using Docker to stabilize test results:
docker run -p 80:80 kennethreitz/httpbin
In this case, you need to replace https://httpbin.org links with http://127.0.0.1.