|
61 | 61 | import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
62 | 62 | import org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactory;
|
63 | 63 | import org.springframework.integration.ip.tcp.connection.FailoverClientConnectionFactory;
|
| 64 | +import org.springframework.integration.ip.tcp.connection.TcpConnection; |
64 | 65 | import org.springframework.integration.ip.tcp.connection.TcpConnectionSupport;
|
65 | 66 | import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
|
66 | 67 | import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
|
|
80 | 81 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
81 | 82 |
|
82 | 83 | import static org.assertj.core.api.Assertions.assertThat;
|
| 84 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
83 | 85 | import static org.assertj.core.api.Assertions.catchThrowable;
|
84 | 86 | import static org.assertj.core.api.Assertions.fail;
|
85 | 87 | import static org.awaitility.Awaitility.await;
|
| 88 | +import static org.mockito.ArgumentMatchers.any; |
| 89 | +import static org.mockito.BDDMockito.given; |
| 90 | +import static org.mockito.BDDMockito.willReturn; |
| 91 | +import static org.mockito.BDDMockito.willThrow; |
86 | 92 | import static org.mockito.Mockito.doThrow;
|
87 | 93 | import static org.mockito.Mockito.mock;
|
88 | 94 | import static org.mockito.Mockito.verify;
|
@@ -397,7 +403,7 @@ private void testGoodNetGWTimeoutGuts(AbstractClientConnectionFactory ccf,
|
397 | 403 |
|
398 | 404 | Expression remoteTimeoutExpression = Mockito.mock(Expression.class);
|
399 | 405 |
|
400 |
| - when(remoteTimeoutExpression.getValue(Mockito.any(EvaluationContext.class), Mockito.any(Message.class), |
| 406 | + when(remoteTimeoutExpression.getValue(any(EvaluationContext.class), any(Message.class), |
401 | 407 | Mockito.eq(Long.class))).thenReturn(50L, 60000L);
|
402 | 408 |
|
403 | 409 | gateway.setRemoteTimeoutExpression(remoteTimeoutExpression);
|
@@ -489,7 +495,7 @@ void testCachingFailover() throws Exception {
|
489 | 495 | TcpConnectionSupport mockConn1 = makeMockConnection();
|
490 | 496 | when(factory1.getConnection()).thenReturn(mockConn1);
|
491 | 497 | doThrow(new UncheckedIOException(new IOException("fail")))
|
492 |
| - .when(mockConn1).send(Mockito.any(Message.class)); |
| 498 | + .when(mockConn1).send(any(Message.class)); |
493 | 499 |
|
494 | 500 | AbstractClientConnectionFactory factory2 = new TcpNetClientConnectionFactory("localhost",
|
495 | 501 | serverSocket.get().getLocalPort());
|
@@ -522,7 +528,7 @@ void testCachingFailover() throws Exception {
|
522 | 528 | assertThat(reply.getPayload()).isEqualTo("bar");
|
523 | 529 | done.set(true);
|
524 | 530 | gateway.stop();
|
525 |
| - verify(mockConn1).send(Mockito.any(Message.class)); |
| 531 | + verify(mockConn1).send(any(Message.class)); |
526 | 532 | factory2.stop();
|
527 | 533 | serverSocket.get().close();
|
528 | 534 | }
|
@@ -572,7 +578,7 @@ void testFailoverCached() throws Exception {
|
572 | 578 | when(factory1.getConnection()).thenReturn(mockConn1);
|
573 | 579 | when(factory1.isSingleUse()).thenReturn(true);
|
574 | 580 | doThrow(new UncheckedIOException(new IOException("fail")))
|
575 |
| - .when(mockConn1).send(Mockito.any(Message.class)); |
| 581 | + .when(mockConn1).send(any(Message.class)); |
576 | 582 | CachingClientConnectionFactory cachingFactory1 = new CachingClientConnectionFactory(factory1, 1);
|
577 | 583 |
|
578 | 584 | AbstractClientConnectionFactory factory2 = new TcpNetClientConnectionFactory("localhost",
|
@@ -607,7 +613,7 @@ void testFailoverCached() throws Exception {
|
607 | 613 | assertThat(reply.getPayload()).isEqualTo("bar");
|
608 | 614 | done.set(true);
|
609 | 615 | gateway.stop();
|
610 |
| - verify(mockConn1).send(Mockito.any(Message.class)); |
| 616 | + verify(mockConn1).send(any(Message.class)); |
611 | 617 | factory2.stop();
|
612 | 618 | serverSocket.get().close();
|
613 | 619 | }
|
@@ -1080,4 +1086,37 @@ void testAsyncTimeout() throws Exception {
|
1080 | 1086 | }
|
1081 | 1087 | }
|
1082 | 1088 |
|
| 1089 | + @Test |
| 1090 | + void semaphoreIsReleasedOnAsyncSendFailure() throws InterruptedException { |
| 1091 | + AbstractClientConnectionFactory ccf = mock(AbstractClientConnectionFactory.class); |
| 1092 | + |
| 1093 | + TcpConnection connection = mock(TcpConnectionSupport.class); |
| 1094 | + |
| 1095 | + given(connection.getConnectionId()).willReturn("testId"); |
| 1096 | + willThrow(new RuntimeException("intentional")) |
| 1097 | + .given(connection) |
| 1098 | + .send(any(Message.class)); |
| 1099 | + |
| 1100 | + willReturn(connection) |
| 1101 | + .given(ccf) |
| 1102 | + .getConnection(); |
| 1103 | + |
| 1104 | + TcpOutboundGateway gateway = new TcpOutboundGateway(); |
| 1105 | + gateway.setConnectionFactory(ccf); |
| 1106 | + gateway.setAsync(true); |
| 1107 | + gateway.setBeanFactory(mock(BeanFactory.class)); |
| 1108 | + gateway.setRemoteTimeout(-1); |
| 1109 | + gateway.afterPropertiesSet(); |
| 1110 | + |
| 1111 | + assertThatExceptionOfType(MessageHandlingException.class) |
| 1112 | + .isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("Test1"))) |
| 1113 | + .withCauseExactlyInstanceOf(RuntimeException.class) |
| 1114 | + .withStackTraceContaining("intentional"); |
| 1115 | + |
| 1116 | + assertThatExceptionOfType(MessageHandlingException.class) |
| 1117 | + .isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("Test2"))) |
| 1118 | + .withCauseExactlyInstanceOf(RuntimeException.class) |
| 1119 | + .withStackTraceContaining("intentional"); |
| 1120 | + } |
| 1121 | + |
1083 | 1122 | }
|
0 commit comments