From 5aefcd2fdb9de0a1fab5ea5b5a1e61f717ba644e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 11 Jan 2022 14:54:59 +0100 Subject: [PATCH] Re-enable BlockHound integration tests Prior to this commit, our BlockHound integration tests were disabled after the migration to a JDK 17 baseline since the build now always runs on JDK 14 or higher. To re-enable the tests we now supply the deprecated -XX:+AllowRedefinitionToAddDeleteMethods command-line argument to the JVM for tests in the Gradle build. Users can also configure this manually within an IDE to run SpringCoreBlockHoundIntegrationTests. If that command-line argument is removed from the JVM at some point in the future, we will need to investigate an alternative solution. See https://github.com/reactor/BlockHound/issues/33 for details. --- spring-core/spring-core.gradle | 6 ++++++ .../SpringCoreBlockHoundIntegrationTests.java | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spring-core/spring-core.gradle b/spring-core/spring-core.gradle index 79dd105c9e0..7e49806e0dc 100644 --- a/spring-core/spring-core.gradle +++ b/spring-core/spring-core.gradle @@ -92,4 +92,10 @@ test { // Make sure the classes dir is used on the test classpath (required by ResourceTests). // When test fixtures are involved, the JAR is used by default. classpath = sourceSets.main.output.classesDirs + classpath - files(jar.archiveFile) + + // Ensure that BlockHound tests run on JDK 13+. For details, see: + // https://github.com/reactor/BlockHound/issues/33 + jvmArgs += [ + "-XX:+AllowRedefinitionToAddDeleteMethods" + ] } diff --git a/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java b/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java index ea4b7fbbd55..370eb36a456 100644 --- a/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java +++ b/spring-core/src/test/java/org/springframework/core/SpringCoreBlockHoundIntegrationTests.java @@ -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. @@ -22,7 +22,6 @@ import java.util.concurrent.CompletableFuture; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledForJreRange; import reactor.blockhound.BlockHound; import reactor.core.scheduler.ReactorBlockHoundIntegration; import reactor.core.scheduler.Schedulers; @@ -32,16 +31,23 @@ import org.springframework.util.ConcurrentReferenceHashMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.condition.JRE.JAVA_14; /** * Tests to verify the spring-core BlockHound integration rules. * + *

NOTE: to run this test class in the IDE, you need to specify the following + * JVM argument. For details, see + * BlockHound issue 33. + * + *

+ * -XX:+AllowRedefinitionToAddDeleteMethods
+ * 
+ * * @author Rossen Stoyanchev + * @author Sam Brannen * @since 5.2.4 */ -@DisabledForJreRange(min = JAVA_14) -public class SpringCoreBlockHoundIntegrationTests { +class SpringCoreBlockHoundIntegrationTests { @BeforeAll @@ -64,7 +70,7 @@ public class SpringCoreBlockHoundIntegrationTests { testNonBlockingTask(() -> { Method setName = TestObject.class.getMethod("setName", String.class); String[] names = new LocalVariableTableParameterNameDiscoverer().getParameterNames(setName); - assertThat(names).isEqualTo(new String[] {"name"}); + assertThat(names).containsExactly("name"); }); }