Skip to content

Commit f26c3a9

Browse files
committed
Polishing SocketSupportTests
https://build.spring.io/browse/INT-MASTER-952 The SSL error might be like `Connection reset by peer` as well. Also move `client` and `server` `stop()` to the finally, since it looks like in case of handshake error we leave dangling opened socket
1 parent 60be693 commit f26c3a9

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/SocketSupportTests.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,8 @@
6060

6161
/**
6262
* @author Gary Russell
63+
* @author Artem Bilan
64+
*
6365
* @since 2.2
6466
*/
6567
public class SocketSupportTests {
@@ -354,15 +356,18 @@ public void postProcessServerSocket(ServerSocket serverSocket) {
354356
DefaultTcpNetSSLSocketFactorySupport clientTcpSocketFactorySupport =
355357
new DefaultTcpNetSSLSocketFactorySupport(clientSslContextSupport);
356358
client.setTcpSocketFactorySupport(clientTcpSocketFactorySupport);
357-
client.start();
358-
359-
TcpConnection connection = client.getConnection();
360-
connection.send(new GenericMessage<String>("Hello, world!"));
361-
assertTrue(latch.await(10, TimeUnit.SECONDS));
362-
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
363359

364-
client.stop();
365-
server.stop();
360+
try {
361+
client.start();
362+
TcpConnection connection = client.getConnection();
363+
connection.send(new GenericMessage<String>("Hello, world!"));
364+
assertTrue(latch.await(10, TimeUnit.SECONDS));
365+
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
366+
}
367+
finally {
368+
client.stop();
369+
server.stop();
370+
}
366371
}
367372

368373
@Test
@@ -428,7 +433,8 @@ public void testNioClientAndServerSSLDifferentContexts() throws Exception {
428433
assertThat(e.getMessage(),
429434
anyOf(
430435
containsString("Socket closed during SSL Handshake"),
431-
containsString("Broken pipe")));
436+
containsString("Broken pipe"),
437+
containsString("Connection reset by peer")));
432438
}
433439
}
434440
}
@@ -465,15 +471,18 @@ protected void postProcessSSLEngine(SSLEngine sslEngine) {
465471
DefaultTcpNioSSLConnectionSupport clientTcpNioConnectionSupport =
466472
new DefaultTcpNioSSLConnectionSupport(clientSslContextSupport);
467473
client.setTcpNioConnectionSupport(clientTcpNioConnectionSupport);
468-
client.start();
469-
470-
TcpConnection connection = client.getConnection();
471-
connection.send(new GenericMessage<String>("Hello, world!"));
472-
assertTrue(latch.await(10, TimeUnit.SECONDS));
473-
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
474474

475-
client.stop();
476-
server.stop();
475+
try {
476+
client.start();
477+
TcpConnection connection = client.getConnection();
478+
connection.send(new GenericMessage<String>("Hello, world!"));
479+
assertTrue(latch.await(10, TimeUnit.SECONDS));
480+
assertEquals("Hello, world!", new String((byte[]) messages.get(0).getPayload()));
481+
}
482+
finally {
483+
client.stop();
484+
server.stop();
485+
}
477486
}
478487

479488
@Test

0 commit comments

Comments
 (0)