forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for @ShouldNotPin/@ShouldPin on superclass
Fix for quarkusio#41782 Allow the usage of @ShouldPin and @ShouldNotPin on super classes
- Loading branch information
Showing
14 changed files
with
258 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...t5-virtual-threads/src/test/java/io/quarkus/test/junit5/virtual/internal/JUnitEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.test.junit5.virtual.internal; | ||
|
||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod; | ||
import static org.junit.platform.testkit.engine.EventConditions.*; | ||
|
||
import org.assertj.core.api.Condition; | ||
import org.junit.platform.testkit.engine.EngineTestKit; | ||
import org.junit.platform.testkit.engine.Events; | ||
|
||
public class JUnitEngine { | ||
|
||
public static void runTestAndAssertFailure(Class<?> clazz, String methodName, String message) { | ||
runTest(clazz, methodName).assertThatEvents() | ||
.haveExactly(1, event(test(methodName), | ||
finishedWithFailure(new Condition<>( | ||
throwable -> throwable instanceof AssertionError && throwable.getMessage().contains(message), | ||
"")))); | ||
} | ||
|
||
public static void runTestAndAssertSuccess(Class<?> clazz, String methodName) { | ||
runTest(clazz, methodName).assertThatEvents() | ||
.haveExactly(1, event(test(methodName), | ||
finishedSuccessfully())); | ||
} | ||
|
||
public static Events runTest(Class<?> clazz, String methodName) { | ||
return EngineTestKit | ||
.engine("junit-jupiter") | ||
.selectors(selectMethod(clazz, methodName)) | ||
.execute() | ||
.testEvents(); | ||
} | ||
|
||
} |
33 changes: 0 additions & 33 deletions
33
...ads/src/test/java/io/quarkus/test/junit5/virtual/internal/LoomUnitExampleOnClassTest.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...rtual-threads/src/test/java/io/quarkus/test/junit5/virtual/internal/ShouldNotPinTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.quarkus.test.junit5.virtual.internal; | ||
|
||
import static io.quarkus.test.junit5.virtual.internal.JUnitEngine.runTestAndAssertFailure; | ||
import static io.quarkus.test.junit5.virtual.internal.JUnitEngine.runTestAndAssertSuccess; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledForJreRange; | ||
import org.junit.jupiter.api.condition.JRE; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleOnMethodTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldNotPinOnClassTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldNotPinOnSuperClassTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldPinOnSuperClassTest; | ||
|
||
public class ShouldNotPinTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
@EnabledForJreRange(min = JRE.JAVA_21) | ||
void testShouldNotPinButPinEventDetected(Class<?> clazz, String methodName) { | ||
runTestAndAssertFailure(clazz, methodName, "was expected to NOT pin the carrier thread"); | ||
} | ||
|
||
public static Stream<Arguments> testShouldNotPinButPinEventDetected() { | ||
return Stream.of( | ||
arguments(LoomUnitExampleOnMethodTest.class, "failWhenShouldNotPinAndPinDetected"), | ||
arguments(LoomUnitExampleOnMethodTest.class, "failWhenShouldNotPinAtMostAndTooManyPinDetected"), | ||
arguments(LoomUnitExampleShouldNotPinOnClassTest.class, "failWhenShouldNotPinAndPinDetected"), | ||
arguments(LoomUnitExampleShouldNotPinOnSuperClassTest.class, "failWhenShouldNotPinAndPinDetected"), | ||
arguments(LoomUnitExampleShouldPinOnSuperClassTest.class, "failWhenShouldNotPinAndPinDetected")); | ||
} | ||
|
||
@Test | ||
@EnabledForJreRange(min = JRE.JAVA_21) | ||
void shouldNotPinOnMethodOverridesClassAnnotation() { | ||
runTestAndAssertSuccess(LoomUnitExampleShouldNotPinOnClassTest.class, "overrideClassAnnotation"); | ||
runTestAndAssertSuccess(LoomUnitExampleShouldNotPinOnSuperClassTest.class, "overrideClassAnnotation"); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...-virtual-threads/src/test/java/io/quarkus/test/junit5/virtual/internal/ShouldPinTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkus.test.junit5.virtual.internal; | ||
|
||
import static io.quarkus.test.junit5.virtual.internal.JUnitEngine.runTestAndAssertFailure; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.condition.EnabledForJreRange; | ||
import org.junit.jupiter.api.condition.JRE; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleOnMethodTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldNotPinOnClassTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldNotPinOnSuperClassTest; | ||
import io.quarkus.test.junit5.virtual.internal.ignore.LoomUnitExampleShouldPinOnSuperClassTest; | ||
|
||
public class ShouldPinTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
@EnabledForJreRange(min = JRE.JAVA_21) | ||
void testShouldPinButNoPinEventDetected(Class<?> clazz, String methodName) { | ||
runTestAndAssertFailure(clazz, methodName, "was expected to pin the carrier thread, it didn't"); | ||
} | ||
|
||
public static Stream<Arguments> testShouldPinButNoPinEventDetected() { | ||
return Stream.of( | ||
arguments(LoomUnitExampleOnMethodTest.class, "failWhenMethodShouldPinButNoPinDetected"), | ||
arguments(LoomUnitExampleShouldNotPinOnClassTest.class, "failWhenMethodShouldPinButNoPinDetected"), | ||
arguments(LoomUnitExampleShouldNotPinOnSuperClassTest.class, "failWhenShouldPinAndNoPinDetected"), | ||
arguments(LoomUnitExampleShouldPinOnSuperClassTest.class, "failWhenShouldPinAndNoPinDetected")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...test/java/io/quarkus/test/junit5/virtual/internal/ignore/LoomUnitExampleOnMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldNotPin; | ||
import io.quarkus.test.junit5.virtual.ShouldPin; | ||
import io.quarkus.test.junit5.virtual.VirtualThreadUnit; | ||
import io.quarkus.test.junit5.virtual.internal.TestPinJfrEvent; | ||
|
||
@VirtualThreadUnit | ||
public class LoomUnitExampleOnMethodTest { | ||
|
||
@Test | ||
@ShouldNotPin | ||
void failWhenShouldNotPinAndPinDetected() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldNotPin(atMost = 1) | ||
void failWhenShouldNotPinAtMostAndTooManyPinDetected() { | ||
TestPinJfrEvent.pin(); | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldPin | ||
void failWhenMethodShouldPinButNoPinDetected() { | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...o/quarkus/test/junit5/virtual/internal/ignore/LoomUnitExampleShouldNotPinOnClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldNotPin; | ||
import io.quarkus.test.junit5.virtual.ShouldPin; | ||
import io.quarkus.test.junit5.virtual.VirtualThreadUnit; | ||
import io.quarkus.test.junit5.virtual.internal.TestPinJfrEvent; | ||
|
||
@VirtualThreadUnit | ||
@ShouldNotPin // You can use @ShouldNotPin or @ShouldPin on the class itself, it's applied to each method. | ||
public class LoomUnitExampleShouldNotPinOnClassTest { | ||
|
||
@Test | ||
public void failWhenShouldNotPinAndPinDetected() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldPin(atMost = 1) | ||
public void overrideClassAnnotation() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldPin | ||
public void failWhenMethodShouldPinButNoPinDetected() { | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../quarkus/test/junit5/virtual/internal/ignore/LoomUnitExampleShouldNotPinOnSuperClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldNotPin; | ||
import io.quarkus.test.junit5.virtual.VirtualThreadUnit; | ||
|
||
@VirtualThreadUnit | ||
@ShouldNotPin // You can use @ShouldNotPin or @ShouldPin on the super class itself, it's applied to each method. | ||
public abstract class LoomUnitExampleShouldNotPinOnSuperClass { | ||
} |
27 changes: 27 additions & 0 deletions
27
...rkus/test/junit5/virtual/internal/ignore/LoomUnitExampleShouldNotPinOnSuperClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldPin; | ||
import io.quarkus.test.junit5.virtual.internal.TestPinJfrEvent; | ||
|
||
public class LoomUnitExampleShouldNotPinOnSuperClassTest extends LoomUnitExampleShouldNotPinOnSuperClass { | ||
|
||
@Test | ||
public void failWhenShouldNotPinAndPinDetected() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldPin(atMost = 1) | ||
public void overrideClassAnnotation() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
@ShouldPin // Method annotation overrides the class annotation | ||
public void failWhenShouldPinAndNoPinDetected() { | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../io/quarkus/test/junit5/virtual/internal/ignore/LoomUnitExampleShouldPinOnSuperClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldPin; | ||
import io.quarkus.test.junit5.virtual.VirtualThreadUnit; | ||
|
||
@VirtualThreadUnit | ||
@ShouldPin // You can use @ShouldNotPin or @ShouldPin on the super class itself, it's applied to each method. | ||
public abstract class LoomUnitExampleShouldPinOnSuperClass { | ||
} |
21 changes: 21 additions & 0 deletions
21
...quarkus/test/junit5/virtual/internal/ignore/LoomUnitExampleShouldPinOnSuperClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.test.junit5.virtual.internal.ignore; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit5.virtual.ShouldNotPin; | ||
import io.quarkus.test.junit5.virtual.internal.TestPinJfrEvent; | ||
|
||
public class LoomUnitExampleShouldPinOnSuperClassTest extends LoomUnitExampleShouldPinOnSuperClass { | ||
|
||
@Test | ||
@ShouldNotPin // Method annotation overrides the class annotation | ||
public void failWhenShouldNotPinAndPinDetected() { | ||
TestPinJfrEvent.pin(); | ||
} | ||
|
||
@Test | ||
public void failWhenShouldPinAndNoPinDetected() { | ||
|
||
} | ||
|
||
} |