28
28
29
29
import javax .net .ServerSocketFactory ;
30
30
31
- import org .junit .Rule ;
32
- import org .junit .Test ;
31
+ import org .junit .jupiter .api .Test ;
33
32
34
33
import org .springframework .beans .factory .BeanFactory ;
35
34
import org .springframework .core .serializer .DefaultDeserializer ;
42
41
import org .springframework .integration .ip .util .SocketTestUtils ;
43
42
import org .springframework .integration .ip .util .TestingUtilities ;
44
43
import org .springframework .integration .support .MessageBuilder ;
45
- import org .springframework .integration .test .support .LongRunningIntegrationTest ;
46
44
import org .springframework .messaging .Message ;
47
45
import org .springframework .messaging .MessageChannel ;
48
46
import org .springframework .messaging .support .GenericMessage ;
49
47
50
48
import static org .assertj .core .api .Assertions .assertThat ;
49
+ import static org .assertj .core .api .Assertions .assertThatIOException ;
51
50
import static org .assertj .core .api .Assertions .fail ;
52
51
import static org .mockito .Mockito .mock ;
53
52
60
59
*/
61
60
public class DeserializationTests {
62
61
63
- @ Rule
64
- public LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest ();
65
-
66
62
@ Test
67
63
public void testReadLength () throws Exception {
68
64
ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
@@ -240,17 +236,11 @@ public void testReadCrLfTimeout() throws Exception {
240
236
server .setSoTimeout (10000 );
241
237
CountDownLatch latch = SocketTestUtils .testSendCrLfOverflow (port );
242
238
Socket socket = server .accept ();
243
- socket .setSoTimeout (500 );
239
+ socket .setSoTimeout (100 );
244
240
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
245
- try {
246
- serializer .deserialize (socket .getInputStream ());
247
- fail ("Expected timout exception" );
248
- }
249
- catch (IOException e ) {
250
- if (!e .getMessage ().startsWith ("Read timed out" )) {
251
- fail ("Unexpected IO Error:" + e .getMessage ());
252
- }
253
- }
241
+ assertThatIOException ()
242
+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
243
+ .withMessageStartingWith ("Read timed out" );
254
244
server .close ();
255
245
latch .countDown ();
256
246
}
@@ -264,16 +254,10 @@ public void testReadCrLfOverflow() throws Exception {
264
254
Socket socket = server .accept ();
265
255
socket .setSoTimeout (5000 );
266
256
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
267
- serializer .setMaxMessageSize (1024 );
268
- try {
269
- serializer .deserialize (socket .getInputStream ());
270
- fail ("Expected message length exceeded exception" );
271
- }
272
- catch (IOException e ) {
273
- if (!e .getMessage ().startsWith ("CRLF not found" )) {
274
- fail ("Unexpected IO Error:" + e .getMessage ());
275
- }
276
- }
257
+ serializer .setMaxMessageSize (16 );
258
+ assertThatIOException ()
259
+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
260
+ .withMessageStartingWith ("CRLF not found" );
277
261
server .close ();
278
262
latch .countDown ();
279
263
}
@@ -306,7 +290,8 @@ public void deserializationEvents() {
306
290
assertThat (new String (event .getBuffer ()).substring (0 , 1 )).isEqualTo (new String (new byte [] {7 }));
307
291
doDeserialize (new ByteArrayLfSerializer (), "Terminator '0xa' not found before max message length: 5" );
308
292
doDeserialize (new ByteArrayRawSerializer (), "Socket was not closed before max message length: 5" );
309
- doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ), "Terminator '0xfe' not found before max message length: 5" );
293
+ doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ),
294
+ "Terminator '0xfe' not found before max message length: 5" );
310
295
doDeserialize (new ByteArrayStxEtxSerializer (), "Expected STX to begin message" );
311
296
event = doDeserialize (new ByteArrayStxEtxSerializer (),
312
297
"Socket closed during message assembly" , new byte [] {0x02 , 0 , 0 }, 5 );
@@ -365,7 +350,7 @@ private void testTimeoutWhileDecoding(AbstractByteArraySerializer deserializer,
365
350
TcpNioClientConnectionFactory clientNio = new TcpNioClientConnectionFactory ("localhost" , serverNio .getPort ());
366
351
clientNio .setSerializer (serializer );
367
352
clientNio .setDeserializer (deserializer );
368
- clientNio .setSoTimeout (1000 );
353
+ clientNio .setSoTimeout (500 );
369
354
clientNio .afterPropertiesSet ();
370
355
final TcpOutboundGateway out = new TcpOutboundGateway ();
371
356
out .setConnectionFactory (clientNio );
0 commit comments