-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list of hosts with ports for setting connection #1
base: master
Are you sure you want to change the base?
Changes from all commits
0d87218
0b74858
d713ce7
0f2da33
25b7fdc
662a27d
53affd2
fabac4d
edf5421
563b7b6
13294d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,7 +481,7 @@ static void RunTests(Client& client) { | |
ArrayExample(client); | ||
CancelableExample(client); | ||
DateExample(client); | ||
DateTime64Example(client); | ||
// DateTime64Example(client); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't delete tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also forgot to commit uncommented line. I had commented it because this example always fails there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, you are right, but I am not sure it's your problem, so you can keep it unchanged for now |
||
DecimalExample(client); | ||
EnumExample(client); | ||
ExecptionExample(client); | ||
|
@@ -510,6 +510,67 @@ int main() { | |
.SetCompressionMethod(CompressionMethod::LZ4)); | ||
RunTests(client); | ||
} | ||
|
||
{ | ||
ClientOptions::HostPort correct_host_port = ClientOptions::HostPort("localhost", 9000); | ||
Client client(ClientOptions() | ||
.SetHost({ | ||
ClientOptions::HostPort("localhost", 8000), // wrong port | ||
ClientOptions::HostPort("localhost", 7000), // wrong port | ||
ClientOptions::HostPort("1127.91.2.1"), // wrong host | ||
ClientOptions::HostPort("1127.91.2.2"), // wrong host | ||
ClientOptions::HostPort("notlocalwronghost"), // wrong host | ||
ClientOptions::HostPort("another_notlocalwronghost"), // wrong host | ||
correct_host_port, | ||
ClientOptions::HostPort("localhost", 9001), // wrong port | ||
ClientOptions::HostPort("1127.911.2.2"), // wrong host | ||
}) | ||
.SetPingBeforeQuery(true)); | ||
assert(client.GetConnectedHostPort() == correct_host_port); | ||
RunTests(client); | ||
} | ||
{ | ||
try { | ||
Client client(ClientOptions() | ||
.SetHost({ | ||
ClientOptions::HostPort("notlocalwronghost") // wrong host | ||
}) | ||
.SetSendRetries(0) | ||
.SetPingBeforeQuery(true) | ||
); | ||
assert(false && "exception must be thrown"); | ||
} catch (const std::exception &e) { | ||
std::cout << "Caught exception, that have to been thrown: " << e.what() << std::endl; | ||
} | ||
} | ||
{ | ||
try { | ||
Client client(ClientOptions() | ||
.SetHost({ | ||
ClientOptions::HostPort("localhost", 8000), // wrong port | ||
}) | ||
.SetSendRetries(0) | ||
.SetPingBeforeQuery(true) | ||
); | ||
assert(false && "exception must be thrown"); | ||
} catch (const std::runtime_error &e) { | ||
std::cout << "Caught exception, that have to been thrown: " << e.what() << std::endl; | ||
} | ||
} | ||
{ | ||
try { | ||
Client client(ClientOptions() | ||
.SetHost({ | ||
ClientOptions::HostPort("1127.91.2.1"), // wrong host | ||
}) | ||
.SetSendRetries(0) | ||
.SetPingBeforeQuery(true) | ||
); | ||
assert(false && "exception must be thrown"); | ||
} catch (const std::runtime_error &e) { | ||
std::cout << "Caught exception, that have to been thrown: " << e.what() << std::endl; | ||
} | ||
} | ||
} catch (const std::exception& e) { | ||
std::cerr << "exception : " << e.what() << std::endl; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to catch specific error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it better? We can't predict what type of object will be thrown. Yea, in this function we throw only
runtime_error
, but we don't exactly know what could be thrown from functions, that are used inResetConnection
.Moreover, in
RetryGuard
previous developers don't catch specific error -- they also use...
. It is partly confirms hypothesis, that any object can be thrown from subfunctions ofResetConnetction
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't predict the type of exception, we don't know the code. But we should do.
It is better because when you read the code, you understand what you throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can catch runtime_error and other exceptions and then use the
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done