Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ services:
- docker

before_script:
- .travis/$TRAVIS_OS_NAME/init.sh
- dotnet restore
- docker -v
- docker-compose down
- docker-compose up -d
- pushd samples/docker-compose
- docker-compose down
- docker-compose up -d --build
- popd

script:
- dotnet build -f netcoreapp1.0 src/tarantool.client
- dotnet test tests/tarantool.client.tests
- curl --fail http://localhost:5000
- .travis/$TRAVIS_OS_NAME/test.sh
11 changes: 11 additions & 0 deletions .travis/linux/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

echo 'Linux init script'

docker -v
docker-compose down
docker-compose up -d
pushd samples/docker-compose
docker-compose down
docker-compose up -d --build
popd
6 changes: 6 additions & 0 deletions .travis/linux/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

echo 'Linux test script'

dotnet test tests/tarantool.client.tests
curl -o /dev/null --fail http://localhost:5000
5 changes: 5 additions & 0 deletions .travis/osx/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo 'Mac init script'
brew tap caskroom/cask
brew cask install docker
3 changes: 3 additions & 0 deletions .travis/osx/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo 'Mac test script'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public interface ITuple{}
public interface ITarantoolTuple{}
<#
var maxParametersCount = 8;
var typeParameters = new Func<int, string>(count => string.Join(", ", Enumerable.Range(1, count).Select(num => $"T{num}")));
Expand Down Expand Up @@ -38,12 +38,29 @@ for(int i=0;i < maxParametersCount; i++){
return hashCode;
}
}

public override string ToString()
{
return $"<# for(int j=0; j< i+1; j++)
{
if (j != 0)
{
#>, <#
}
#>{Item<#=j+1#>}<#
} #>";
}
}
<#
}
#>

public class TarantoolTuple{
public class TarantoolTuple : ITarantoolTuple {
private TarantoolTuple()
{
}

public static TarantoolTuple Empty { get; } = new TarantoolTuple();
<#
for(int i=0;i < maxParametersCount; i++){
#>
Expand Down
41 changes: 37 additions & 4 deletions src/tarantool.client/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,54 @@ public Schema GetSchema()
return new Schema(_logicalConnection);
}

public async Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple request)
public async Task Call_1_6(string functionName)
{
await Call_1_6<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
}

public Task<DataResponse<TResponse[]>> Call_1_6<TResponse>(string functionName)
where TResponse : ITarantoolTuple
{
return Call_1_6<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
}

public async Task<DataResponse<TResponse[]>> Call_1_6<TTuple, TResponse>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
where TResponse : ITarantoolTuple
{
var callRequest = new CallRequest<TTuple>(functionName, request);
var callRequest = new CallRequest<TTuple>(functionName, parameters, false);
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
}

public async Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple request)
public async Task Call(string functionName)
{
await Call<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
}

public Task<DataResponse<TResponse[]>> Call<TResponse>(string functionName)
{
return Call<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
}

public async Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
{
var callRequest = new CallRequest<TTuple>(functionName, parameters);
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
}

public async Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple parameters)
where TTuple : ITarantoolTuple
{
var evalRequest = new EvalRequest<TTuple>(expression, request);
var evalRequest = new EvalRequest<TTuple>(expression, parameters);
return await _logicalConnection.SendRequest<EvalRequest<TTuple>, TResponse>(evalRequest);
}

public Task<DataResponse<TResponse[]>> Eval<TResponse>(string expression)
{
return Eval<TarantoolTuple, TResponse>(expression, TarantoolTuple.Empty);
}

private async Task LoginIfNotGuest(GreetingsResponse greetings)
{
var singleNode = _clientOptions.ConnectionOptions.Nodes.Single();
Expand Down
4 changes: 1 addition & 3 deletions src/tarantool.client/Converters/ResponsePacketConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public void Write(DataResponse<T> value, IMsgPackWriter writer)

public DataResponse<T> Read(IMsgPackReader reader)
{
var data = default(T);

var length = reader.ReadMapLength();
if (length != 1u)
{
Expand All @@ -41,7 +39,7 @@ public DataResponse<T> Read(IMsgPackReader reader)
throw ExceptionHelper.UnexpectedKey(dataKey, Key.Data);
}

data = _dataConverter.Read(reader);
var data = _dataConverter.Read(reader);

return new DataResponse<T>(data);
}
Expand Down
54 changes: 53 additions & 1 deletion src/tarantool.client/Converters/TupleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer)
public TarantoolTuple Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}

const uint expected = 0u;
if (actual != expected)
{
throw ExceptionHelper.InvalidArrayLength(expected, actual);
}

return TarantoolTuple.Create();
return TarantoolTuple.Empty;
}
}

Expand Down Expand Up @@ -64,6 +69,12 @@ public void Write(TarantoolTuple<T1> value, IMsgPackWriter writer)
public TarantoolTuple<T1> Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 1u;
if (actual != expected)
{
Expand Down Expand Up @@ -105,6 +116,11 @@ public void Write(TarantoolTuple<T1, T2> value, IMsgPackWriter writer)
public TarantoolTuple<T1, T2> Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}

const uint expected = 2u;
if (actual != expected)
{
Expand Down Expand Up @@ -150,6 +166,12 @@ public void Write(TarantoolTuple<T1, T2, T3> value, IMsgPackWriter writer)
public TarantoolTuple<T1, T2, T3> Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 3u;
if (actual != expected)
{
Expand Down Expand Up @@ -199,6 +221,12 @@ public void Write(TarantoolTuple<T1, T2, T3, T4> value, IMsgPackWriter writer)
public TarantoolTuple<T1, T2, T3, T4> Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 4u;
if (actual != expected)
{
Expand Down Expand Up @@ -252,6 +280,12 @@ public void Write(TarantoolTuple<T1, T2, T3, T4, T5> value, IMsgPackWriter write
public TarantoolTuple<T1, T2, T3, T4, T5> Read(IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 5u;
if (actual != expected)
{
Expand Down Expand Up @@ -310,6 +344,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6> Read(
IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 6u;
if (actual != expected)
{
Expand Down Expand Up @@ -372,6 +412,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6, T7> Read(
IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 7u;
if (actual != expected)
{
Expand Down Expand Up @@ -438,6 +484,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6, T7, TRest> Read(
IMsgPackReader reader)
{
var actual = reader.ReadArrayLength();
if (actual == null)
{
return null;
}


const uint expected = 8u;
if (actual != expected)
{
Expand Down
4 changes: 2 additions & 2 deletions src/tarantool.client/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<DataResponse<TTuple[]>> Replace<TTuple>(TTuple tuple)
public async Task<TTuple> Min<TTuple>()
where TTuple : ITarantoolTuple
{
return await Min<TTuple, TarantoolTuple>(TarantoolTuple.Create());
return await Min<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
}

public async Task<TTuple> Min<TTuple, TKey>(TKey key)
Expand All @@ -104,7 +104,7 @@ public async Task<TTuple> Min<TTuple, TKey>(TKey key)
public async Task<TTuple> Max<TTuple>()
where TTuple : ITarantoolTuple
{
return await Max<TTuple, TarantoolTuple>(TarantoolTuple.Create());
return await Max<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
}

public async Task<TTuple> Max<TTuple, TKey>(TKey key = null)
Expand Down
16 changes: 6 additions & 10 deletions src/tarantool.client/LogicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,20 @@ public async Task<DataResponse<TResponse[]>> SendRequest<TRequest, TResponse>(TR
return await SendRequestImpl<TRequest, DataResponse<TResponse[]>>(request);
}

public TaskCompletionSource<MemoryStream> PopResponseCompletionSource(RequestId requestId,
MemoryStream resultStream)
public TaskCompletionSource<MemoryStream> PopResponseCompletionSource(RequestId requestId, MemoryStream resultStream)
{
TaskCompletionSource<MemoryStream> request;

if (!_pendingRequests.TryRemove(requestId, out request))
{
throw ExceptionHelper.WrongRequestId(requestId);
}

return request;
return _pendingRequests.TryRemove(requestId, out request)
? request
: null;
}

public static byte[] ReadFully(Stream input)
{
input.Position = 0;
byte[] buffer = new byte[16*1024];
using (MemoryStream ms = new MemoryStream())
var buffer = new byte[16*1024];
using (var ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
Expand Down
3 changes: 2 additions & 1 deletion src/tarantool.client/Model/Enums/CommandCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ public enum CommandCode : uint
Replace = 0x03,
Update = 0x04,
Delete = 0x05,
Call = 0x06,
OldCall = 0x06,
Auth = 0x07,
Eval = 0x08,
Upsert = 0x09,
Call = 0x0A,

//Admin command codes
Ping = 0x40,
Expand Down
7 changes: 5 additions & 2 deletions src/tarantool.client/Model/Requests/CallRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ namespace ProGaudi.Tarantool.Client.Model.Requests
public class CallRequest<T> : IRequest
where T : ITarantoolTuple
{
public CallRequest(string functionName, T tuple)
private readonly bool _use17;

public CallRequest(string functionName, T tuple, bool use17 = true)
{
_use17 = use17;
FunctionName = functionName;
Tuple = tuple;
}
Expand All @@ -15,6 +18,6 @@ public CallRequest(string functionName, T tuple)

public T Tuple { get; }

public CommandCode Code => CommandCode.Call;
public CommandCode Code => _use17 ? CommandCode.Call : CommandCode.OldCall;
}
}
Loading