@Override protected IOException newTimeoutException(IOException cause) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (cause != null) { socketTimeoutException.initCause(cause); } return socketTimeoutException; }
@Override protected IOException newTimeoutException(@Nullable IOException cause) { InterruptedIOException ioe = new SocketTimeoutException("timeout"); if (cause != null) { ioe.initCause(cause); } return ioe; }
@Override protected IOException newTimeoutException(IOException cause) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (cause != null) { socketTimeoutException.initCause(cause); } return socketTimeoutException; }
@Override protected IOException newTimeoutException(IOException cause) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (cause != null) { socketTimeoutException.initCause(cause); } return socketTimeoutException; }
@Override public void write(byte[] source, int offset, int byteCount) throws IOException { if (closed) throw new IOException("closed"); // Not IllegalStateException! if (expectedContentLength != -1L && bytesReceived + byteCount > expectedContentLength) { throw new ProtocolException("expected " + expectedContentLength + " bytes but received " + bytesReceived + byteCount); } bytesReceived += byteCount; try { sink.write(source, offset, byteCount); } catch (InterruptedIOException e) { throw new SocketTimeoutException(e.getMessage()); } }
@Override public void write(byte[] source, int offset, int byteCount) throws IOException { if (closed) throw new IOException("closed"); // Not IllegalStateException! if (expectedContentLength != -1L && bytesReceived + byteCount > expectedContentLength) { throw new ProtocolException("expected " + expectedContentLength + " bytes but received " + bytesReceived + byteCount); } bytesReceived += byteCount; try { sink.write(source, offset, byteCount); } catch (InterruptedIOException e) { throw new SocketTimeoutException(e.getMessage()); } }
void writePingFrame() { WebSocketWriter writer; int failedPing; synchronized (this) { if (failed) return; writer = this.writer; failedPing = awaitingPong ? sentPingCount : -1; sentPingCount++; awaitingPong = true; } if (failedPing != -1) { failWebSocket(new SocketTimeoutException("sent ping but didn't receive pong within " + pingIntervalMillis + "ms (after " + (failedPing - 1) + " successful ping/pongs)"), null); return; } try { writer.writePing(ByteString.EMPTY); } catch (IOException e) { failWebSocket(e, null); } }
/** {@inheritDoc} */ @Override protected void writeToSocket(Socket sock, TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException { if (netDisabled) { netDisabledLatch.countDown(); throw new SocketTimeoutException("CustomDiscoverySpi: network is disabled."); } else super.writeToSocket(sock, msg, timeout); }
@Test public void testHeartbeatStatsSerialization() throws Exception { ObjectMapper objectMapper = new ObjectMapperProvider().get(); Stats stats = new Stats(new URI("http://example.com")); String serialized = objectMapper.writeValueAsString(stats); JsonNode deserialized = objectMapper.readTree(serialized); assertFalse(deserialized.has("lastFailureInfo")); stats.recordFailure(new SocketTimeoutException("timeout")); serialized = objectMapper.writeValueAsString(stats); deserialized = objectMapper.readTree(serialized); assertFalse(deserialized.get("lastFailureInfo").isNull()); assertEquals(deserialized.get("lastFailureInfo").get("type").asText(), SocketTimeoutException.class.getName()); }
@Test public void testCatchesExceptionOnReadBufferWithOffsetAndCount() throws IOException { IOException exception = new SocketTimeoutException(); when(wrapped.read(any(byte[].class), anyInt(), anyInt())).thenThrow(exception); int read = is.read(new byte[0], 10, 100); assertEquals(-1, read); assertEquals(exception, is.getException()); }
/** {@inheritDoc} */ @Override public void sendMessage(ByteBuffer data) throws IgniteCheckedException { if (failure && !matrix.hasConnection(locNode, remoteNode)) throw new IgniteCheckedException("Test", new SocketTimeoutException()); delegate.sendMessage(data); }
/** {@inheritDoc} */ @Override public void sendMessage(byte[] data, int len) throws IgniteCheckedException { if (failure && !matrix.hasConnection(locNode, remoteNode)) throw new IgniteCheckedException("Test", new SocketTimeoutException()); delegate.sendMessage(data, len); }
/** {@inheritDoc} */ @Override public void doHandshake(IgniteInClosure2X<InputStream, OutputStream> handshakeC) throws IgniteCheckedException { if (failure && !matrix.hasConnection(locNode, remoteNode)) throw new IgniteCheckedException("Test", new SocketTimeoutException()); delegate.doHandshake(handshakeC); }
/** {@inheritDoc} */ @Override protected <T> T readMessage(Socket sock, @Nullable InputStream in, long timeout) throws IOException, IgniteCheckedException { if (netDisabled) { U.sleep(timeout); throw new SocketTimeoutException("CustomDiscoverySpi: network is disabled."); } else return super.readMessage(sock, in, timeout); }
@Test public void testCatchesExceptionOnReadBuffer() throws IOException { IOException exception = new SocketTimeoutException(); when(wrapped.read(any(byte[].class))).thenThrow(exception); int read = is.read(new byte[0]); assertEquals(-1, read); assertEquals(exception, is.getException()); }
@Test public void testCatchesExceptionOnRead() throws IOException { IOException expected = new SocketTimeoutException(); when(wrapped.read()).thenThrow(expected); int read = is.read(); assertEquals(-1, read); assertEquals(expected, is.getException()); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void testResetsExceptionToNullOnRelease() throws IOException { IOException exception = new SocketTimeoutException(); when(wrapped.read()).thenThrow(exception); is.read(); is.release(); assertNull(is.getException()); }
@Test public void testCatchesExceptionOnSkip() throws IOException { IOException exception = new SocketTimeoutException(); when(wrapped.skip(anyLong())).thenThrow(exception); long skipped = is.skip(100); assertEquals(0, skipped); assertEquals(exception, is.getException()); }
@Override void readPacket(QuorumPacket pp) throws IOException { /** * In real scenario got SocketTimeoutException while reading * the packet from leader because of network problem, but * here throwing SocketTimeoutException based on whether * error is injected or not */ super.readPacket(pp); if (injectError && pp.getType() == Leader.PROPOSAL) { String type = LearnerHandler.packetToString(pp); throw new SocketTimeoutException( "Socket timeout while reading the packet for operation " + type); } }
/** {@inheritDoc} */ @Override protected GridCommunicationClient createTcpClient( ClusterNode node, int connIdx ) throws IgniteCheckedException { if (failure && !matrix.hasConnection(getLocalNode(), node)) { processClientCreationError(node, null, new IgniteCheckedException("Test", new SocketTimeoutException())); return null; } return new FailingCommunicationClient(getLocalNode(), node, super.createTcpClient(node, connIdx)); }