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:
Artem Bilan
2022-06-27 20:26:13 -04:00
parent 979b8417ef
commit 2022c40d55
39 changed files with 278 additions and 354 deletions

View File

@@ -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.
@@ -17,7 +17,7 @@
package org.springframework.integration.aggregator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
@@ -200,13 +200,9 @@ public class ResequencerTests {
Message<?> message3 = createMessage("789", "ABC", 4, 1, replyChannel);
this.resequencer.handleMessage(message1);
this.resequencer.handleMessage(message2);
try {
this.resequencer.handleMessage(message3);
fail("Expected exception");
}
catch (MessagingException e) {
assertThat(e.getMessage()).contains("out of capacity (2) for group 'ABC'");
}
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> this.resequencer.handleMessage(message3))
.withStackTraceContaining("out of capacity (2) for group 'ABC'");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-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.
@@ -100,7 +100,7 @@ public class ReactiveStreamsConsumerTests {
assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() -> testChannel.send(testMessage))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("doesn't have subscribers to accept messages");
.withStackTraceContaining("doesn't have subscribers to accept messages");
reactiveConsumer.start();
@@ -279,7 +279,7 @@ public class ReactiveStreamsConsumerTests {
assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() -> testChannel.send(testMessage))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("doesn't have subscribers to accept messages");
.withStackTraceContaining("doesn't have subscribers to accept messages");
endpointFactoryBean.start();
@@ -321,7 +321,7 @@ public class ReactiveStreamsConsumerTests {
assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() -> testChannel.send(testMessage))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("doesn't have subscribers to accept messages");
.withStackTraceContaining("doesn't have subscribers to accept messages");
reactiveConsumer.start();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-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,15 +17,14 @@
package org.springframework.integration.channel.registry;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -49,8 +48,7 @@ import org.springframework.messaging.support.ErrorMessage;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
@@ -59,8 +57,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @since 3.0
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class HeaderChannelRegistryTests {
@@ -95,7 +92,7 @@ public class HeaderChannelRegistryTests {
public void testReplace() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.input);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("foo"));
Message<?> reply = template.sendAndReceive(new GenericMessage<>("foo"));
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:foo");
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
@@ -109,7 +106,7 @@ public class HeaderChannelRegistryTests {
public void testReplaceTtl() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputTtl);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
Message<?> reply = template.sendAndReceive(new GenericMessage<>("ttl"));
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:ttl");
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
@@ -135,7 +132,7 @@ public class HeaderChannelRegistryTests {
.get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis())
.isGreaterThan(160000L).isLessThan(181000L);
// Now for Elvis...
reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
reply = template.sendAndReceive(new GenericMessage<>("ttl"));
assertThat(reply).isNotNull();
assertThat(reply.getPayload()).isEqualTo("echo:ttl");
stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
@@ -167,7 +164,7 @@ public class HeaderChannelRegistryTests {
public void testReplaceError() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputPolled);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("bar"));
Message<?> reply = template.sendAndReceive(new GenericMessage<>("bar"));
assertThat(reply).isNotNull();
assertThat(reply instanceof ErrorMessage).isTrue();
assertThat(((ErrorMessage) reply).getOriginalMessage()).isNotNull();
@@ -188,15 +185,9 @@ public class HeaderChannelRegistryTests {
@Test
public void testNull() {
Message<String> requestMessage = MessageBuilder.withPayload("foo")
.build();
try {
this.input.send(requestMessage);
fail("expected exception");
}
catch (Exception e) {
assertThat(e.getMessage()).contains("no output-channel or replyChannel");
}
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> this.input.send(new GenericMessage<>("test")))
.withStackTraceContaining("no output-channel or replyChannel");
}
@Test
@@ -223,14 +214,10 @@ public class HeaderChannelRegistryTests {
throw new NoSuchBeanDefinitionException("bar");
}).when(beanFactory).getBean("foo", MessageChannel.class);
resolver.setBeanFactory(beanFactory);
try {
resolver.resolveDestination("foo");
fail("Expected exception");
}
catch (DestinationResolutionException e) {
assertThat(e.getMessage()).contains("failed to look up MessageChannel with name 'foo' in the BeanFactory" +
".");
}
assertThatExceptionOfType(DestinationResolutionException.class)
.isThrownBy(() -> resolver.resolveDestination("foo"))
.withMessageContaining("failed to look up MessageChannel with name 'foo' in the BeanFactory.");
}
@Test
@@ -241,15 +228,11 @@ public class HeaderChannelRegistryTests {
throw new NoSuchBeanDefinitionException("bar");
}).when(beanFactory).getBean("foo", MessageChannel.class);
resolver.setBeanFactory(beanFactory);
try {
resolver.resolveDestination("foo");
fail("Expected exception");
}
catch (DestinationResolutionException e) {
assertThat(e.getMessage()).contains("failed to look up MessageChannel with name 'foo' in the BeanFactory" +
" " +
"(and there is no HeaderChannelRegistry present).");
}
assertThatExceptionOfType(DestinationResolutionException.class)
.isThrownBy(() -> resolver.resolveDestination("foo"))
.withMessageContaining("failed to look up MessageChannel with name 'foo' in the BeanFactory" +
" (and there is no HeaderChannelRegistry present).");
}
@Test

View File

@@ -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,7 +17,7 @@
package org.springframework.integration.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.time.Duration;
import java.util.ArrayList;
@@ -217,24 +217,17 @@ public class AggregatorParserTests {
@Test
public void testMissingMethodOnAggregator() {
try {
new ClassPathXmlApplicationContext("invalidMethodNameAggregator.xml", this.getClass()).close();
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage()).contains("Adder] has no eligible methods");
}
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("invalidMethodNameAggregator.xml", getClass()))
.withStackTraceContaining("Adder] has no eligible methods");
}
@Test
public void testMissingReleaseStrategyDefinition() {
try {
new ClassPathXmlApplicationContext("ReleaseStrategyMethodWithMissingReference.xml", this.getClass()).close();
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage()).contains("No bean named 'testReleaseStrategy' available");
}
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("ReleaseStrategyMethodWithMissingReference.xml",
getClass()))
.withStackTraceContaining("No bean named 'testReleaseStrategy' available");
}
@Test
@@ -289,13 +282,9 @@ public class AggregatorParserTests {
@Test
public void testAggregatorWithInvalidReleaseStrategyMethod() {
try {
new ClassPathXmlApplicationContext("invalidReleaseStrategyMethod.xml", this.getClass()).close();
fail("Expected exception");
}
catch (BeanCreationException e) {
assertThat(e.getMessage()).contains("TestReleaseStrategy] has no eligible methods");
}
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("invalidReleaseStrategyMethod.xml", getClass()))
.withStackTraceContaining("TestReleaseStrategy] has no eligible methods");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@@ -16,9 +16,9 @@
package org.springframework.integration.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -26,18 +26,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Marius Bogoevici
* @author Gary Russell
* @author Artem Bilan
*/
public class CorrelationStrategyInvalidConfigurationTests {
@Test
public void testCorrelationStrategyWithVoidReturningMethods() throws Exception {
try {
new ClassPathXmlApplicationContext("correlationStrategyWithVoidMethods.xml",
CorrelationStrategyInvalidConfigurationTests.class).close();
}
catch (BeanCreationException e) {
assertThat(e.getMessage()).contains("MessageCountReleaseStrategy] has no eligible methods");
}
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("correlationStrategyWithVoidMethods.xml",
getClass()))
.withStackTraceContaining("MessageCountReleaseStrategy] has no eligible methods");
}
public static class VoidReturningCorrelationStrategy {

View File

@@ -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.
@@ -113,8 +113,8 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
.isThrownBy(() -> this.gatewayTestInputChannel.send(message2))
.withCauseInstanceOf(MessageHandlingException.class)
.withRootCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("Expression evaluation failed")
.withMessageContaining("Wrong payload");
.withStackTraceContaining("Expression evaluation failed")
.withStackTraceContaining("Wrong payload");
}
@Test
@@ -199,7 +199,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() ->
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-fail-context.xml", getClass()))
.withMessageContaining("An AbstractMessageProducingMessageHandler may only be referenced once")
.withStackTraceContaining("An AbstractMessageProducingMessageHandler may only be referenced once")
.withRootCauseExactlyInstanceOf(IllegalArgumentException.class);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-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,7 +17,7 @@
package org.springframework.integration.routingslip;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.Arrays;
import java.util.Collections;
@@ -27,8 +27,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -52,7 +51,7 @@ import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.support.GenericXmlContextLoader;
import reactor.core.publisher.Flux;
@@ -60,10 +59,11 @@ import reactor.core.publisher.Flux;
/**
* @author Artem Bilan
*
* @since 4.1
*/
@ContextConfiguration(loader = GenericXmlContextLoader.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class RoutingSlipTests {
@@ -119,24 +119,15 @@ public class RoutingSlipTests {
@Test
public void testInvalidRoutingSlipRoutStrategy() {
try {
new RoutingSlipHeaderValueMessageProcessor(new Date());
fail("IllegalArgumentException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getMessage()).contains("The RoutingSlip can contain " +
"only bean names of MessageChannel or RoutingSlipRouteStrategy, " +
"or MessageChannel and RoutingSlipRouteStrategy instances");
}
try {
this.invalidRoutingSlipChannel.send(new GenericMessage<>("foo"));
fail("MessagingException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(MessagingException.class);
assertThat(e.getMessage()).contains("replyChannel must be a MessageChannel or String");
}
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new RoutingSlipHeaderValueMessageProcessor(new Date()))
.withMessageContaining("The RoutingSlip can contain " +
"only bean names of MessageChannel or RoutingSlipRouteStrategy, " +
"or MessageChannel and RoutingSlipRouteStrategy instances");
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> this.invalidRoutingSlipChannel.send(new GenericMessage<>("foo")))
.withStackTraceContaining("replyChannel must be a MessageChannel or String");
}
public static class TestRoutingSlipRoutePojo {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@@ -136,7 +136,7 @@ public class SplitterIntegrationTests {
new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidRef.xml",
SplitterIntegrationTests.class))
.withRootCauseExactlyInstanceOf(IllegalArgumentException.class)
.withMessageContaining("'delimiters' property is only available");
.withStackTraceContaining("'delimiters' property is only available");
}
@Test
@@ -146,7 +146,7 @@ public class SplitterIntegrationTests {
new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidInnerBean.xml",
SplitterIntegrationTests.class))
.withRootCauseExactlyInstanceOf(IllegalArgumentException.class)
.withMessageContaining("'delimiters' property is only available");
.withStackTraceContaining("'delimiters' property is only available");
}
@Test
@@ -156,7 +156,7 @@ public class SplitterIntegrationTests {
new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidExpression.xml",
SplitterIntegrationTests.class))
.withRootCauseExactlyInstanceOf(IllegalArgumentException.class)
.withMessageContaining("'delimiters' property is only available");
.withStackTraceContaining("'delimiters' property is only available");
}
@Test