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