Fix compatibility with the latest SF
* Upgrade Spring dependencies to the latest SNAPSHOTs * Fix tests to verify against stack traces: the message of the `NestedRuntimeException` does not include the nested exception information. Related to https://github.com/spring-projects/spring-framework/issues/25162 * Fix `JdbcMessageStore` and `DefaultLockRepository` to rely on the `DataIntegrityViolationException` instead of only its `DuplicateKeyException` extension. This is the current behavior of the SQL errors translation * Disable `WebFluxDslTests.testValidation()` - doesn't subscribe to the reply somehow... * Refine `SimplePool.PoolSemaphore.reducePermits()`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.ip.tcp.connection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -40,6 +41,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
@@ -98,19 +100,20 @@ public class ConnectionEventTests {
|
||||
doThrow(toBeThrown).when(serializer).serialize(Mockito.any(Object.class), Mockito.any(OutputStream.class));
|
||||
conn.setMapper(new TcpMessageMapper());
|
||||
conn.setSerializer(serializer);
|
||||
try {
|
||||
conn.send(new GenericMessage<>("bar"));
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
.isThrownBy(() -> conn.send(new GenericMessage<>("bar")));
|
||||
|
||||
assertThat(theEvent.size() > 0).isTrue();
|
||||
assertThat(theEvent.get(0)).isNotNull();
|
||||
assertThat(theEvent.get(0) instanceof TcpConnectionExceptionEvent).isTrue();
|
||||
assertThat(theEvent.get(0)).isInstanceOf(TcpConnectionExceptionEvent.class);
|
||||
assertThat(theEvent.get(0).toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "]"))
|
||||
.isTrue();
|
||||
assertThat(theEvent.get(0).toString())
|
||||
.contains("RuntimeException: foo, failedMessage=GenericMessage [payload=bar");
|
||||
assertThat(theEvent.get(0))
|
||||
.extracting("cause")
|
||||
.asInstanceOf(InstanceOfAssertFactories.THROWABLE)
|
||||
.hasStackTraceContaining("RuntimeException: foo")
|
||||
.hasStackTraceContaining("failedMessage=GenericMessage [payload=bar");
|
||||
TcpConnectionExceptionEvent event = (TcpConnectionExceptionEvent) theEvent.get(0);
|
||||
assertThat(event.getCause()).isNotNull();
|
||||
assertThat(event.getCause().getCause()).isSameAs(toBeThrown);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -355,7 +355,7 @@ public class ConnectionFactoryTests {
|
||||
if (fail) {
|
||||
assertThatExceptionOfType(MessagingException.class).isThrownBy(() ->
|
||||
gateway.handleMessage(new GenericMessage<>("test1")))
|
||||
.withMessageContaining("Connection test failed for");
|
||||
.withStackTraceContaining("Connection test failed for");
|
||||
}
|
||||
else {
|
||||
gateway.handleMessage(new GenericMessage<>("test1"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -112,9 +112,9 @@ public class SocketSupportTests {
|
||||
connectionFactory.setTcpSocketFactorySupport(factorySupport);
|
||||
connectionFactory.setTcpSocketSupport(socketSupport);
|
||||
connectionFactory.start();
|
||||
assertThatThrownBy(() -> connectionFactory.getConnection())
|
||||
.isInstanceOf(UncheckedIOException.class)
|
||||
.hasCauseInstanceOf(SocketTimeoutException.class);
|
||||
assertThatThrownBy(connectionFactory::getConnection)
|
||||
.isInstanceOf(UncheckedIOException.class)
|
||||
.hasCauseInstanceOf(SocketTimeoutException.class);
|
||||
|
||||
connectionFactory.stop();
|
||||
}
|
||||
@@ -211,7 +211,7 @@ public class SocketSupportTests {
|
||||
};
|
||||
clientConnectionFactory.setTcpSocketSupport(clientSocketSupport);
|
||||
clientConnectionFactory.start();
|
||||
clientConnectionFactory.getConnection().send(new GenericMessage<String>("Hello, world!"));
|
||||
clientConnectionFactory.getConnection().send(new GenericMessage<>("Hello, world!"));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(ppServerSocketCountClient.get()).isEqualTo(0);
|
||||
assertThat(ppSocketCountClient.get()).isEqualTo(1);
|
||||
@@ -383,7 +383,7 @@ public class SocketSupportTests {
|
||||
DefaultTcpNetSSLSocketFactorySupport tcpSocketFactorySupport =
|
||||
new DefaultTcpNetSSLSocketFactorySupport(sslContextSupport);
|
||||
server.setTcpSocketFactorySupport(tcpSocketFactorySupport);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
final List<Message<?>> messages = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
server.registerListener(message -> {
|
||||
messages.add(message);
|
||||
@@ -400,7 +400,7 @@ public class SocketSupportTests {
|
||||
client.start();
|
||||
|
||||
TcpConnection connection = client.getConnection();
|
||||
connection.send(new GenericMessage<String>("Hello, world!"));
|
||||
connection.send(new GenericMessage<>("Hello, world!"));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
|
||||
assertThat(messages.get(0).getHeaders().get("cipher")).isNotNull();
|
||||
@@ -413,7 +413,7 @@ public class SocketSupportTests {
|
||||
public void testNetClientAndServerSSLDifferentContexts() throws Exception {
|
||||
testNetClientAndServerSSLDifferentContexts(false);
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> testNetClientAndServerSSLDifferentContexts(true));
|
||||
.isThrownBy(() -> testNetClientAndServerSSLDifferentContexts(true));
|
||||
}
|
||||
|
||||
private void testNetClientAndServerSSLDifferentContexts(boolean badServer) throws Exception {
|
||||
@@ -425,7 +425,7 @@ public class SocketSupportTests {
|
||||
DefaultTcpNetSSLSocketFactorySupport serverTcpSocketFactorySupport =
|
||||
new DefaultTcpNetSSLSocketFactorySupport(serverSslContextSupport);
|
||||
server.setTcpSocketFactorySupport(serverTcpSocketFactorySupport);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
final List<Message<?>> messages = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
server.registerListener(message -> {
|
||||
if (!(message instanceof ErrorMessage)) {
|
||||
@@ -456,7 +456,7 @@ public class SocketSupportTests {
|
||||
try {
|
||||
client.start();
|
||||
TcpConnection connection = client.getConnection();
|
||||
connection.send(new GenericMessage<String>("Hello, world!"));
|
||||
connection.send(new GenericMessage<>("Hello, world!"));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
|
||||
}
|
||||
@@ -477,7 +477,7 @@ public class SocketSupportTests {
|
||||
DefaultTcpNioSSLConnectionSupport tcpNioConnectionSupport =
|
||||
new DefaultTcpNioSSLConnectionSupport(sslContextSupport, false);
|
||||
server.setTcpNioConnectionSupport(tcpNioConnectionSupport);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
final List<Message<?>> messages = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
server.registerListener(message -> {
|
||||
messages.add(message);
|
||||
@@ -504,7 +504,7 @@ public class SocketSupportTests {
|
||||
|
||||
TcpConnection connection = client.getConnection();
|
||||
assertThat(TestUtils.getPropertyValue(connection, "handshakeTimeout")).isEqualTo(34);
|
||||
connection.send(new GenericMessage<String>("Hello, world!"));
|
||||
connection.send(new GenericMessage<>("Hello, world!"));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
|
||||
assertThat(messages.get(0).getHeaders().get("cipher")).isNotNull();
|
||||
@@ -522,8 +522,8 @@ public class SocketSupportTests {
|
||||
public void testNioClientAndServerSSLDifferentContexts() throws Exception {
|
||||
testNioClientAndServerSSLDifferentContexts(false);
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> testNioClientAndServerSSLDifferentContexts(true))
|
||||
.withMessageMatching(".*javax.net.ssl.SSLHandshakeException.*");
|
||||
.isThrownBy(() -> testNioClientAndServerSSLDifferentContexts(true))
|
||||
.withStackTraceContaining("javax.net.ssl.SSLHandshakeException");
|
||||
}
|
||||
|
||||
private void testNioClientAndServerSSLDifferentContexts(boolean badServer) throws Exception {
|
||||
@@ -542,7 +542,7 @@ public class SocketSupportTests {
|
||||
|
||||
};
|
||||
server.setTcpNioConnectionSupport(tcpNioConnectionSupport);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
final List<Message<?>> messages = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
server.registerListener(message -> {
|
||||
messages.add(message);
|
||||
@@ -562,7 +562,7 @@ public class SocketSupportTests {
|
||||
try {
|
||||
client.start();
|
||||
TcpConnection connection = client.getConnection();
|
||||
connection.send(new GenericMessage<String>("Hello, world!"));
|
||||
connection.send(new GenericMessage<>("Hello, world!"));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(new String((byte[]) messages.get(0).getPayload())).isEqualTo("Hello, world!");
|
||||
}
|
||||
@@ -581,7 +581,7 @@ public class SocketSupportTests {
|
||||
DefaultTcpNioSSLConnectionSupport serverTcpNioConnectionSupport =
|
||||
new DefaultTcpNioSSLConnectionSupport(serverSslContextSupport, false);
|
||||
server.setTcpNioConnectionSupport(serverTcpNioConnectionSupport);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
final List<Message<?>> messages = new ArrayList<>();
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
final Replier replier = new Replier();
|
||||
server.registerSender(replier);
|
||||
@@ -627,7 +627,7 @@ public class SocketSupportTests {
|
||||
TcpConnection connection = client.getConnection();
|
||||
assertThat(TestUtils.getPropertyValue(connection, "handshakeTimeout")).isEqualTo(30);
|
||||
byte[] bytes = new byte[100000];
|
||||
connection.send(new GenericMessage<String>("Hello, world!" + new String(bytes)));
|
||||
connection.send(new GenericMessage<>("Hello, world!" + new String(bytes)));
|
||||
assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
|
||||
byte[] payload = (byte[]) messages.get(0).getPayload();
|
||||
assertThat(payload.length).isEqualTo(13 + bytes.length);
|
||||
|
||||
Reference in New Issue
Block a user