@Test public void connectUnknownHost() throws Exception { Mockito.doThrow(new UnknownHostException()).when(mockSocket).connect(Mockito.any()); final TcpCollector.ConnectDatum result; try (TcpCollector tcpCollector = new TcpCollector(dstAddress, GROUP)) { result = tcpCollector.tryConnect(mockSocket); } assertThat(result.getResult(), equalTo(TcpCollector.ConnectResult.UNKNOWN_HOST)); Mockito.verify(mockSocket, times(1)).connect(Mockito.eq(dstAddress)); Mockito.verifyNoMoreInteractions(mockSocket); }
private ConnectDatum tryConnect() { try (SocketChannel dstSocket = SocketChannel.open()) { return tryConnect(dstSocket); } catch (IOException ex) { throw new RuntimeException("socket creation failed", ex); } }
TcpCollector extends SynchronousGroupGenerator { private ConnectDatum tryConnect() { try (SocketChannel dstSocket = SocketChannel.open()) { return tryConnect(dstSocket); } catch (IOException ex) { throw new RuntimeException("socket creation failed", ex); } } }
TcpCollector extends SynchronousGroupGenerator { private ConnectDatum tryConnect() { try (SocketChannel dstSocket = SocketChannel.open()) { return tryConnect(dstSocket); } catch (IOException ex) { throw new RuntimeException("socket creation failed", ex); } }  }
TcpCollector extends SynchronousGroupGenerator { private ConnectDatum tryConnect() { try (SocketChannel dstSocket = SocketChannel.open()) { return tryConnect(dstSocket); } catch (IOException ex) { throw new RuntimeException("socket creation failed", ex); } }  @Override Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout); }
TcpCollector extends SynchronousGroupGenerator { private ConnectDatum tryConnect() { try (SocketChannel dstSocket = SocketChannel.open()) { return tryConnect(dstSocket); } catch (IOException ex) { throw new RuntimeException("socket creation failed", ex); } }  @Override Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout);  }