kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | ec5f39205dd7cd930ddb2fae9b34b6d3d19729f2df31de2c391fb5ea3f92ff62 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-11-03 15:13 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-11-03 15:13 +01:00 |
| Parents | 390663e21058 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/FakeHost.java +13 −3
| @@ -49,24 +49,34 @@ | ||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | @Override public void run() { |
| 52 | + ServerSocket server = null; | |
| 53 | + Socket client = null; | |
| 52 | 54 | try { |
| 53 | 55 | InetAddress bindAddress = InetAddress.getByName(address); |
| 54 | 56 | int backlog = (behavior == Behavior.THROWING_CONNECT_TIMEOUTS) |
| 55 | 57 | ? 1 |
| 56 | 58 | : -1; // default |
| 57 | - ServerSocket server = new ServerSocket(port, backlog, bindAddress); | |
| 59 | + server = new ServerSocket(port, backlog, bindAddress); | |
| 58 | 60 | |
| 59 | 61 | if (behavior == Behavior.THROWING_CONNECT_TIMEOUTS) { |
| 60 | 62 | // fill backlog queue |
| 61 | - new Socket().connect(server.getLocalSocketAddress()); | |
| 63 | + client = new Socket(); | |
| 64 | + client.connect(server.getLocalSocketAddress()); | |
| 62 | 65 | } |
| 63 | - | |
| 64 | 66 | TimeUnit.MINUTES.sleep(10); |
| 65 | 67 | fail("Mock host wasn't expected to live more than 10 minutes"); |
| 66 | 68 | } catch (IOException e) { |
| 67 | 69 | fail("Unexpected I/O exception", e); |
| 68 | 70 | } catch (InterruptedException e) { |
| 69 | 71 | // 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 | + | |
| 70 | 80 | } |
| 71 | 81 | } |
| 72 | 82 | } |