29
29
30
30
import javax .net .ServerSocketFactory ;
31
31
32
- import org .junit .Rule ;
33
- import org .junit .Test ;
32
+ import org .junit .jupiter .api .Test ;
34
33
35
34
import org .springframework .beans .factory .BeanFactory ;
36
35
import org .springframework .context .ApplicationEvent ;
45
44
import org .springframework .integration .ip .util .SocketTestUtils ;
46
45
import org .springframework .integration .ip .util .TestingUtilities ;
47
46
import org .springframework .integration .support .MessageBuilder ;
48
- import org .springframework .integration .test .support .LongRunningIntegrationTest ;
49
47
import org .springframework .messaging .Message ;
50
48
import org .springframework .messaging .MessageChannel ;
51
49
import org .springframework .messaging .support .GenericMessage ;
52
50
53
51
import static org .assertj .core .api .Assertions .assertThat ;
52
+ import static org .assertj .core .api .Assertions .assertThatIOException ;
54
53
import static org .assertj .core .api .Assertions .fail ;
55
54
import static org .mockito .Mockito .mock ;
56
55
62
61
*/
63
62
public class DeserializationTests {
64
63
65
- @ Rule
66
- public LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest ();
67
-
68
64
@ Test
69
65
public void testReadLength () throws Exception {
70
66
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
@@ -245,18 +241,11 @@ public void testReadCrLfTimeout() throws Exception {
245
241
server .setSoTimeout (10000 );
246
242
CountDownLatch latch = SocketTestUtils .testSendCrLfOverflow (port );
247
243
Socket socket = server .accept ();
248
- socket .setSoTimeout (500 );
244
+ socket .setSoTimeout (100 );
249
245
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
250
- try {
251
- serializer .deserialize (socket .getInputStream ());
252
- fail ("Expected timout exception" );
253
- }
254
- catch (IOException e ) {
255
- if (!e .getMessage ().startsWith ("Read timed out" )) {
256
- e .printStackTrace ();
257
- fail ("Unexpected IO Error:" + e .getMessage ());
258
- }
259
- }
246
+ assertThatIOException ()
247
+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
248
+ .withMessageStartingWith ("Read timed out" );
260
249
server .close ();
261
250
latch .countDown ();
262
251
}
@@ -270,17 +259,10 @@ public void testReadCrLfOverflow() throws Exception {
270
259
Socket socket = server .accept ();
271
260
socket .setSoTimeout (5000 );
272
261
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
273
- serializer .setMaxMessageSize (1024 );
274
- try {
275
- serializer .deserialize (socket .getInputStream ());
276
- fail ("Expected message length exceeded exception" );
277
- }
278
- catch (IOException e ) {
279
- if (!e .getMessage ().startsWith ("CRLF not found" )) {
280
- e .printStackTrace ();
281
- fail ("Unexpected IO Error:" + e .getMessage ());
282
- }
283
- }
262
+ serializer .setMaxMessageSize (16 );
263
+ assertThatIOException ()
264
+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
265
+ .withMessageStartingWith ("CRLF not found" );
284
266
server .close ();
285
267
latch .countDown ();
286
268
}
@@ -317,7 +299,8 @@ public void deserializationEvents() throws Exception {
317
299
assertThat (new String (event .getBuffer ()).substring (0 , 1 )).isEqualTo (new String (new byte [] {7 }));
318
300
doDeserialize (new ByteArrayLfSerializer (), "Terminator '0xa' not found before max message length: 5" );
319
301
doDeserialize (new ByteArrayRawSerializer (), "Socket was not closed before max message length: 5" );
320
- doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ), "Terminator '0xfe' not found before max message length: 5" );
302
+ doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ),
303
+ "Terminator '0xfe' not found before max message length: 5" );
321
304
doDeserialize (new ByteArrayStxEtxSerializer (), "Expected STX to begin message" );
322
305
event = doDeserialize (new ByteArrayStxEtxSerializer (),
323
306
"Socket closed during message assembly" , new byte [] {0x02 , 0 , 0 }, 5 );
@@ -389,7 +372,7 @@ public void testTimeoutWhileDecoding(AbstractByteArraySerializer deserializer, S
389
372
TcpNioClientConnectionFactory clientNio = new TcpNioClientConnectionFactory ("localhost" , serverNio .getPort ());
390
373
clientNio .setSerializer (serializer );
391
374
clientNio .setDeserializer (deserializer );
392
- clientNio .setSoTimeout (1000 );
375
+ clientNio .setSoTimeout (500 );
393
376
clientNio .afterPropertiesSet ();
394
377
final TcpOutboundGateway out = new TcpOutboundGateway ();
395
378
out .setConnectionFactory (clientNio );
0 commit comments