43
43
import java .util .Set ;
44
44
import java .util .concurrent .CountDownLatch ;
45
45
import java .util .concurrent .ExecutionException ;
46
- import java .util .concurrent .Executors ;
47
46
import java .util .concurrent .Future ;
48
47
import java .util .concurrent .TimeUnit ;
49
48
import java .util .concurrent .atomic .AtomicBoolean ;
61
60
import org .springframework .beans .factory .BeanFactory ;
62
61
import org .springframework .core .serializer .DefaultDeserializer ;
63
62
import org .springframework .core .serializer .DefaultSerializer ;
63
+ import org .springframework .core .task .AsyncTaskExecutor ;
64
+ import org .springframework .core .task .SimpleAsyncTaskExecutor ;
64
65
import org .springframework .expression .EvaluationContext ;
65
66
import org .springframework .expression .Expression ;
66
67
import org .springframework .expression .spel .standard .SpelExpressionParser ;
@@ -90,6 +91,8 @@ public class TcpOutboundGatewayTests {
90
91
91
92
private static final Log logger = LogFactory .getLog (TcpOutboundGatewayTests .class );
92
93
94
+ private AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor ();
95
+
93
96
@ ClassRule
94
97
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest ();
95
98
@@ -101,13 +104,13 @@ public class TcpOutboundGatewayTests {
101
104
public void testGoodNetSingle () throws Exception {
102
105
final CountDownLatch latch = new CountDownLatch (1 );
103
106
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 (() -> {
106
109
try {
107
110
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 , 100 );
108
111
serverSocket .set (server );
109
112
latch .countDown ();
110
- List <Socket > sockets = new ArrayList <Socket >();
113
+ List <Socket > sockets = new ArrayList <>();
111
114
int i = 0 ;
112
115
while (true ) {
113
116
Socket socket = server .accept ();
@@ -165,8 +168,8 @@ public void testGoodNetSingle() throws Exception {
165
168
public void testGoodNetMultiplex () throws Exception {
166
169
final CountDownLatch latch = new CountDownLatch (1 );
167
170
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 (() -> {
170
173
try {
171
174
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 , 10 );
172
175
serverSocket .set (server );
@@ -220,8 +223,8 @@ public void testGoodNetMultiplex() throws Exception {
220
223
public void testGoodNetTimeout () throws Exception {
221
224
final CountDownLatch latch = new CountDownLatch (1 );
222
225
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 (() -> {
225
228
try {
226
229
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
227
230
serverSocket .set (server );
@@ -260,12 +263,12 @@ public void testGoodNetTimeout() throws Exception {
260
263
Future <Integer >[] results = (Future <Integer >[]) new Future <?>[2 ];
261
264
for (int i = 0 ; i < 2 ; i ++) {
262
265
final int j = i ;
263
- results [j ] = (Executors . newSingleThreadExecutor () .submit (() -> {
266
+ results [j ] = (this . executor .submit (() -> {
264
267
gateway .handleMessage (MessageBuilder .withPayload ("Test" + j ).build ());
265
268
return 0 ;
266
269
}));
267
270
}
268
- Set <String > replies = new HashSet <String >();
271
+ Set <String > replies = new HashSet <>();
269
272
int timeouts = 0 ;
270
273
for (int i = 0 ; i < 2 ; i ++) {
271
274
try {
@@ -344,7 +347,7 @@ private void testGoodNetGWTimeoutGuts(final int port, AbstractClientConnectionFa
344
347
final AtomicReference <String > lastReceived = new AtomicReference <String >();
345
348
final CountDownLatch serverLatch = new CountDownLatch (2 );
346
349
347
- Executors . newSingleThreadExecutor () .execute (() -> {
350
+ this . executor .execute (() -> {
348
351
try {
349
352
latch .countDown ();
350
353
int i = 0 ;
@@ -398,7 +401,7 @@ private void testGoodNetGWTimeoutGuts(final int port, AbstractClientConnectionFa
398
401
399
402
for (int i = 0 ; i < 2 ; i ++) {
400
403
final int j = i ;
401
- results [j ] = (Executors . newSingleThreadExecutor () .submit (() -> {
404
+ results [j ] = (this . executor .submit (() -> {
402
405
gateway .handleMessage (MessageBuilder .withPayload ("Test" + j ).build ());
403
406
return j ;
404
407
}));
@@ -442,7 +445,7 @@ public void testCachingFailover() throws Exception {
442
445
final AtomicBoolean done = new AtomicBoolean ();
443
446
final CountDownLatch serverLatch = new CountDownLatch (1 );
444
447
445
- Executors . newSingleThreadExecutor () .execute (() -> {
448
+ this . executor .execute (() -> {
446
449
try {
447
450
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
448
451
serverSocket .set (server );
@@ -517,12 +520,12 @@ public void testCachingFailover() throws Exception {
517
520
518
521
@ Test
519
522
public void testFailoverCached () throws Exception {
520
- final AtomicReference <ServerSocket > serverSocket = new AtomicReference <ServerSocket >();
523
+ final AtomicReference <ServerSocket > serverSocket = new AtomicReference <>();
521
524
final CountDownLatch latch = new CountDownLatch (1 );
522
525
final AtomicBoolean done = new AtomicBoolean ();
523
526
final CountDownLatch serverLatch = new CountDownLatch (1 );
524
527
525
- Executors . newSingleThreadExecutor () .execute (() -> {
528
+ this . executor .execute (() -> {
526
529
try {
527
530
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
528
531
serverSocket .set (server );
@@ -667,11 +670,11 @@ private void testGWPropagatesSocketCloseGuts(final int port, AbstractClientConne
667
670
final ServerSocket server ) throws Exception {
668
671
final CountDownLatch latch = new CountDownLatch (1 );
669
672
final AtomicBoolean done = new AtomicBoolean ();
670
- final AtomicReference <String > lastReceived = new AtomicReference <String >();
673
+ final AtomicReference <String > lastReceived = new AtomicReference <>();
671
674
final CountDownLatch serverLatch = new CountDownLatch (1 );
672
675
673
- Executors . newSingleThreadExecutor () .execute (() -> {
674
- List <Socket > sockets = new ArrayList <Socket >();
676
+ this . executor .execute (() -> {
677
+ List <Socket > sockets = new ArrayList <>();
675
678
try {
676
679
latch .countDown ();
677
680
while (!done .get ()) {
@@ -793,8 +796,8 @@ private void testGWPropagatesSocketTimeoutGuts(final int port, AbstractClientCon
793
796
final CountDownLatch latch = new CountDownLatch (1 );
794
797
final AtomicBoolean done = new AtomicBoolean ();
795
798
796
- Executors . newSingleThreadExecutor () .execute (() -> {
797
- List <Socket > sockets = new ArrayList <Socket >();
799
+ this . executor .execute (() -> {
800
+ List <Socket > sockets = new ArrayList <>();
798
801
try {
799
802
latch .countDown ();
800
803
while (!done .get ()) {
0 commit comments