Elffuss BraidHub

kikocis/java-driver public

Properly close sockets in FakeHost.
Changesetec5f39205dd7cd930ddb2fae9b34b6d3d19729f2df31de2c391fb5ea3f92ff62
Authorolim7t <omichallat+github@gmail.com> · 2014-11-03 15:13 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2014-11-03 15:13 +01:00
Parents390663e21058

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/FakeHost.java +13 −3
@@ -49,24 +49,34 @@
4949 }
5050
5151 @Override public void run() {
52+ ServerSocket server = null;
53+ Socket client = null;
5254 try {
5355 InetAddress bindAddress = InetAddress.getByName(address);
5456 int backlog = (behavior == Behavior.THROWING_CONNECT_TIMEOUTS)
5557 ? 1
5658 : -1; // default
57- ServerSocket server = new ServerSocket(port, backlog, bindAddress);
59+ server = new ServerSocket(port, backlog, bindAddress);
5860
5961 if (behavior == Behavior.THROWING_CONNECT_TIMEOUTS) {
6062 // fill backlog queue
61- new Socket().connect(server.getLocalSocketAddress());
63+ client = new Socket();
64+ client.connect(server.getLocalSocketAddress());
6265 }
63-
6466 TimeUnit.MINUTES.sleep(10);
6567 fail("Mock host wasn't expected to live more than 10 minutes");
6668 } catch (IOException e) {
6769 fail("Unexpected I/O exception", e);
6870 } catch (InterruptedException e) {
6971 // interruption is the expected way to stop this runnable, exit
72+ try {
73+ if (client != null)
74+ client.close();
75+ server.close();
76+ } catch (IOException e1) {
77+ fail("Unexpected error while closing sockets", e);
78+ }
79+
7080 }
7181 }
7282 }