diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTests.java index 036c6f7c36..dc8717e0df 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/AbstractDataBufferAllocatingTests.java @@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.params.provider.Arguments.arguments; /** - * Base class for tests that read or write data buffers with a rule to check + * Base class for tests that read or write data buffers with an extension to check * that allocated buffers have been released. * * @author Arjen Poutsma @@ -56,7 +56,7 @@ import static org.junit.jupiter.params.provider.Arguments.arguments; public abstract class AbstractDataBufferAllocatingTests { @RegisterExtension - AfterEachCallback leakDetector = context -> verifyAllocations(); + AfterEachCallback leakDetector = context -> waitForDataBufferRelease(Duration.ofSeconds(2)); protected DataBufferFactory bufferFactory; @@ -94,7 +94,7 @@ public abstract class AbstractDataBufferAllocatingTests { /** * Wait until allocations are at 0, or the given duration elapses. */ - protected void waitForDataBufferRelease(Duration duration) throws InterruptedException { + private void waitForDataBufferRelease(Duration duration) throws InterruptedException { Instant start = Instant.now(); while (true) { try { diff --git a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java index 1fd2a75336..68cf59d39c 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/ServerSentEventHttpMessageWriterTests.java @@ -49,7 +49,7 @@ import static org.springframework.core.ResolvableType.forClass; * @author Sam Brannen */ @SuppressWarnings("rawtypes") -public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocatingTests { +class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAllocatingTests { private static final Map HINTS = Collections.emptyMap(); @@ -58,7 +58,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll @ParameterizedDataBufferAllocatingTest - public void canWrite(String displayName, DataBufferFactory bufferFactory) { + void canWrite(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; assertThat(this.messageWriter.canWrite(forClass(Object.class), null)).isTrue(); @@ -73,7 +73,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest - public void writeServerSentEvent(String displayName, DataBufferFactory bufferFactory) { + void writeServerSentEvent(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; ServerSentEvent event = ServerSentEvent.builder().data("bar").id("c42").event("foo") @@ -91,7 +91,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest - public void writeString(String displayName, DataBufferFactory bufferFactory) { + void writeString(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -106,7 +106,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest - public void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) { + void writeMultiLineString(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -121,7 +121,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest // SPR-16516 - public void writeStringWithCustomCharset(String displayName, DataBufferFactory bufferFactory) { + void writeStringWithCustomCharset(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -142,7 +142,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest - public void writePojo(String displayName, DataBufferFactory bufferFactory) { + void writePojo(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); @@ -157,7 +157,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest // SPR-14899 - public void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactory) { + void writePojoWithPrettyPrint(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build(); @@ -179,7 +179,7 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll } @ParameterizedDataBufferAllocatingTest // SPR-16516, SPR-16539 - public void writePojoWithCustomEncoding(String displayName, DataBufferFactory bufferFactory) { + void writePojoWithCustomEncoding(String displayName, DataBufferFactory bufferFactory) { super.bufferFactory = bufferFactory; MockServerHttpResponse outputMessage = new MockServerHttpResponse(super.bufferFactory); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java index 6624c5cd87..758d8f625a 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientDataBufferAllocatingTests.java @@ -26,7 +26,6 @@ import io.netty.channel.ChannelOption; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestInstance; import reactor.core.publisher.Mono; @@ -95,11 +94,6 @@ class WebClientDataBufferAllocatingTests extends AbstractDataBufferAllocatingTes } } - @AfterEach - void shutDown() throws InterruptedException { - waitForDataBufferRelease(Duration.ofSeconds(2)); - } - @ParameterizedDataBufferAllocatingTest void bodyToMonoVoid(String displayName, DataBufferFactory bufferFactory) {