Skip to content

Commit b9f0820

Browse files
authored
Merge pull request #72 from progaudi/fix/tests/cleanup
Fix/tests/cleanup
2 parents d4106f5 + ba2973f commit b9f0820

File tree

25 files changed

+698
-315
lines changed

25 files changed

+698
-315
lines changed

.travis.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@ services:
1616
- docker
1717

1818
before_script:
19+
- .travis/$TRAVIS_OS_NAME/init.sh
1920
- dotnet restore
20-
- docker -v
21-
- docker-compose down
22-
- docker-compose up -d
23-
- pushd samples/docker-compose
24-
- docker-compose down
25-
- docker-compose up -d --build
26-
- popd
2721

2822
script:
2923
- dotnet build -f netcoreapp1.0 src/tarantool.client
30-
- dotnet test tests/tarantool.client.tests
31-
- curl --fail http://localhost:5000
24+
- .travis/$TRAVIS_OS_NAME/test.sh

.travis/linux/init.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Linux init script'
4+
5+
docker -v
6+
docker-compose down
7+
docker-compose up -d
8+
pushd samples/docker-compose
9+
docker-compose down
10+
docker-compose up -d --build
11+
popd

.travis/linux/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Linux test script'
4+
5+
dotnet test tests/tarantool.client.tests
6+
curl -o /dev/null --fail http://localhost:5000

.travis/osx/init.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Mac init script'
4+
brew tap caskroom/cask
5+
brew cask install docker

.travis/osx/test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Mac test script'

_T4Awesome/CodeItems/31c71f1f-2480-4de2-98a0-97a1c9b23c49/21fcbb60-2d73-4a67-b07c-dedd7cfe2799.tt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public interface ITuple{}
1+
public interface ITarantoolTuple{}
22
<#
33
var maxParametersCount = 8;
44
var typeParameters = new Func<int, string>(count => string.Join(", ", Enumerable.Range(1, count).Select(num => $"T{num}")));
@@ -38,12 +38,29 @@ for(int i=0;i < maxParametersCount; i++){
3838
return hashCode;
3939
}
4040
}
41+
42+
public override string ToString()
43+
{
44+
return $"<# for(int j=0; j< i+1; j++)
45+
{
46+
if (j != 0)
47+
{
48+
#>, <#
49+
}
50+
#>{Item<#=j+1#>}<#
51+
} #>";
52+
}
4153
}
4254
<#
4355
}
4456
#>
4557

46-
public class TarantoolTuple{
58+
public class TarantoolTuple : ITarantoolTuple {
59+
private TarantoolTuple()
60+
{
61+
}
62+
63+
public static TarantoolTuple Empty { get; } = new TarantoolTuple();
4764
<#
4865
for(int i=0;i < maxParametersCount; i++){
4966
#>

src/tarantool.client/Box.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,54 @@ public Schema GetSchema()
8282
return new Schema(_logicalConnection);
8383
}
8484

85-
public async Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple request)
85+
public async Task Call_1_6(string functionName)
86+
{
87+
await Call_1_6<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
88+
}
89+
90+
public Task<DataResponse<TResponse[]>> Call_1_6<TResponse>(string functionName)
91+
where TResponse : ITarantoolTuple
92+
{
93+
return Call_1_6<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
94+
}
95+
96+
public async Task<DataResponse<TResponse[]>> Call_1_6<TTuple, TResponse>(string functionName, TTuple parameters)
8697
where TTuple : ITarantoolTuple
8798
where TResponse : ITarantoolTuple
8899
{
89-
var callRequest = new CallRequest<TTuple>(functionName, request);
100+
var callRequest = new CallRequest<TTuple>(functionName, parameters, false);
90101
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
91102
}
92103

93-
public async Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple request)
104+
public async Task Call(string functionName)
105+
{
106+
await Call<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
107+
}
108+
109+
public Task<DataResponse<TResponse[]>> Call<TResponse>(string functionName)
110+
{
111+
return Call<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
112+
}
113+
114+
public async Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple parameters)
115+
where TTuple : ITarantoolTuple
116+
{
117+
var callRequest = new CallRequest<TTuple>(functionName, parameters);
118+
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
119+
}
120+
121+
public async Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple parameters)
94122
where TTuple : ITarantoolTuple
95123
{
96-
var evalRequest = new EvalRequest<TTuple>(expression, request);
124+
var evalRequest = new EvalRequest<TTuple>(expression, parameters);
97125
return await _logicalConnection.SendRequest<EvalRequest<TTuple>, TResponse>(evalRequest);
98126
}
99127

128+
public Task<DataResponse<TResponse[]>> Eval<TResponse>(string expression)
129+
{
130+
return Eval<TarantoolTuple, TResponse>(expression, TarantoolTuple.Empty);
131+
}
132+
100133
private async Task LoginIfNotGuest(GreetingsResponse greetings)
101134
{
102135
var singleNode = _clientOptions.ConnectionOptions.Nodes.Single();

src/tarantool.client/Converters/ResponsePacketConverter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public void Write(DataResponse<T> value, IMsgPackWriter writer)
2727

2828
public DataResponse<T> Read(IMsgPackReader reader)
2929
{
30-
var data = default(T);
31-
3230
var length = reader.ReadMapLength();
3331
if (length != 1u)
3432
{
@@ -41,7 +39,7 @@ public DataResponse<T> Read(IMsgPackReader reader)
4139
throw ExceptionHelper.UnexpectedKey(dataKey, Key.Data);
4240
}
4341

44-
data = _dataConverter.Read(reader);
42+
var data = _dataConverter.Read(reader);
4543

4644
return new DataResponse<T>(data);
4745
}

src/tarantool.client/Converters/TupleConverter.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ public void Write(TarantoolTuple value, IMsgPackWriter writer)
2828
public TarantoolTuple Read(IMsgPackReader reader)
2929
{
3030
var actual = reader.ReadArrayLength();
31+
if (actual == null)
32+
{
33+
return null;
34+
}
35+
3136
const uint expected = 0u;
3237
if (actual != expected)
3338
{
3439
throw ExceptionHelper.InvalidArrayLength(expected, actual);
3540
}
3641

37-
return TarantoolTuple.Create();
42+
return TarantoolTuple.Empty;
3843
}
3944
}
4045

@@ -64,6 +69,12 @@ public void Write(TarantoolTuple<T1> value, IMsgPackWriter writer)
6469
public TarantoolTuple<T1> Read(IMsgPackReader reader)
6570
{
6671
var actual = reader.ReadArrayLength();
72+
if (actual == null)
73+
{
74+
return null;
75+
}
76+
77+
6778
const uint expected = 1u;
6879
if (actual != expected)
6980
{
@@ -105,6 +116,11 @@ public void Write(TarantoolTuple<T1, T2> value, IMsgPackWriter writer)
105116
public TarantoolTuple<T1, T2> Read(IMsgPackReader reader)
106117
{
107118
var actual = reader.ReadArrayLength();
119+
if (actual == null)
120+
{
121+
return null;
122+
}
123+
108124
const uint expected = 2u;
109125
if (actual != expected)
110126
{
@@ -150,6 +166,12 @@ public void Write(TarantoolTuple<T1, T2, T3> value, IMsgPackWriter writer)
150166
public TarantoolTuple<T1, T2, T3> Read(IMsgPackReader reader)
151167
{
152168
var actual = reader.ReadArrayLength();
169+
if (actual == null)
170+
{
171+
return null;
172+
}
173+
174+
153175
const uint expected = 3u;
154176
if (actual != expected)
155177
{
@@ -199,6 +221,12 @@ public void Write(TarantoolTuple<T1, T2, T3, T4> value, IMsgPackWriter writer)
199221
public TarantoolTuple<T1, T2, T3, T4> Read(IMsgPackReader reader)
200222
{
201223
var actual = reader.ReadArrayLength();
224+
if (actual == null)
225+
{
226+
return null;
227+
}
228+
229+
202230
const uint expected = 4u;
203231
if (actual != expected)
204232
{
@@ -252,6 +280,12 @@ public void Write(TarantoolTuple<T1, T2, T3, T4, T5> value, IMsgPackWriter write
252280
public TarantoolTuple<T1, T2, T3, T4, T5> Read(IMsgPackReader reader)
253281
{
254282
var actual = reader.ReadArrayLength();
283+
if (actual == null)
284+
{
285+
return null;
286+
}
287+
288+
255289
const uint expected = 5u;
256290
if (actual != expected)
257291
{
@@ -310,6 +344,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6> Read(
310344
IMsgPackReader reader)
311345
{
312346
var actual = reader.ReadArrayLength();
347+
if (actual == null)
348+
{
349+
return null;
350+
}
351+
352+
313353
const uint expected = 6u;
314354
if (actual != expected)
315355
{
@@ -372,6 +412,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6, T7> Read(
372412
IMsgPackReader reader)
373413
{
374414
var actual = reader.ReadArrayLength();
415+
if (actual == null)
416+
{
417+
return null;
418+
}
419+
420+
375421
const uint expected = 7u;
376422
if (actual != expected)
377423
{
@@ -438,6 +484,12 @@ public TarantoolTuple<T1, T2, T3, T4, T5, T6, T7, TRest> Read(
438484
IMsgPackReader reader)
439485
{
440486
var actual = reader.ReadArrayLength();
487+
if (actual == null)
488+
{
489+
return null;
490+
}
491+
492+
441493
const uint expected = 8u;
442494
if (actual != expected)
443495
{

src/tarantool.client/Index.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task<DataResponse<TTuple[]>> Replace<TTuple>(TTuple tuple)
8282
public async Task<TTuple> Min<TTuple>()
8383
where TTuple : ITarantoolTuple
8484
{
85-
return await Min<TTuple, TarantoolTuple>(TarantoolTuple.Create());
85+
return await Min<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
8686
}
8787

8888
public async Task<TTuple> Min<TTuple, TKey>(TKey key)
@@ -104,7 +104,7 @@ public async Task<TTuple> Min<TTuple, TKey>(TKey key)
104104
public async Task<TTuple> Max<TTuple>()
105105
where TTuple : ITarantoolTuple
106106
{
107-
return await Max<TTuple, TarantoolTuple>(TarantoolTuple.Create());
107+
return await Max<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
108108
}
109109

110110
public async Task<TTuple> Max<TTuple, TKey>(TKey key = null)

src/tarantool.client/LogicalConnection.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,20 @@ public async Task<DataResponse<TResponse[]>> SendRequest<TRequest, TResponse>(TR
4848
return await SendRequestImpl<TRequest, DataResponse<TResponse[]>>(request);
4949
}
5050

51-
public TaskCompletionSource<MemoryStream> PopResponseCompletionSource(RequestId requestId,
52-
MemoryStream resultStream)
51+
public TaskCompletionSource<MemoryStream> PopResponseCompletionSource(RequestId requestId, MemoryStream resultStream)
5352
{
5453
TaskCompletionSource<MemoryStream> request;
5554

56-
if (!_pendingRequests.TryRemove(requestId, out request))
57-
{
58-
throw ExceptionHelper.WrongRequestId(requestId);
59-
}
60-
61-
return request;
55+
return _pendingRequests.TryRemove(requestId, out request)
56+
? request
57+
: null;
6258
}
6359

6460
public static byte[] ReadFully(Stream input)
6561
{
6662
input.Position = 0;
67-
byte[] buffer = new byte[16*1024];
68-
using (MemoryStream ms = new MemoryStream())
63+
var buffer = new byte[16*1024];
64+
using (var ms = new MemoryStream())
6965
{
7066
int read;
7167
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)

src/tarantool.client/Model/Enums/CommandCode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ public enum CommandCode : uint
88
Replace = 0x03,
99
Update = 0x04,
1010
Delete = 0x05,
11-
Call = 0x06,
11+
OldCall = 0x06,
1212
Auth = 0x07,
1313
Eval = 0x08,
1414
Upsert = 0x09,
15+
Call = 0x0A,
1516

1617
//Admin command codes
1718
Ping = 0x40,

src/tarantool.client/Model/Requests/CallRequest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ namespace ProGaudi.Tarantool.Client.Model.Requests
55
public class CallRequest<T> : IRequest
66
where T : ITarantoolTuple
77
{
8-
public CallRequest(string functionName, T tuple)
8+
private readonly bool _use17;
9+
10+
public CallRequest(string functionName, T tuple, bool use17 = true)
911
{
12+
_use17 = use17;
1013
FunctionName = functionName;
1114
Tuple = tuple;
1215
}
@@ -15,6 +18,6 @@ public CallRequest(string functionName, T tuple)
1518

1619
public T Tuple { get; }
1720

18-
public CommandCode Code => CommandCode.Call;
21+
public CommandCode Code => _use17 ? CommandCode.Call : CommandCode.OldCall;
1922
}
2023
}

0 commit comments

Comments
 (0)