@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException { throw new SocketException("not supported"); }
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { throw new SocketException("not supported"); } }
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { throw new SocketException("not supported"); } }
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException { throw new SocketException("not supported"); }
public void write(byte[]... buf) throws IOException { OutputStream output = this.output; if (output != null) { for (byte[] bs : buf) { output.write(bs); } } else { throw new SocketException("Socket already closed."); } }
public int download(String url, FetchHandler handler) throws IOException { timesCalled += 1; if (timesCalled <= count) { throw new SocketException("Connection Reset"); } else { return SC_OK; } } }
@Override public int read(byte b[], int off, int len) throws IOException { if (readCount++ % NUM_READ_COUNTS_BEFORE_ERROR == 0) { if (numConnectionResets++ < maxConnectionResets) { // Simulate connection reset throw new SocketException("Test Connection reset"); } } return delegate.read(b, off, len); } }
@Override public int read() throws IOException { if (readCount++ % NUM_READ_COUNTS_BEFORE_ERROR == 0) { if (numConnectionResets++ < maxConnectionResets) { // Simulate connection reset throw new SocketException("Test Connection reset"); } } return delegate.read(); }
/** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ private Proxy nextProxy() throws IOException { if (!hasNextProxy()) { throw new SocketException("No route to " + address.url().host() + "; exhausted proxy configurations: " + proxies); } Proxy result = proxies.get(nextProxyIndex++); resetNextInetSocketAddress(result); return result; }
@Override public Socket accept() throws IOException { if (isClosed()) { throw new SocketException("Socket is closed"); } if (!isBound()) { throw new SocketException("Socket is not bound yet"); } final PrependableSocket prependableSocket = new PrependableSocket(null); implAccept(prependableSocket); return new UnifiedSocket(x509Util, allowInsecureConnection, prependableSocket); }
@Override public int read(byte b[], int off, int len) throws IOException { if (throwError) { throwError = false; errorCount++; if (errorCount % 2 == 0) { throw new IOException("test retry"); } else { delegate.close(); throw new SocketException("Test Connection reset"); } } else { throwError = errorCount < MAX_ERROR; return delegate.read(b, off, len); } } }
/** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ private Proxy nextProxy() throws IOException { if (!hasNextProxy()) { throw new SocketException("No route to " + address.url().host() + "; exhausted proxy configurations: " + proxies); } Proxy result = proxies.get(nextProxyIndex++); resetNextInetSocketAddress(result); return result; }
throw new SocketException("No route to " + socketHost + ":" + socketPort + "; port is out of range");
/** Returns the next proxy to try. May be PROXY.NO_PROXY but never null. */ private Proxy nextProxy() throws IOException { if (!hasNextProxy()) { throw new SocketException("No route to " + address.url().host() + "; exhausted proxy configurations: " + proxies); } Proxy result = proxies.get(nextProxyIndex++); resetNextInetSocketAddress(result); return result; }
/** {@inheritDoc} */ @Override protected void writeToSocket(Socket sock, OutputStream out, TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException { if (blockAll || block && sock.getPort() == 47500) throw new SocketException("Test discovery exception"); super.writeToSocket(sock, out, msg, timeout); }
@Test public void resolveMethodBestMatch() { SocketException exception = new SocketException(); assertEquals("handleSocketException", this.resolver.resolveMethod(exception).getName()); }
@Override protected void processPacket(QuorumPacket qp) throws Exception { if (stopPing && qp.getType() == Leader.PING) { LOG.info("Follower skipped ping"); throw new SocketException("Socket time out while sending the ping response"); } else { super.processPacket(qp); } } };
@Test public void resolveMethodBestMatch() { ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(ExceptionController.class); SocketException exception = new SocketException(); assertEquals("handleSocketException", resolver.resolveMethod(exception).getName()); }
@Test // SPR-16132 public void followUpRequestAfterFailure() { MockRestServiceServer server = MockRestServiceServer.bindTo(this.restTemplate).build(); server.expect(requestTo("/some-service/some-endpoint")) .andRespond(request -> { throw new SocketException("pseudo network error"); }); server.expect(requestTo("/reporting-service/report-error")) .andExpect(method(POST)).andRespond(withSuccess()); try { this.restTemplate.getForEntity("/some-service/some-endpoint", String.class); } catch (Exception ex) { this.restTemplate.postForEntity("/reporting-service/report-error", ex.toString(), String.class); } server.verify(); }
@Test // SPR-16132 public void sequentialRequestsWithFirstFailing() throws Exception { this.manager.expectRequest(once(), requestTo("/foo")). andExpect(method(GET)).andRespond(request -> { throw new SocketException("pseudo network error"); }); this.manager.expectRequest(once(), requestTo("/handle-error")). andExpect(method(POST)).andRespond(withSuccess()); try { this.manager.validateRequest(createRequest(GET, "/foo")); fail("Expected SocketException"); } catch (SocketException ex) { // expected } this.manager.validateRequest(createRequest(POST, "/handle-error")); this.manager.verify(); }