List of usage examples for org.springframework.integration.ip.tcp.connection TcpNioConnection setPipeTimeout
public void setPipeTimeout(long pipeTimeout)
From source file:org.springframework.integration.ip.tcp.connection.TcpNioConnectionTests.java
@Test public void testInsufficientThreads() throws Exception { final ExecutorService exec = Executors.newFixedThreadPool(2); Future<Object> future = exec.submit(() -> { SocketChannel channel = mock(SocketChannel.class); Socket socket = mock(Socket.class); Mockito.when(channel.socket()).thenReturn(socket); doAnswer(invocation -> {//from w w w.j ava 2s .c om ByteBuffer buffer = invocation.getArgument(0); buffer.position(1); return 1; }).when(channel).read(Mockito.any(ByteBuffer.class)); when(socket.getReceiveBufferSize()).thenReturn(1024); final TcpNioConnection connection = new TcpNioConnection(channel, false, false, nullPublisher, null); connection.setTaskExecutor(exec); connection.setPipeTimeout(200); Method method = TcpNioConnection.class.getDeclaredMethod("doRead"); method.setAccessible(true); // Nobody reading, should timeout on 6th write. try { for (int i = 0; i < 6; i++) { method.invoke(connection); } } catch (Exception e) { e.printStackTrace(); throw (Exception) e.getCause(); } return null; }); try { Object o = future.get(10, TimeUnit.SECONDS); fail("Expected exception, got " + o); } catch (ExecutionException e) { assertEquals("Timed out waiting for buffer space", e.getCause().getMessage()); } }