4343import java .util .Set ;
4444import java .util .concurrent .CountDownLatch ;
4545import java .util .concurrent .ExecutionException ;
46- import java .util .concurrent .Executors ;
4746import java .util .concurrent .Future ;
4847import java .util .concurrent .TimeUnit ;
4948import java .util .concurrent .atomic .AtomicBoolean ;
6160import org .springframework .beans .factory .BeanFactory ;
6261import org .springframework .core .serializer .DefaultDeserializer ;
6362import org .springframework .core .serializer .DefaultSerializer ;
63+ import org .springframework .core .task .AsyncTaskExecutor ;
64+ import org .springframework .core .task .SimpleAsyncTaskExecutor ;
6465import org .springframework .expression .EvaluationContext ;
6566import org .springframework .expression .Expression ;
6667import org .springframework .expression .spel .standard .SpelExpressionParser ;
@@ -90,6 +91,8 @@ public class TcpOutboundGatewayTests {
9091
9192 private static final Log logger = LogFactory .getLog (TcpOutboundGatewayTests .class );
9293
94+ private AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor ();
95+
9396 @ ClassRule
9497 public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest ();
9598
@@ -101,13 +104,13 @@ public class TcpOutboundGatewayTests {
101104 public void testGoodNetSingle () throws Exception {
102105 final CountDownLatch latch = new CountDownLatch (1 );
103106 final AtomicBoolean done = new AtomicBoolean ();
104- final AtomicReference <ServerSocket > serverSocket = new AtomicReference <ServerSocket >();
105- Executors . newSingleThreadExecutor () .execute (() -> {
107+ final AtomicReference <ServerSocket > serverSocket = new AtomicReference <>();
108+ this . executor .execute (() -> {
106109 try {
107110 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 , 100 );
108111 serverSocket .set (server );
109112 latch .countDown ();
110- List <Socket > sockets = new ArrayList <Socket >();
113+ List <Socket > sockets = new ArrayList <>();
111114 int i = 0 ;
112115 while (true ) {
113116 Socket socket = server .accept ();
@@ -165,8 +168,8 @@ public void testGoodNetSingle() throws Exception {
165168 public void testGoodNetMultiplex () throws Exception {
166169 final CountDownLatch latch = new CountDownLatch (1 );
167170 final AtomicBoolean done = new AtomicBoolean ();
168- final AtomicReference <ServerSocket > serverSocket = new AtomicReference <ServerSocket >();
169- Executors . newSingleThreadExecutor () .execute (() -> {
171+ final AtomicReference <ServerSocket > serverSocket = new AtomicReference <>();
172+ this . executor .execute (() -> {
170173 try {
171174 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 , 10 );
172175 serverSocket .set (server );
@@ -220,8 +223,8 @@ public void testGoodNetMultiplex() throws Exception {
220223 public void testGoodNetTimeout () throws Exception {
221224 final CountDownLatch latch = new CountDownLatch (1 );
222225 final AtomicBoolean done = new AtomicBoolean ();
223- final AtomicReference <ServerSocket > serverSocket = new AtomicReference <ServerSocket >();
224- Executors . newSingleThreadExecutor () .execute (() -> {
226+ final AtomicReference <ServerSocket > serverSocket = new AtomicReference <>();
227+ this . executor .execute (() -> {
225228 try {
226229 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
227230 serverSocket .set (server );
@@ -260,12 +263,12 @@ public void testGoodNetTimeout() throws Exception {
260263 Future <Integer >[] results = (Future <Integer >[]) new Future <?>[2 ];
261264 for (int i = 0 ; i < 2 ; i ++) {
262265 final int j = i ;
263- results [j ] = (Executors . newSingleThreadExecutor () .submit (() -> {
266+ results [j ] = (this . executor .submit (() -> {
264267 gateway .handleMessage (MessageBuilder .withPayload ("Test" + j ).build ());
265268 return 0 ;
266269 }));
267270 }
268- Set <String > replies = new HashSet <String >();
271+ Set <String > replies = new HashSet <>();
269272 int timeouts = 0 ;
270273 for (int i = 0 ; i < 2 ; i ++) {
271274 try {
@@ -344,7 +347,7 @@ private void testGoodNetGWTimeoutGuts(final int port, AbstractClientConnectionFa
344347 final AtomicReference <String > lastReceived = new AtomicReference <String >();
345348 final CountDownLatch serverLatch = new CountDownLatch (2 );
346349
347- Executors . newSingleThreadExecutor () .execute (() -> {
350+ this . executor .execute (() -> {
348351 try {
349352 latch .countDown ();
350353 int i = 0 ;
@@ -398,7 +401,7 @@ private void testGoodNetGWTimeoutGuts(final int port, AbstractClientConnectionFa
398401
399402 for (int i = 0 ; i < 2 ; i ++) {
400403 final int j = i ;
401- results [j ] = (Executors . newSingleThreadExecutor () .submit (() -> {
404+ results [j ] = (this . executor .submit (() -> {
402405 gateway .handleMessage (MessageBuilder .withPayload ("Test" + j ).build ());
403406 return j ;
404407 }));
@@ -442,7 +445,7 @@ public void testCachingFailover() throws Exception {
442445 final AtomicBoolean done = new AtomicBoolean ();
443446 final CountDownLatch serverLatch = new CountDownLatch (1 );
444447
445- Executors . newSingleThreadExecutor () .execute (() -> {
448+ this . executor .execute (() -> {
446449 try {
447450 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
448451 serverSocket .set (server );
@@ -517,12 +520,12 @@ public void testCachingFailover() throws Exception {
517520
518521 @ Test
519522 public void testFailoverCached () throws Exception {
520- final AtomicReference <ServerSocket > serverSocket = new AtomicReference <ServerSocket >();
523+ final AtomicReference <ServerSocket > serverSocket = new AtomicReference <>();
521524 final CountDownLatch latch = new CountDownLatch (1 );
522525 final AtomicBoolean done = new AtomicBoolean ();
523526 final CountDownLatch serverLatch = new CountDownLatch (1 );
524527
525- Executors . newSingleThreadExecutor () .execute (() -> {
528+ this . executor .execute (() -> {
526529 try {
527530 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
528531 serverSocket .set (server );
@@ -667,11 +670,11 @@ private void testGWPropagatesSocketCloseGuts(final int port, AbstractClientConne
667670 final ServerSocket server ) throws Exception {
668671 final CountDownLatch latch = new CountDownLatch (1 );
669672 final AtomicBoolean done = new AtomicBoolean ();
670- final AtomicReference <String > lastReceived = new AtomicReference <String >();
673+ final AtomicReference <String > lastReceived = new AtomicReference <>();
671674 final CountDownLatch serverLatch = new CountDownLatch (1 );
672675
673- Executors . newSingleThreadExecutor () .execute (() -> {
674- List <Socket > sockets = new ArrayList <Socket >();
676+ this . executor .execute (() -> {
677+ List <Socket > sockets = new ArrayList <>();
675678 try {
676679 latch .countDown ();
677680 while (!done .get ()) {
@@ -793,8 +796,8 @@ private void testGWPropagatesSocketTimeoutGuts(final int port, AbstractClientCon
793796 final CountDownLatch latch = new CountDownLatch (1 );
794797 final AtomicBoolean done = new AtomicBoolean ();
795798
796- Executors . newSingleThreadExecutor () .execute (() -> {
797- List <Socket > sockets = new ArrayList <Socket >();
799+ this . executor .execute (() -> {
800+ List <Socket > sockets = new ArrayList <>();
798801 try {
799802 latch .countDown ();
800803 while (!done .get ()) {
0 commit comments