Skip to content

Commit 26d3947

Browse files
authored
Merge pull request #122 from progaudi/feature/sql
Feature/sql
2 parents 50619b9 + a7940f1 commit 26d3947

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1279
-217
lines changed

.travis.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ matrix:
33
- os: linux # Ubuntu 14.04
44
dist: trusty
55
sudo: required
6-
- os: osx # OSX 10.12
7-
osx_image: xcode8.3
6+
- os: osx
7+
osx_image: xcode9.2
8+
env: TARANTOOL_VERSION= TEST_FILTER='--filter "Tarantool!=1.8"'
9+
- os: osx
10+
osx_image: xcode9.2
11+
env: TARANTOOL_VERSION=--HEAD TEST_FILTER='--filter "Tarantool=1.8"'
812

913
before_install:
1014
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo ./scripts/ubuntu-prereqs.sh ; fi
@@ -14,9 +18,10 @@ install:
1418
- ./scripts/dotnet-install.sh
1519
- PATH=$PATH:$HOME/.dotnet && export PATH
1620
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then docker-compose -f docker-compose.yml up -d ; fi
17-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tarantool tarantool/tarantool.lua ; fi
21+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then (cd tarantool && tarantool tarantool.lua && cd ..) ; fi
1822
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then redis-server --daemonize yes ; fi
1923

2024
script:
2125
- ./scripts/build-netcore.sh
22-
- ./scripts/test-netcore.sh
26+
- if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then ./scripts/linux-test-netcore.sh ; fi
27+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./scripts/mac-test-netcore.sh ; fi

docker-compose.tests.yml

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
version: '2'
1+
version: '3.2'
22

33
services:
4-
5-
tarantool-client:
6-
build: .
7-
command: /app/scripts/test-netcore.sh
8-
environment:
9-
TARANTOOL_REPLICATION_SOURCE: "tarantool:3301"
10-
links:
11-
- tarantool
12-
- redis
4+
tarantool-client:
5+
build: .
6+
command: /app/scripts/test-netcore.sh
7+
environment:
8+
TARANTOOL_1_7_REPLICATION_SOURCE: "tarantool_1_7:3301"
9+
TARANTOOL_1_8_REPLICATION_SOURCE: "tarantool_1_8:3301"
10+
REDIS_HOST: redis
11+
links:
12+
- tarantool_1_7
13+
- tarantool_1_8
14+
- redis

docker-compose.yml

+37-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
version: '2'
1+
version: '3.2'
22

33
services:
4-
tarantool:
5-
image: tarantool/tarantool:1.7
6-
command: tarantool /usr/local/share/tarantool/tarantool.docker.lua
7-
volumes:
8-
- $PWD/tarantool:/usr/local/share/tarantool
9-
ports:
10-
- "3301:3301"
11-
environment:
12-
TARANTOOL_USER_NAME: admin
13-
TARANTOOL_USER_PASSWORD: adminPassword
14-
TARANTOOL_SLAB_ALLOC_ARENA: 0.1
4+
tarantool_1_7:
5+
image: progaudi/tarantool:1.7.5-184-g5be3a82be # same version as tarantool in homebrew on mac os
6+
command: tarantool /usr/local/share/tarantool/tarantool.docker.lua
7+
volumes:
8+
- $PWD/tarantool:/usr/local/share/tarantool
9+
ports:
10+
- "3301:3301"
11+
environment:
12+
TARANTOOL_USER_NAME: admin
13+
TARANTOOL_USER_PASSWORD: adminPassword
14+
TARANTOOL_SLAB_ALLOC_ARENA: 0.1
1515

16-
redis:
17-
image: redis:3.0-alpine
18-
command: redis-server
19-
ports:
20-
- 6379:6379
16+
tarantool_1_8:
17+
image: progaudi/tarantool:1.8.2-288-g99128d7d3
18+
command: tarantool /usr/local/share/tarantool/tarantool.docker.lua
19+
volumes:
20+
- $PWD/tarantool:/usr/local/share/tarantool
21+
ports:
22+
- "3302:3301"
23+
environment:
24+
TARANTOOL_USER_NAME: admin
25+
TARANTOOL_USER_PASSWORD: adminPassword
26+
TARANTOOL_SLAB_ALLOC_ARENA: 0.1
27+
28+
redis:
29+
image: redis:3.0-alpine
30+
command: redis-server
31+
ports:
32+
- 6379:6379
33+
34+
admin:
35+
image: quay.io/basis-company/tarantool-admin
36+
ports:
37+
- 8888:80
38+
depends_on:
39+
- tarantool_1_7
40+
- tarantool_1_8

scripts/build-netcore.sh

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
#!/usr/bin/env bash
22

3-
set -ev
3+
set -evx
44

5-
pushd ${BASH_SOURCE%/*}
5+
pushd ${BASH_SOURCE%/*}/..
66

7-
cd ..
8-
9-
dotnet restore
10-
dotnet build -c Release -f netstandard1.4 src/progaudi.tarantool/progaudi.tarantool.csproj
11-
dotnet build -c Release -f netstandard2.0 src/progaudi.tarantool/progaudi.tarantool.csproj
12-
dotnet build -c Release -f netcoreapp1.0 tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj
13-
dotnet build -c Release -f netcoreapp1.1 tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj
14-
dotnet build -c Release -f netcoreapp2.0 tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj
7+
dotnet build -c Release progaudi.tarantool.sln
158

169
popd

scripts/if_there_are_changes_in.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage:
4+
# if_there_are_changes_in folder1 ... folderN --then script arg1 arg2 arg3 --else script2 arg1 arg2
5+
# Purpose:
6+
# Run script only if provided folders has changes against master.
7+
8+
set -e
9+
10+
# populate logic_folders
11+
logic_folders=()
12+
true_script=()
13+
false_script=("true")
14+
step="populate_folders"
15+
16+
for arg in "$@"
17+
do
18+
if [ $arg == "--then" ]; then
19+
step="then"
20+
continue;
21+
fi
22+
23+
if [ $arg == "--else" ]; then
24+
step="else"
25+
false_script=()
26+
continue;
27+
fi
28+
29+
if [ $step == "populate_folders" ]; then
30+
logic_folders+=($arg)
31+
elif [ $step == "then" ]; then
32+
true_script+=($arg)
33+
else
34+
false_script+=($arg)
35+
fi
36+
done
37+
38+
pushd ${BASH_SOURCE%/*}/..
39+
40+
predicate_is_true=0
41+
for folder in ${logic_folders[@]}; do
42+
echo "Check for changes in $folder"
43+
changes=$(git diff --relative=$folder HEAD~1 --quiet --; echo $?)
44+
45+
if [ $changes = 1 ]; then
46+
predicate_is_true=1
47+
echo "There are changes in $folder"
48+
else
49+
echo "No changes in $folder"
50+
fi
51+
done
52+
53+
popd
54+
55+
if [ $predicate_is_true = 1 ]; then
56+
${true_script[@]}
57+
else
58+
${false_script[@]}
59+
fi

scripts/test-netcore.sh renamed to scripts/linux-test-netcore.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
set -ev
44

5-
pushd ${BASH_SOURCE%/*}
6-
7-
cd ..
5+
pushd ${BASH_SOURCE%/*}/..
86

97
dotnet test -c Release --no-build tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj -- -parallel assemblies
108

scripts/mac-prereqs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ set -ev
44

55
brew update
66
brew install openssl jq
7-
brew install tarantool
7+
brew install tarantool $TARANTOOL_VERSION
88
brew install redis
99

1010
mkdir -p /usr/local/lib
1111

1212
ln -sf /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
13-
ln -sf /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
13+
ln -sf /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

scripts/mac-test-netcore.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -v -x
4+
5+
pushd ${BASH_SOURCE%/*}/..
6+
7+
TARANTOOL_1_7_REPLICATION_SOURCE=localhost:3301 TARANTOOL_1_8_REPLICATION_SOURCE=localhost:3301 dotnet test -c Release --no-build $TEST_FILTER tests/progaudi.tarantool.tests/progaudi.tarantool.tests.csproj -- -parallel assemblies

scripts/publish-nuget.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
version=$(git describe --tags | sed s/-/./)
6+
dotnet_path=/$(echo $1 | sed 's/\\/\//g' | sed 's/://')
7+
./scripts/if_there_are_changes_in.sh 'src/progaudi.tarantool' --then $dotnet_path/dotnet pack --include-symbols -c Release -o ../../Publish src/progaudi.tarantool/progaudi.tarantool.csproj /property:Version=$version
8+
./scripts/if_there_are_changes_in.sh 'src/progaudi.tarantool' --then $dotnet_path/dotnet nuget push Publish/progaudi.tarantool.$version.nupkg -k $2 -s https://api.nuget.org/v3/index.json

src/progaudi.tarantool/Box.cs

+54-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Threading.Tasks;
2-
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
33
using ProGaudi.Tarantool.Client.Model;
44
using ProGaudi.Tarantool.Client.Model.Requests;
55
using ProGaudi.Tarantool.Client.Model.Responses;
6+
using ProGaudi.Tarantool.Client.Utils;
67

78
namespace ProGaudi.Tarantool.Client
89
{
@@ -12,6 +13,10 @@ public class Box : IBox
1213

1314
private readonly ILogicalConnection _logicalConnection;
1415

16+
private BoxInfo _info;
17+
18+
private bool _sqlReady;
19+
1520
public Box(ClientOptions options)
1621
{
1722
_clientOptions = options;
@@ -22,10 +27,42 @@ public Box(ClientOptions options)
2227
Schema = new Schema(_logicalConnection);
2328
}
2429

30+
public Metrics Metrics { get; }
31+
32+
public bool IsConnected => _logicalConnection.IsConnected();
33+
34+
public ISchema Schema { get; }
35+
36+
public BoxInfo Info
37+
{
38+
get => _info;
39+
private set
40+
{
41+
_info = value;
42+
_sqlReady = value.IsSqlAvailable();
43+
}
44+
}
45+
2546
public async Task Connect()
2647
{
2748
await _logicalConnection.Connect().ConfigureAwait(false);
28-
await ReloadSchema().ConfigureAwait(false);
49+
await Task.WhenAll(GetAdditionalTasks()).ConfigureAwait(false);
50+
51+
IEnumerable<Task> GetAdditionalTasks()
52+
{
53+
if (_clientOptions.ConnectionOptions.ReadSchemaOnConnect)
54+
yield return ReloadSchema();
55+
56+
if (_clientOptions.ConnectionOptions.ReadBoxInfoOnConnect)
57+
yield return ReloadBoxInfo();
58+
}
59+
}
60+
61+
public async Task ReloadBoxInfo()
62+
{
63+
var report = await Eval<BoxInfo>("return box.info").ConfigureAwait(false);
64+
if (report.Data.Length != 1) throw ExceptionHelper.CantParseBoxInfoResponse();
65+
Info = report.Data[0];
2966
}
3067

3168
public static async Task<Box> Connect(string replicationSource)
@@ -35,13 +72,6 @@ public static async Task<Box> Connect(string replicationSource)
3572
return box;
3673
}
3774

38-
public Metrics Metrics
39-
{
40-
get;
41-
}
42-
43-
public bool IsConnected => _logicalConnection.IsConnected();
44-
4575
public static Task<Box> Connect(string host, int port)
4676
{
4777
return Connect($"{host}:{port}");
@@ -61,8 +91,6 @@ public void Dispose()
6191

6292
public ISchema GetSchema() => Schema;
6393

64-
public ISchema Schema { get; }
65-
6694
public Task ReloadSchema()
6795
{
6896
_clientOptions.LogWriter?.WriteLine("Schema reloading...");
@@ -121,5 +149,19 @@ public Task<DataResponse<TResponse[]>> Eval<TResponse>(string expression)
121149
{
122150
return Eval<TarantoolTuple, TResponse>(expression, TarantoolTuple.Empty);
123151
}
152+
153+
public Task<DataResponse> ExecuteSql(string query, params SqlParameter[] parameters)
154+
{
155+
if (!_sqlReady) throw ExceptionHelper.SqlIsNotAvailable(Info.Version);
156+
157+
return _logicalConnection.SendRequest(new ExecuteSqlRequest(query, parameters));
158+
}
159+
160+
public Task<DataResponse<TResponse[]>> ExecuteSql<TResponse>(string query, params SqlParameter[] parameters)
161+
{
162+
if (!_sqlReady) throw ExceptionHelper.SqlIsNotAvailable(Info.Version);
163+
164+
return _logicalConnection.SendRequest<ExecuteSqlRequest, TResponse>(new ExecuteSqlRequest(query, parameters));
165+
}
124166
}
125167
}

0 commit comments

Comments
 (0)