|
17 | 17 | package org.springframework.integration.ip.tcp.connection;
|
18 | 18 |
|
19 | 19 | import static org.hamcrest.Matchers.containsString;
|
| 20 | +import static org.hamcrest.Matchers.lessThan; |
20 | 21 | import static org.hamcrest.Matchers.not;
|
21 | 22 | import static org.junit.Assert.assertEquals;
|
22 | 23 | import static org.junit.Assert.assertNotNull;
|
|
64 | 65 |
|
65 | 66 | import org.apache.commons.logging.Log;
|
66 | 67 | import org.apache.commons.logging.LogFactory;
|
| 68 | +import org.junit.Ignore; |
67 | 69 | import org.junit.Rule;
|
68 | 70 | import org.junit.Test;
|
69 | 71 | import org.junit.rules.TestName;
|
|
90 | 92 | import org.springframework.messaging.support.ErrorMessage;
|
91 | 93 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
92 | 94 | import org.springframework.util.ReflectionUtils;
|
| 95 | +import org.springframework.util.StopWatch; |
93 | 96 |
|
94 | 97 |
|
95 | 98 | /**
|
@@ -130,6 +133,7 @@ public void testWriteTimeout() throws Exception {
|
130 | 133 | Socket s = server.accept();
|
131 | 134 | // block so we fill the buffer
|
132 | 135 | done.await(10, TimeUnit.SECONDS);
|
| 136 | + s.close(); |
133 | 137 | }
|
134 | 138 | catch (Exception e) {
|
135 | 139 | e.printStackTrace();
|
@@ -806,6 +810,36 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
|
806 | 810 | te.shutdown();
|
807 | 811 | }
|
808 | 812 |
|
| 813 | + @Test |
| 814 | + @Ignore // Timing is too short for CI/Travis |
| 815 | + public void testNoDelayOnClose() throws Exception { |
| 816 | + TcpNioServerConnectionFactory cf = new TcpNioServerConnectionFactory(0); |
| 817 | + final CountDownLatch reading = new CountDownLatch(1); |
| 818 | + final StopWatch watch = new StopWatch(); |
| 819 | + cf.setDeserializer(is -> { |
| 820 | + reading.countDown(); |
| 821 | + watch.start(); |
| 822 | + is.read(); |
| 823 | + is.read(); |
| 824 | + watch.stop(); |
| 825 | + return null; |
| 826 | + }); |
| 827 | + cf.registerListener(m -> false); |
| 828 | + final CountDownLatch listening = new CountDownLatch(1); |
| 829 | + cf.setApplicationEventPublisher(e -> { |
| 830 | + listening.countDown(); |
| 831 | + }); |
| 832 | + cf.afterPropertiesSet(); |
| 833 | + cf.start(); |
| 834 | + assertTrue(listening.await(10, TimeUnit.SECONDS)); |
| 835 | + Socket socket = SocketFactory.getDefault().createSocket("localhost", cf.getPort()); |
| 836 | + socket.getOutputStream().write("x".getBytes()); |
| 837 | + assertTrue(reading.await(10, TimeUnit.SECONDS)); |
| 838 | + socket.close(); |
| 839 | + cf.stop(); |
| 840 | + assertThat(watch.getLastTaskTimeMillis(), lessThan(950L)); |
| 841 | + } |
| 842 | + |
809 | 843 | private void readFully(InputStream is, byte[] buff) throws IOException {
|
810 | 844 | for (int i = 0; i < buff.length; i++) {
|
811 | 845 | buff[i] = (byte) is.read();
|
|
0 commit comments