Merge branch '3.3.x'

Closes gh-43270
This commit is contained in:
Andy Wilkinson 2024-11-22 15:40:51 +00:00
commit 32433e84f3
28 changed files with 184 additions and 129 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,6 +54,7 @@ class CassandraHealthContributorAutoConfigurationTests {
} }
@Test @Test
@SuppressWarnings("resource")
void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() { void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() {
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
.withClassLoader(new FilteredClassLoader("org.springframework.data")) .withClassLoader(new FilteredClassLoader("org.springframework.data"))

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -67,6 +67,7 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
} }
@Test @Test
@SuppressWarnings("resource")
void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() { void runWithCqlSessionAndSpringDataAbsentShouldCreateDriverIndicator() {
this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class)) this.contextRunner.withBean(CqlSession.class, () -> mock(CqlSession.class))
.withClassLoader(new FilteredClassLoader("org.springframework.data")) .withClassLoader(new FilteredClassLoader("org.springframework.data"))

View File

@ -198,6 +198,7 @@ class ZipkinConfigurationsSenderConfigurationTests {
} }
@Test @Test
@SuppressWarnings("resource")
void shouldUseCustomHttpEndpointSupplierFactoryWhenReactive() { void shouldUseCustomHttpEndpointSupplierFactoryWhenReactive() {
this.reactiveContextRunner.withUserConfiguration(WebClientConfiguration.class) this.reactiveContextRunner.withUserConfiguration(WebClientConfiguration.class)
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class)) .withClassLoader(new FilteredClassLoader(URLConnectionSender.class))
@ -207,6 +208,7 @@ class ZipkinConfigurationsSenderConfigurationTests {
} }
@Test @Test
@SuppressWarnings("resource")
void shouldUseCustomHttpEndpointSupplierFactoryWhenRestTemplate() { void shouldUseCustomHttpEndpointSupplierFactoryWhenRestTemplate() {
this.contextRunner.withUserConfiguration(RestTemplateConfiguration.class) this.contextRunner.withUserConfiguration(RestTemplateConfiguration.class)
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class)) .withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class))

View File

@ -102,6 +102,8 @@ class PulsarContainerFactoryCustomizersTests {
/** /**
* Test customizer that will match all {@link PulsarListenerContainerFactory}. * Test customizer that will match all {@link PulsarListenerContainerFactory}.
*
* @param <T> the container factory type
*/ */
static class TestCustomizer<T extends PulsarContainerFactory<?, ?>> implements PulsarContainerFactoryCustomizer<T> { static class TestCustomizer<T extends PulsarContainerFactory<?, ?>> implements PulsarContainerFactoryCustomizer<T> {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -51,32 +51,35 @@ abstract class AbstractDevToolsDataSourceAutoConfigurationTests {
@Test @Test
void singleManuallyConfiguredDataSourceIsNotClosed() throws Exception { void singleManuallyConfiguredDataSourceIsNotClosed() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext(SingleDataSourceConfiguration.class)); try (ConfigurableApplicationContext context = getContext(
DataSource dataSource = context.getBean(DataSource.class); () -> createContext(SingleDataSourceConfiguration.class))) {
Statement statement = configureDataSourceBehavior(dataSource); DataSource dataSource = context.getBean(DataSource.class);
then(statement).should(never()).execute("SHUTDOWN");
}
@Test
void multipleDataSourcesAreIgnored() throws Exception {
ConfigurableApplicationContext context = getContext(
() -> createContext(MultipleDataSourcesConfiguration.class));
Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
for (DataSource dataSource : dataSources) {
Statement statement = configureDataSourceBehavior(dataSource); Statement statement = configureDataSourceBehavior(dataSource);
then(statement).should(never()).execute("SHUTDOWN"); then(statement).should(never()).execute("SHUTDOWN");
} }
} }
@Test
void multipleDataSourcesAreIgnored() throws Exception {
try (ConfigurableApplicationContext context = getContext(
() -> createContext(MultipleDataSourcesConfiguration.class))) {
Collection<DataSource> dataSources = context.getBeansOfType(DataSource.class).values();
for (DataSource dataSource : dataSources) {
Statement statement = configureDataSourceBehavior(dataSource);
then(statement).should(never()).execute("SHUTDOWN");
}
}
}
@Test @Test
void emptyFactoryMethodMetadataIgnored() { void emptyFactoryMethodMetadataIgnored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
DataSource dataSource = mock(DataSource.class); DataSource dataSource = mock(DataSource.class);
AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(dataSource.getClass()); AnnotatedGenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(dataSource.getClass());
context.registerBeanDefinition("dataSource", beanDefinition); context.registerBeanDefinition("dataSource", beanDefinition);
context.register(DevToolsDataSourceAutoConfiguration.class); context.register(DevToolsDataSourceAutoConfiguration.class);
context.refresh(); context.refresh();
context.close(); }
} }
protected final Statement configureDataSourceBehavior(DataSource dataSource) throws SQLException { protected final Statement configureDataSourceBehavior(DataSource dataSource) throws SQLException {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -61,88 +61,99 @@ class DevToolsPooledDataSourceAutoConfigurationTests extends AbstractDevToolsDat
@Test @Test
void autoConfiguredInMemoryDataSourceIsShutdown() throws Exception { void autoConfiguredInMemoryDataSourceIsShutdown() throws Exception {
ConfigurableApplicationContext context = getContext( try (ConfigurableApplicationContext context = getContext(
() -> createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); () -> createContext(DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should().execute("SHUTDOWN"); then(statement).should().execute("SHUTDOWN");
}
} }
@Test @Test
void autoConfiguredExternalDataSourceIsNotShutdown() throws Exception { void autoConfiguredExternalDataSourceIsNotShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.postgresql.Driver", try (ConfigurableApplicationContext context = getContext(() -> createContext("org.postgresql.Driver",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should(never()).execute("SHUTDOWN"); then(statement).should(never()).execute("SHUTDOWN");
}
} }
@Test @Test
void h2ServerIsNotShutdown() throws Exception { void h2ServerIsNotShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.h2.Driver", try (ConfigurableApplicationContext context = getContext(() -> createContext("org.h2.Driver",
"jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); "jdbc:h2:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should(never()).execute("SHUTDOWN"); then(statement).should(never()).execute("SHUTDOWN");
}
} }
@Test @Test
void inMemoryH2IsShutdown() throws Exception { void inMemoryH2IsShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.h2.Driver", "jdbc:h2:mem:test", try (ConfigurableApplicationContext context = getContext(() -> createContext("org.h2.Driver",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); "jdbc:h2:mem:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should().execute("SHUTDOWN"); then(statement).should().execute("SHUTDOWN");
}
} }
@Test @Test
void hsqlServerIsNotShutdown() throws Exception { void hsqlServerIsNotShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.hsqldb.jdbcDriver", try (ConfigurableApplicationContext context = getContext(() -> createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); "jdbc:hsqldb:hsql://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should(never()).execute("SHUTDOWN"); then(statement).should(never()).execute("SHUTDOWN");
}
} }
@Test @Test
void inMemoryHsqlIsShutdown() throws Exception { void inMemoryHsqlIsShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.hsqldb.jdbcDriver", try (ConfigurableApplicationContext context = getContext(() -> createContext("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); "jdbc:hsqldb:mem:test", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
context.close(); context.close();
then(statement).should().execute("SHUTDOWN"); then(statement).should().execute("SHUTDOWN");
}
} }
@Test @Test
void derbyClientIsNotShutdown() throws Exception { void derbyClientIsNotShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("org.apache.derby.jdbc.ClientDriver", try (ConfigurableApplicationContext context = getContext(
"jdbc:derby://localhost", DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); () -> createContext("org.apache.derby.jdbc.ClientDriver", "jdbc:derby://localhost",
Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class)); DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
context.close(); Statement statement = configureDataSourceBehavior(context.getBean(DataSource.class));
then(statement).should(never()).execute("SHUTDOWN"); context.close();
then(statement).should(never()).execute("SHUTDOWN");
}
} }
@Test @Test
void inMemoryDerbyIsShutdown() throws Exception { void inMemoryDerbyIsShutdown() throws Exception {
ConfigurableApplicationContext context = getContext( try (ConfigurableApplicationContext context = getContext(
() -> createContext("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test;create=true", () -> createContext("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:test;create=true",
DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class)); DataSourceAutoConfiguration.class, DataSourceSpyConfiguration.class))) {
HikariDataSource dataSource = context.getBean(HikariDataSource.class); HikariDataSource dataSource = context.getBean(HikariDataSource.class);
JdbcTemplate jdbc = new JdbcTemplate(dataSource); JdbcTemplate jdbc = new JdbcTemplate(dataSource);
jdbc.execute("SELECT 1 FROM SYSIBM.SYSDUMMY1"); jdbc.execute("SELECT 1 FROM SYSIBM.SYSDUMMY1");
HikariPoolMXBean pool = dataSource.getHikariPoolMXBean(); HikariPoolMXBean pool = dataSource.getHikariPoolMXBean();
// Prevent a race between Hikari's initialization and Derby shutdown // Prevent a race between Hikari's initialization and Derby shutdown
Awaitility.await() Awaitility.await()
.atMost(Duration.ofSeconds(30)) .atMost(Duration.ofSeconds(30))
.until(pool::getIdleConnections, (idle) -> idle == dataSource.getMinimumIdle()); .until(pool::getIdleConnections, (idle) -> idle == dataSource.getMinimumIdle());
context.close(); context.close();
// Connect should fail as DB no longer exists // Connect should fail as DB no longer exists
assertThatExceptionOfType(SQLException.class) assertThatExceptionOfType(SQLException.class).isThrownBy(() -> connect("jdbc:derby:memory:test"))
.isThrownBy(() -> new EmbeddedDriver().connect("jdbc:derby:memory:test", new Properties())) .satisfies((ex) -> assertThat(ex.getSQLState()).isEqualTo("XJ004"));
.satisfies((ex) -> assertThat(ex.getSQLState()).isEqualTo("XJ004")); // Shut Derby down fully so that it closes its log file
// Shut Derby down fully so that it closes its log file assertThatExceptionOfType(SQLException.class).isThrownBy(() -> connect("jdbc:derby:;shutdown=true"));
assertThatExceptionOfType(SQLException.class) }
.isThrownBy(() -> new EmbeddedDriver().connect("jdbc:derby:;shutdown=true", new Properties())); }
private void connect(String jdbcUrl) throws SQLException {
new EmbeddedDriver().connect(jdbcUrl, new Properties()).close();
} }
} }

View File

@ -71,28 +71,32 @@ class DevToolsR2dbcAutoConfigurationTests {
@Test @Test
void nonEmbeddedConnectionFactoryIsNotShutdown() throws Exception { void nonEmbeddedConnectionFactoryIsNotShutdown() throws Exception {
ConfigurableApplicationContext context = getContext(() -> createContext("r2dbc:h2:file:///testdb")); try (ConfigurableApplicationContext context = getContext(() -> createContext("r2dbc:h2:file:///testdb"))) {
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
context.close(); context.close();
assertThat(shutdowns).doesNotContain(connectionFactory); assertThat(shutdowns).doesNotContain(connectionFactory);
}
} }
@Test @Test
void singleManuallyConfiguredConnectionFactoryIsNotClosed() throws Exception { void singleManuallyConfiguredConnectionFactoryIsNotClosed() throws Exception {
ConfigurableApplicationContext context = getContext( try (ConfigurableApplicationContext context = getContext(
() -> createContext(SingleConnectionFactoryConfiguration.class)); () -> createContext(SingleConnectionFactoryConfiguration.class))) {
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
context.close(); context.close();
assertThat(shutdowns).doesNotContain(connectionFactory); assertThat(shutdowns).doesNotContain(connectionFactory);
}
} }
@Test @Test
void multipleConnectionFactoriesAreIgnored() throws Exception { void multipleConnectionFactoriesAreIgnored() throws Exception {
ConfigurableApplicationContext context = getContext( try (ConfigurableApplicationContext context = getContext(
() -> createContext(MultipleConnectionFactoriesConfiguration.class)); () -> createContext(MultipleConnectionFactoriesConfiguration.class))) {
Collection<ConnectionFactory> connectionFactory = context.getBeansOfType(ConnectionFactory.class).values(); Collection<ConnectionFactory> connectionFactory = context.getBeansOfType(ConnectionFactory.class)
context.close(); .values();
assertThat(shutdowns).doesNotContainAnyElementsOf(connectionFactory); context.close();
assertThat(shutdowns).doesNotContainAnyElementsOf(connectionFactory);
}
} }
@Test @Test

View File

@ -403,7 +403,7 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "resource" })
private A createAssertableContext(boolean refresh) { private A createAssertableContext(boolean refresh) {
ResolvableType resolvableType = ResolvableType.forClass(AbstractApplicationContextRunner.class, getClass()); ResolvableType resolvableType = ResolvableType.forClass(AbstractApplicationContextRunner.class, getClass());
Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1); Class<A> assertType = (Class<A>) resolvableType.resolveGeneric(1);

View File

@ -33,6 +33,7 @@ import static org.mockito.Mockito.withSettings;
class AssertableApplicationContextTests { class AssertableApplicationContextTests {
@Test @Test
@SuppressWarnings("resource")
void getShouldReturnProxy() { void getShouldReturnProxy() {
AssertableApplicationContext context = AssertableApplicationContext AssertableApplicationContext context = AssertableApplicationContext
.get(() -> mock(ConfigurableApplicationContext.class)); .get(() -> mock(ConfigurableApplicationContext.class));
@ -41,12 +42,13 @@ class AssertableApplicationContextTests {
@Test @Test
void getWhenHasAdditionalInterfaceShouldReturnProxy() { void getWhenHasAdditionalInterfaceShouldReturnProxy() {
AssertableApplicationContext context = AssertableApplicationContext.get( try (AssertableApplicationContext context = AssertableApplicationContext.get(
() -> mock(ConfigurableApplicationContext.class, () -> mock(ConfigurableApplicationContext.class,
withSettings().extraInterfaces(AdditionalContextInterface.class)), withSettings().extraInterfaces(AdditionalContextInterface.class)),
AdditionalContextInterface.class); AdditionalContextInterface.class)) {
assertThat(context).isInstanceOf(ConfigurableApplicationContext.class) assertThat(context).isInstanceOf(ConfigurableApplicationContext.class)
.isInstanceOf(AdditionalContextInterface.class); .isInstanceOf(AdditionalContextInterface.class);
}
} }
} }

View File

@ -33,6 +33,7 @@ import static org.mockito.Mockito.withSettings;
class AssertableReactiveWebApplicationContextTests { class AssertableReactiveWebApplicationContextTests {
@Test @Test
@SuppressWarnings("resource")
void getShouldReturnProxy() { void getShouldReturnProxy() {
AssertableReactiveWebApplicationContext context = AssertableReactiveWebApplicationContext AssertableReactiveWebApplicationContext context = AssertableReactiveWebApplicationContext
.get(() -> mock(ConfigurableReactiveWebApplicationContext.class)); .get(() -> mock(ConfigurableReactiveWebApplicationContext.class));
@ -41,12 +42,13 @@ class AssertableReactiveWebApplicationContextTests {
@Test @Test
void getWhenHasAdditionalInterfaceShouldReturnProxy() { void getWhenHasAdditionalInterfaceShouldReturnProxy() {
AssertableReactiveWebApplicationContext context = AssertableReactiveWebApplicationContext.get( try (AssertableReactiveWebApplicationContext context = AssertableReactiveWebApplicationContext.get(
() -> mock(ConfigurableReactiveWebApplicationContext.class, () -> mock(ConfigurableReactiveWebApplicationContext.class,
withSettings().extraInterfaces(AdditionalContextInterface.class)), withSettings().extraInterfaces(AdditionalContextInterface.class)),
AdditionalContextInterface.class); AdditionalContextInterface.class)) {
assertThat(context).isInstanceOf(ConfigurableReactiveWebApplicationContext.class) assertThat(context).isInstanceOf(ConfigurableReactiveWebApplicationContext.class)
.isInstanceOf(AdditionalContextInterface.class); .isInstanceOf(AdditionalContextInterface.class);
}
} }
} }

View File

@ -33,6 +33,7 @@ import static org.mockito.Mockito.withSettings;
class AssertableWebApplicationContextTests { class AssertableWebApplicationContextTests {
@Test @Test
@SuppressWarnings("resource")
void getShouldReturnProxy() { void getShouldReturnProxy() {
AssertableWebApplicationContext context = AssertableWebApplicationContext AssertableWebApplicationContext context = AssertableWebApplicationContext
.get(() -> mock(ConfigurableWebApplicationContext.class)); .get(() -> mock(ConfigurableWebApplicationContext.class));
@ -41,12 +42,13 @@ class AssertableWebApplicationContextTests {
@Test @Test
void getWhenHasAdditionalInterfaceShouldReturnProxy() { void getWhenHasAdditionalInterfaceShouldReturnProxy() {
ConfigurableWebApplicationContext context = AssertableWebApplicationContext.get( try (ConfigurableWebApplicationContext context = AssertableWebApplicationContext.get(
() -> mock(ConfigurableWebApplicationContext.class, () -> mock(ConfigurableWebApplicationContext.class,
withSettings().extraInterfaces(AdditionalContextInterface.class)), withSettings().extraInterfaces(AdditionalContextInterface.class)),
AdditionalContextInterface.class); AdditionalContextInterface.class)) {
assertThat(context).isInstanceOf(ConfigurableWebApplicationContext.class) assertThat(context).isInstanceOf(ConfigurableWebApplicationContext.class)
.isInstanceOf(AdditionalContextInterface.class); .isInstanceOf(AdditionalContextInterface.class);
}
} }
} }

View File

@ -600,7 +600,7 @@ class DockerApiTests {
} }
@Test @Test
void createWithPlatformAndInsufficientApiVersionThrowsException() throws Exception { void createWithPlatformAndInsufficientApiVersionThrowsException() {
ImageReference imageReference = ImageReference.of("ubuntu:bionic"); ImageReference imageReference = ImageReference.of("ubuntu:bionic");
ContainerConfig config = ContainerConfig.of(imageReference, (update) -> update.withCommand("/bin/bash")); ContainerConfig config = ContainerConfig.of(imageReference, (update) -> update.withCommand("/bin/bash"));
ImagePlatform platform = ImagePlatform.of("linux/arm64/v1"); ImagePlatform platform = ImagePlatform.of("linux/arm64/v1");

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,10 @@
package org.springframework.boot.buildpack.platform.json; package org.springframework.boot.buildpack.platform.json;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -45,8 +47,13 @@ public abstract class AbstractJsonTests {
} }
protected final String getContentAsString(String name) { protected final String getContentAsString(String name) {
return new BufferedReader(new InputStreamReader(getContent(name), StandardCharsets.UTF_8)).lines() try (InputStream in = getContent(name)) {
.collect(Collectors.joining("\n")); return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining("\n"));
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
} }
} }

View File

@ -348,8 +348,11 @@ class BootZipCopyAction implements CopyAction {
private void writeJarModeLibrary(String location, JarModeLibrary library) throws IOException { private void writeJarModeLibrary(String location, JarModeLibrary library) throws IOException {
String name = location + library.getName(); String name = location + library.getName();
writeEntry(name, ZipEntryContentWriter.fromInputStream(library.openStream()), false, writeEntry(name, ZipEntryContentWriter.fromInputStream(library.openStream()), false, (entry) -> {
(entry) -> prepareStoredEntry(library.openStream(), entry)); try (InputStream in = library.openStream()) {
prepareStoredEntry(library.openStream(), entry);
}
});
if (BootZipCopyAction.this.layerResolver != null) { if (BootZipCopyAction.this.layerResolver != null) {
Layer layer = BootZipCopyAction.this.layerResolver.getLayer(library); Layer layer = BootZipCopyAction.this.layerResolver.getLayer(library);
this.layerIndex.add(layer, name); this.layerIndex.add(layer, name);

View File

@ -122,9 +122,10 @@ class NativeImagePluginActionIntegrationTests {
BuildResult result = this.gradleBuild.build("bootJar"); BuildResult result = this.gradleBuild.build("bootJar");
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs"); File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
JarFile jarFile = new JarFile(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".jar")); try (JarFile jarFile = new JarFile(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".jar"))) {
Manifest manifest = jarFile.getManifest(); Manifest manifest = jarFile.getManifest();
assertThat(manifest.getMainAttributes().getValue("Spring-Boot-Native-Processed")).isEqualTo("true"); assertThat(manifest.getMainAttributes().getValue("Spring-Boot-Native-Processed")).isEqualTo("true");
}
} }
private String projectPath(String path) { private String projectPath(String path) {

View File

@ -84,6 +84,7 @@ public class NestedFileSystemProvider extends FileSystemProvider {
} }
@Override @Override
@SuppressWarnings("resource")
public Path getPath(URI uri) { public Path getPath(URI uri) {
NestedLocation location = NestedLocation.fromUri(uri); NestedLocation location = NestedLocation.fromUri(uri);
synchronized (this.fileSystems) { synchronized (this.fileSystems) {

View File

@ -475,7 +475,6 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate @TestTemplate
void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) { void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("dockerTest", "build-image-created-date") mavenBuild.project("dockerTest", "build-image-created-date")
.goals("package") .goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")

View File

@ -88,6 +88,7 @@ public enum TestImage {
* {@link org.testcontainers.containers.CassandraContainer}. * {@link org.testcontainers.containers.CassandraContainer}.
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of {@link #CASSANDRA} * @deprecated since 3.4.0 for removal in 3.6.0 in favor of {@link #CASSANDRA}
*/ */
@SuppressWarnings("deprecation")
@Deprecated(since = "3.4.0", forRemoval = true) @Deprecated(since = "3.4.0", forRemoval = true)
CASSANDRA_DEPRECATED("cassandra", "3.11.10", () -> org.testcontainers.containers.CassandraContainer.class, CASSANDRA_DEPRECATED("cassandra", "3.11.10", () -> org.testcontainers.containers.CassandraContainer.class,
(container) -> ((org.testcontainers.containers.CassandraContainer<?>) container) (container) -> ((org.testcontainers.containers.CassandraContainer<?>) container)
@ -139,6 +140,7 @@ public enum TestImage {
* deprecated {@link org.testcontainers.containers.KafkaContainer}. * deprecated {@link org.testcontainers.containers.KafkaContainer}.
* @deprecated since 3.4.0 for removal in 3.6.0 in favor of {@link #CONFLUENT_KAFKA} * @deprecated since 3.4.0 for removal in 3.6.0 in favor of {@link #CONFLUENT_KAFKA}
*/ */
@SuppressWarnings("deprecation")
@Deprecated(since = "3.4.0", forRemoval = true) @Deprecated(since = "3.4.0", forRemoval = true)
CONFLUENT_KAFKA_DEPRECATED("confluentinc/cp-kafka", "7.4.0", CONFLUENT_KAFKA_DEPRECATED("confluentinc/cp-kafka", "7.4.0",
() -> org.testcontainers.containers.KafkaContainer.class), () -> org.testcontainers.containers.KafkaContainer.class),

View File

@ -99,6 +99,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
return super.loadClass(name); return super.loadClass(name);
} }
@SuppressWarnings("resource")
static ModifiedClassPathClassLoader get(Class<?> testClass, Method testMethod, List<Object> arguments) { static ModifiedClassPathClassLoader get(Class<?> testClass, Method testMethod, List<Object> arguments) {
Set<AnnotatedElement> candidates = new LinkedHashSet<>(); Set<AnnotatedElement> candidates = new LinkedHashSet<>();
candidates.add(testClass); candidates.add(testClass);

View File

@ -67,6 +67,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("deprecation")
void getReturnsRequestFactoryOfExpectedType() { void getReturnsRequestFactoryOfExpectedType() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories
.get(ClientHttpRequestFactorySettings.DEFAULTS); .get(ClientHttpRequestFactorySettings.DEFAULTS);
@ -74,6 +75,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("deprecation")
void getOfGeneralTypeReturnsRequestFactoryOfExpectedType() { void getOfGeneralTypeReturnsRequestFactoryOfExpectedType() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(ClientHttpRequestFactory.class, ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(ClientHttpRequestFactory.class,
ClientHttpRequestFactorySettings.DEFAULTS); ClientHttpRequestFactorySettings.DEFAULTS);
@ -81,6 +83,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("deprecation")
void getOfSpecificTypeReturnsRequestFactoryOfExpectedType() { void getOfSpecificTypeReturnsRequestFactoryOfExpectedType() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(this.requestFactoryType, ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories.get(this.requestFactoryType,
ClientHttpRequestFactorySettings.DEFAULTS); ClientHttpRequestFactorySettings.DEFAULTS);
@ -88,7 +91,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings({ "deprecation", "unchecked" })
void getReturnsRequestFactoryWithConfiguredConnectTimeout() { void getReturnsRequestFactoryWithConfiguredConnectTimeout() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories
.get(ClientHttpRequestFactorySettings.DEFAULTS.withConnectTimeout(Duration.ofSeconds(60))); .get(ClientHttpRequestFactorySettings.DEFAULTS.withConnectTimeout(Duration.ofSeconds(60)));
@ -96,7 +99,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings({ "deprecation", "unchecked" })
void getReturnsRequestFactoryWithConfiguredReadTimeout() { void getReturnsRequestFactoryWithConfiguredReadTimeout() {
ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories ClientHttpRequestFactory requestFactory = ClientHttpRequestFactories
.get(ClientHttpRequestFactorySettings.DEFAULTS.withReadTimeout(Duration.ofSeconds(120))); .get(ClientHttpRequestFactorySettings.DEFAULTS.withReadTimeout(Duration.ofSeconds(120)));
@ -104,6 +107,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("deprecation")
void shouldSetConnectTimeoutsWhenUsingReflective() { void shouldSetConnectTimeoutsWhenUsingReflective() {
Assumptions.assumeTrue(supportsSettingConnectTimeout()); Assumptions.assumeTrue(supportsSettingConnectTimeout());
ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS
@ -114,6 +118,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@Test @Test
@SuppressWarnings("deprecation")
void shouldSetReadTimeoutsWhenUsingReflective() { void shouldSetReadTimeoutsWhenUsingReflective() {
Assumptions.assumeTrue(supportsSettingReadTimeout()); Assumptions.assumeTrue(supportsSettingReadTimeout());
ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS ClientHttpRequestFactorySettings settings = ClientHttpRequestFactorySettings.DEFAULTS
@ -124,6 +129,7 @@ abstract class AbstractClientHttpRequestFactoriesTests<T extends ClientHttpReque
} }
@ParameterizedTest @ParameterizedTest
@SuppressWarnings("deprecation")
@ValueSource(strings = { "GET", "POST" }) @ValueSource(strings = { "GET", "POST" })
void connectWithSslBundle(String httpMethod) throws Exception { void connectWithSslBundle(String httpMethod) throws Exception {
TomcatServletWebServerFactory webServerFactory = new TomcatServletWebServerFactory(0); TomcatServletWebServerFactory webServerFactory = new TomcatServletWebServerFactory(0);

View File

@ -37,8 +37,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Tests for {@link ClientHttpRequestFactories}. * Tests for {@link ClientHttpRequestFactories}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class ClientHttpRequestFactoriesTests { class ClientHttpRequestFactoriesTests {
@Test @Test

View File

@ -29,8 +29,10 @@ import static org.mockito.Mockito.mock;
* Tests for {@link ClientHttpRequestFactorySettings}. * Tests for {@link ClientHttpRequestFactorySettings}.
* *
* @author Phillip Webb * @author Phillip Webb
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class ClientHttpRequestFactorySettingsTests { class ClientHttpRequestFactorySettingsTests {
private static final Duration ONE_SECOND = Duration.ofSeconds(1); private static final Duration ONE_SECOND = Duration.ofSeconds(1);

View File

@ -570,19 +570,16 @@ public abstract class AbstractReactiveWebServerFactoryTests {
factory.setHttp2(http2); factory.setHttp2(http2);
this.webServer = factory.getWebServer(new EchoHandler()); this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start(); this.webServer.start();
org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(
new HttpClientTransportOverHTTP2(new HTTP2Client())); try (org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(
client.start(); new HttpClientTransportOverHTTP2(new HTTP2Client()))) {
try { client.start();
ContentResponse response = client.POST("http://localhost:" + this.webServer.getPort()) ContentResponse response = client.POST("http://localhost:" + this.webServer.getPort())
.body(new StringRequestContent("text/plain", "Hello World")) .body(new StringRequestContent("text/plain", "Hello World"))
.send(); .send();
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(response.getContentAsString()).isEqualTo("Hello World"); assertThat(response.getContentAsString()).isEqualTo("Hello World");
} }
finally {
client.stop();
}
} }
@Test @Test

View File

@ -1288,17 +1288,13 @@ public abstract class AbstractServletWebServerFactoryTests {
factory.setHttp2(http2); factory.setHttp2(http2);
this.webServer = factory.getWebServer(exampleServletRegistration()); this.webServer = factory.getWebServer(exampleServletRegistration());
this.webServer.start(); this.webServer.start();
org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient( try (org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(
new HttpClientTransportOverHTTP2(new HTTP2Client())); new HttpClientTransportOverHTTP2(new HTTP2Client()))) {
client.start(); client.start();
try {
ContentResponse response = client.GET("http://localhost:" + this.webServer.getPort() + "/hello"); ContentResponse response = client.GET("http://localhost:" + this.webServer.getPort() + "/hello");
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value()); assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(response.getContentAsString()).isEqualTo("Hello World"); assertThat(response.getContentAsString()).isEqualTo("Hello World");
} }
finally {
client.stop();
}
} }
@Test @Test

View File

@ -35,9 +35,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* available and, therefore, Jetty's client is used instead. * available and, therefore, Jetty's client is used instead.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@ClassPathExclusions("httpclient5-*.jar") @ClassPathExclusions("httpclient5-*.jar")
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class HttpWebServiceMessageSenderBuilderJettyClientIntegrationTests { class HttpWebServiceMessageSenderBuilderJettyClientIntegrationTests {
private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder(); private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();

View File

@ -36,9 +36,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* predominant HTTP client. * predominant HTTP client.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar" }) @ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar" })
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class HttpWebServiceMessageSenderBuilderReactorClientIntegrationTests { class HttpWebServiceMessageSenderBuilderReactorClientIntegrationTests {
private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder(); private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();

View File

@ -33,9 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* available * available
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" }) @ClassPathExclusions({ "httpclient5-*.jar", "jetty-client-*.jar", "reactor-netty-http-*.jar" })
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests { class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests {
private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder(); private final HttpWebServiceMessageSenderBuilder builder = new HttpWebServiceMessageSenderBuilder();

View File

@ -33,8 +33,10 @@ import static org.mockito.Mockito.mock;
* Tests for {@link HttpWebServiceMessageSenderBuilder}. * Tests for {@link HttpWebServiceMessageSenderBuilder}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @deprecated since 3.4.0 for removal in 3.6.0
*/ */
@SuppressWarnings("removal") @SuppressWarnings("removal")
@Deprecated(since = "3.4.0", forRemoval = true)
class HttpWebServiceMessageSenderBuilderTests { class HttpWebServiceMessageSenderBuilderTests {
@Test @Test