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 2015-2020 the original author or authors.
* Copyright 2015-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,8 @@
package org.springframework.integration.file.remote;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -97,13 +96,9 @@ public class RemoteFileTemplateTests {
@Test
public void testFailExists() throws Exception {
when(session.exists(anyString())).thenReturn(true);
try {
this.template.send(new GenericMessage<>(this.file), FileExistsMode.FAIL);
fail("Expected exception");
}
catch (MessagingException e) {
assertThat(e.getMessage()).contains("The destination file already exists");
}
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> this.template.send(new GenericMessage<>(this.file), FileExistsMode.FAIL))
.withStackTraceContaining("The destination file already exists");
verify(this.session, never()).write(any(InputStream.class), anyString());
}
@@ -164,9 +159,9 @@ public class RemoteFileTemplateTests {
public void testInvalid() {
assertThatThrownBy(() -> this.template
.send(new GenericMessage<>(new Object()), FileExistsMode.IGNORE))
.isInstanceOf(MessageDeliveryException.class)
.hasCauseInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Unsupported payload type");
.isInstanceOf(MessageDeliveryException.class)
.hasCauseInstanceOf(IllegalArgumentException.class)
.hasStackTraceContaining("Unsupported payload type");
}
}

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.
@@ -36,6 +36,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -43,9 +44,8 @@ import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.BeanFactory;
@@ -81,9 +81,8 @@ public class RemoteFileOutboundGatewayTests {
private final String tmpDir = System.getProperty("java.io.tmpdir");
@Rule
public final TemporaryFolder tempFolder = new TemporaryFolder();
@TempDir
public static File tempFolder;
@Test
public void testBad() {
@@ -168,7 +167,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry(path1.replaceFirst("testremote/", ""), 123, false, false, 1234, "-r--r--r--"),
new TestLsEntry(path2.replaceFirst("testremote/", ""), 123, false, false, 1234,
"-r--r--r--") };
@@ -202,7 +201,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] { new TestLsEntry("f1", 123, false, false, 1234, "-r--r--r--") };
return new TestLsEntry[]{ new TestLsEntry("f1", 123, false, false, 1234, "-r--r--r--") };
}
});
@@ -215,7 +214,7 @@ public class RemoteFileOutboundGatewayTests {
assertThat(out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)).isEqualTo("testremote/");
}
@Test(expected = MessagingException.class)
@Test
public void testMGetEmpty() {
SessionFactory sessionFactory = mock(SessionFactory.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mget", "payload");
@@ -233,7 +232,9 @@ public class RemoteFileOutboundGatewayTests {
}
});
gw.handleRequestMessage(new GenericMessage<>("testremote/*"));
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> gw.handleRequestMessage(new GenericMessage<>("testremote/*")));
}
@Test
@@ -342,7 +343,7 @@ public class RemoteFileOutboundGatewayTests {
}
public TestLsEntry[] level1List() {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 123, false, false, 1234, "-r--r--r--"),
new TestLsEntry("d1", 0, true, false, 12345, "drw-r--r--"),
new TestLsEntry("f2", 12345, false, false, 123456, "-rw-r--r--")
@@ -350,14 +351,14 @@ public class RemoteFileOutboundGatewayTests {
}
public TestLsEntry[] level2List() {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("d2", 0, true, false, 12345, "drw-r--r--"),
new TestLsEntry("f3", 12345, false, false, 123456, "-rw-r--r--")
};
}
public TestLsEntry[] level3List() {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f4", 12345, false, false, 123456, "-rw-r--r--")
};
}
@@ -559,7 +560,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
};
}
@@ -596,7 +597,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
};
}
@@ -658,7 +659,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
};
}
@@ -673,7 +674,7 @@ public class RemoteFileOutboundGatewayTests {
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> gw.handleRequestMessage(new GenericMessage<>("f1")))
.withCauseInstanceOf(RuntimeException.class)
.withMessageContaining("test remove .writing");
.withStackTraceContaining("test remove .writing");
RemoteFileTemplate<?> template = new RemoteFileTemplate<>(sessionFactory);
File outFile = new File(this.tmpDir + "/f1" + template.getTemporaryFileSuffix());
@@ -696,7 +697,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 1234, false, false, modified.getTime(), "-rw-r--r--")
};
}
@@ -731,7 +732,7 @@ public class RemoteFileOutboundGatewayTests {
@Override
public TestLsEntry[] list(String path) {
return new TestLsEntry[] {
return new TestLsEntry[]{
new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--")
};
}
@@ -836,7 +837,7 @@ public class RemoteFileOutboundGatewayTests {
assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() -> gw.handleRequestMessage(requestMessage))
.withMessageContaining("The destination file already exists");
.withStackTraceContaining("The destination file already exists");
gw.setFileExistsMode(FileExistsMode.REPLACE);
path = (String) gw.handleRequestMessage(requestMessage);
@@ -878,10 +879,9 @@ public class RemoteFileOutboundGatewayTests {
written.set(invocation.getArgument(1));
return null;
}).when(session).write(any(InputStream.class), anyString());
tempFolder.newFile("baz.txt");
tempFolder.newFile("qux.txt");
Message<File> requestMessage = MessageBuilder.withPayload(tempFolder.getRoot())
.build();
assertThat(new File(tempFolder, "baz.txt").createNewFile()).isTrue();
assertThat(new File(tempFolder, "qux.txt").createNewFile()).isTrue();
Message<File> requestMessage = MessageBuilder.withPayload(tempFolder).build();
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
assertThat(out).hasSize(2);
assertThat(out.get(0)).isNotEqualTo(out.get(1));
@@ -907,12 +907,12 @@ public class RemoteFileOutboundGatewayTests {
written.set(invocation.getArgument(1));
return null;
}).when(session).write(any(InputStream.class), anyString());
tempFolder.newFile("baz.txt");
tempFolder.newFile("qux.txt");
File dir1 = tempFolder.newFolder();
new File(tempFolder, "baz.txt").createNewFile();
new File(tempFolder, "qux.txt").createNewFile();
File dir1 = Files.createTempDirectory(tempFolder.toPath(), "junit").toFile();
File file3 = File.createTempFile("foo", ".txt", dir1);
Message<File> requestMessage = MessageBuilder.withPayload(tempFolder.getRoot())
Message<File> requestMessage = MessageBuilder.withPayload(tempFolder)
.build();
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
assertThat(out).hasSize(3);
@@ -948,8 +948,12 @@ public class RemoteFileOutboundGatewayTests {
return null;
}).when(session).write(any(InputStream.class), anyString());
List<File> files = new ArrayList<>();
files.add(tempFolder.newFile("fiz.txt"));
files.add(tempFolder.newFile("buz.txt"));
File file1 = new File(tempFolder, "fiz.txt");
file1.createNewFile();
files.add(file1);
File file2 = new File(tempFolder, "buz.txt");
file2.createNewFile();
files.add(file2);
Message<List<File>> requestMessage = MessageBuilder.withPayload(files)
.build();
List<String> out = (List<String>) gw.handleRequestMessage(requestMessage);
@@ -1048,8 +1052,7 @@ public class RemoteFileOutboundGatewayTests {
static class TestRemoteFileOutboundGateway extends AbstractRemoteFileOutboundGateway<TestLsEntry> {
@SuppressWarnings("unchecked")
TestRemoteFileOutboundGateway(SessionFactory sessionFactory,
@SuppressWarnings("unchecked") TestRemoteFileOutboundGateway(SessionFactory sessionFactory,
String command, String expression) {
super(sessionFactory, Command.toCommand(command), expression);
this.setBeanFactory(mock(BeanFactory.class));

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.
@@ -26,7 +26,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.common.LiteralExpression;
@@ -97,7 +97,7 @@ public class CachingSessionFactoryTests {
throw new RuntimeException("bar");
}))
.withCauseInstanceOf(RuntimeException.class)
.withMessageContaining("bar");
.withStackTraceContaining("bar");
verify(session).close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 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.
@@ -61,7 +61,7 @@ public class AbstractRemoteFileSynchronizerTests {
final AtomicBoolean failWhenCopyingBar = new AtomicBoolean(true);
final AtomicInteger count = new AtomicInteger();
SessionFactory<String> sf = new StringSessionFactory();
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<String>(sf) {
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<>(sf) {
@Override
protected boolean isFile(String file) {
@@ -102,7 +102,7 @@ public class AbstractRemoteFileSynchronizerTests {
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> sync.synchronizeToLocalDirectory(mock(File.class)))
.withRootCauseInstanceOf(IOException.class)
.withMessageContaining("fail");
.withStackTraceContaining("fail");
sync.synchronizeToLocalDirectory(mock(File.class));
assertThat(count.get()).isEqualTo(3);
@@ -230,7 +230,7 @@ public class AbstractRemoteFileSynchronizerTests {
@Test
public void testRemoteDirectoryRefreshedOnEachSynchronization(@TempDir File localDir) {
AbstractInboundFileSynchronizer<String> sync =
new AbstractInboundFileSynchronizer<String>(new StringSessionFactory()) {
new AbstractInboundFileSynchronizer<>(new StringSessionFactory()) {
@Override
protected boolean isFile(String file) {
@@ -281,7 +281,7 @@ public class AbstractRemoteFileSynchronizerTests {
AbstractInboundFileSynchronizer<String> sync) {
AbstractInboundFileSynchronizingMessageSource<String> source =
new AbstractInboundFileSynchronizingMessageSource<String>(sync) {
new AbstractInboundFileSynchronizingMessageSource<>(sync) {
@Override
public String getComponentType() {
@@ -299,7 +299,7 @@ public class AbstractRemoteFileSynchronizerTests {
private AbstractInboundFileSynchronizer<String> createLimitingSynchronizer(final AtomicInteger count) {
SessionFactory<String> sf = new StringSessionFactory();
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<String>(sf) {
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<>(sf) {
@Override
protected boolean isFile(String file) {