|
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);
|
@@ -488,7 +494,7 @@ void testCachingFailover() throws Exception {
|
488 | 494 | TcpConnectionSupport mockConn1 = makeMockConnection();
|
489 | 495 | when(factory1.getConnection()).thenReturn(mockConn1);
|
490 | 496 | doThrow(new UncheckedIOException(new IOException("fail")))
|
491 |
| - .when(mockConn1).send(Mockito.any(Message.class)); |
| 497 | + .when(mockConn1).send(any(Message.class)); |
492 | 498 |
|
493 | 499 | AbstractClientConnectionFactory factory2 = new TcpNetClientConnectionFactory("localhost",
|
494 | 500 | serverSocket.get().getLocalPort());
|
@@ -521,7 +527,7 @@ void testCachingFailover() throws Exception {
|
521 | 527 | assertThat(reply.getPayload()).isEqualTo("bar");
|
522 | 528 | done.set(true);
|
523 | 529 | gateway.stop();
|
524 |
| - verify(mockConn1).send(Mockito.any(Message.class)); |
| 530 | + verify(mockConn1).send(any(Message.class)); |
525 | 531 | factory2.stop();
|
526 | 532 | serverSocket.get().close();
|
527 | 533 | }
|
@@ -571,7 +577,7 @@ void testFailoverCached() throws Exception {
|
571 | 577 | when(factory1.getConnection()).thenReturn(mockConn1);
|
572 | 578 | when(factory1.isSingleUse()).thenReturn(true);
|
573 | 579 | doThrow(new UncheckedIOException(new IOException("fail")))
|
574 |
| - .when(mockConn1).send(Mockito.any(Message.class)); |
| 580 | + .when(mockConn1).send(any(Message.class)); |
575 | 581 | CachingClientConnectionFactory cachingFactory1 = new CachingClientConnectionFactory(factory1, 1);
|
576 | 582 |
|
577 | 583 | AbstractClientConnectionFactory factory2 = new TcpNetClientConnectionFactory("localhost",
|
@@ -606,7 +612,7 @@ void testFailoverCached() throws Exception {
|
606 | 612 | assertThat(reply.getPayload()).isEqualTo("bar");
|
607 | 613 | done.set(true);
|
608 | 614 | gateway.stop();
|
609 |
| - verify(mockConn1).send(Mockito.any(Message.class)); |
| 615 | + verify(mockConn1).send(any(Message.class)); |
610 | 616 | factory2.stop();
|
611 | 617 | serverSocket.get().close();
|
612 | 618 | }
|
@@ -1081,4 +1087,37 @@ void testAsyncTimeout() throws Exception {
|
1081 | 1087 | }
|
1082 | 1088 | }
|
1083 | 1089 |
|
| 1090 | + @Test |
| 1091 | + void semaphoreIsReleasedOnAsyncSendFailure() throws InterruptedException { |
| 1092 | + AbstractClientConnectionFactory ccf = mock(AbstractClientConnectionFactory.class); |
| 1093 | + |
| 1094 | + TcpConnection connection = mock(TcpConnectionSupport.class); |
| 1095 | + |
| 1096 | + given(connection.getConnectionId()).willReturn("testId"); |
| 1097 | + willThrow(new RuntimeException("intentional")) |
| 1098 | + .given(connection) |
| 1099 | + .send(any(Message.class)); |
| 1100 | + |
| 1101 | + willReturn(connection) |
| 1102 | + .given(ccf) |
| 1103 | + .getConnection(); |
| 1104 | + |
| 1105 | + TcpOutboundGateway gateway = new TcpOutboundGateway(); |
| 1106 | + gateway.setConnectionFactory(ccf); |
| 1107 | + gateway.setAsync(true); |
| 1108 | + gateway.setBeanFactory(mock(BeanFactory.class)); |
| 1109 | + gateway.setRemoteTimeout(-1); |
| 1110 | + gateway.afterPropertiesSet(); |
| 1111 | + |
| 1112 | + assertThatExceptionOfType(MessageHandlingException.class) |
| 1113 | + .isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("Test1"))) |
| 1114 | + .withCauseExactlyInstanceOf(RuntimeException.class) |
| 1115 | + .withStackTraceContaining("intentional"); |
| 1116 | + |
| 1117 | + assertThatExceptionOfType(MessageHandlingException.class) |
| 1118 | + .isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("Test2"))) |
| 1119 | + .withCauseExactlyInstanceOf(RuntimeException.class) |
| 1120 | + .withStackTraceContaining("intentional"); |
| 1121 | + } |
| 1122 | + |
1084 | 1123 | }
|
0 commit comments