Skip to content

Commit 3c8779c

Browse files
nazaroidaensidhe
authored andcommitted
throw exception when there are no any configured tarantool nodes (#134)
* throw exception when there are no any configured tarantool nodes
1 parent 26d3947 commit 3c8779c

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace ProGaudi.Tarantool.Client
4+
{
5+
public class ClientSetupException : Exception {
6+
public ClientSetupException(string msg) : base(msg)
7+
{
8+
9+
}
10+
}
11+
}

src/progaudi.tarantool/LogicalConnection.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public async Task<byte[]> SendRawRequest<TRequest>(TRequest request, TimeSpan? t
127127

128128
private async Task LoginIfNotGuest(GreetingsResponse greetings)
129129
{
130+
if (! _clientOptions.ConnectionOptions.Nodes.Any())
131+
throw new ClientSetupException("There are zero configured nodes, you should provide one");
132+
130133
var singleNode = _clientOptions.ConnectionOptions.Nodes.Single();
131134

132135
if (string.IsNullOrEmpty(singleNode.Uri.UserName))
@@ -204,4 +207,4 @@ private ArraySegment<byte> CreateAndSerializeHeader<TRequest>(
204207
return new ArraySegment<byte>(packetSizeBuffer, 0, lengthAndHeaderLengthByteCount);
205208
}
206209
}
207-
}
210+
}

src/progaudi.tarantool/NetworkStreamPhysicalConnection.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public void Dispose()
3636

3737
public async Task Connect(ClientOptions options)
3838
{
39+
if (! options.ConnectionOptions.Nodes.Any())
40+
throw new ClientSetupException("There are zero configured nodes, you should provide one");
41+
3942
options.LogWriter?.WriteLine("Starting socket connection...");
4043
var singleNode = options.ConnectionOptions.Nodes.Single();
4144

@@ -121,4 +124,4 @@ private void CheckConnectionStatus()
121124
}
122125
}
123126
}
124-
}
127+
}

tests/progaudi.tarantool.tests/Box/Options.cs

+10
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,15 @@ public async Task ReadBoxInfoOnConnectDisabled()
5050
box.Info.ShouldBeNull();
5151
}
5252
}
53+
54+
[Fact]
55+
public async Task ShouldThrowIfThereAreNoNodesWereConfigured()
56+
{
57+
var options = new ClientOptions();
58+
using (var box = new Client.Box(options))
59+
{
60+
await Assert.ThrowsAsync<ClientSetupException>(() => box.Connect());
61+
}
62+
}
5363
}
5464
}

0 commit comments

Comments
 (0)