Skip to content

Commit f7d5221

Browse files
committed
HHH-19832 Disable BytecodeEnhancedTestEngine by default
1 parent 7a033f5 commit f7d5221

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/BytecodeEnhancementPostDiscoveryFilter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated;
99

1010
import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedEngineDescriptor;
11+
import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedTestEngine;
1112
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
1213
import org.junit.platform.engine.FilterResult;
1314
import org.junit.platform.engine.TestDescriptor;
@@ -24,6 +25,11 @@ public FilterResult apply(TestDescriptor testDescriptor) {
2425
}
2526

2627
boolean isEnhanced = isAnnotated( descriptor.getTestClass(), BytecodeEnhanced.class );
28+
if ( isEnhanced && !BytecodeEnhancedTestEngine.isEnabled() ) {
29+
throw new IllegalStateException(
30+
"BytecodeEnhancedTestEngine is disabled. But the tests rely on the @BytecodeEnhanced extensions: %s. In order to run this test, make sure to exactly align your dependency to JUnit with that of hibernate-testing, and set system property '%s=true'.".formatted(
31+
descriptor, BytecodeEnhancedTestEngine.ENHANCEMENT_EXTENSION_ENGINE_ENABLED ) );
32+
}
2733
if ( root instanceof BytecodeEnhancedEngineDescriptor ) {
2834
if ( !isEnhanced ) {
2935
return FilterResult.excluded( "Not bytecode enhanced." );
@@ -32,7 +38,7 @@ public FilterResult apply(TestDescriptor testDescriptor) {
3238
else {
3339
if ( isEnhanced ) {
3440
testDescriptor.removeFromHierarchy();
35-
return FilterResult.excluded( "Not bytecode enhanced." );
41+
return FilterResult.excluded( "Not bytecode enhanced engine, but test requires bytecode enhancement." );
3642
}
3743
}
3844
}

hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,34 @@
5151
import org.junit.platform.engine.OutputDirectoryCreator;
5252
import org.junit.platform.engine.TestDescriptor;
5353
import org.junit.platform.engine.UniqueId;
54+
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
5455
import org.junit.platform.engine.support.hierarchical.EngineExecutionContext;
5556
import org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine;
5657
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;
5758

5859
public class BytecodeEnhancedTestEngine extends HierarchicalTestEngine<JupiterEngineExecutionContext> {
5960

61+
public static final String ENHANCEMENT_EXTENSION_ENGINE_ENABLED = "hibernate.testing.bytecode.enhancement.extension.engine.enabled";
62+
63+
public static boolean isEnabled() {
64+
return "true".equalsIgnoreCase( System.getProperty( ENHANCEMENT_EXTENSION_ENGINE_ENABLED, "false" ) );
65+
}
66+
6067
@Override
6168
public String getId() {
6269
return "bytecode-enhanced-engine";
6370
}
6471

6572
@Override
6673
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
74+
if ( isEnabled() ) {
75+
return doDiscover( discoveryRequest, uniqueId );
76+
}
77+
78+
return new EngineDescriptor( uniqueId, getId() );
79+
}
80+
81+
public TestDescriptor doDiscover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
6782
final BytecodeEnhancedEngineDescriptor engineDescriptor = new BytecodeEnhancedEngineDescriptor(
6883
(JupiterEngineDescriptor) new JupiterTestEngine().discover( discoveryRequest, uniqueId )
6984
);
@@ -235,8 +250,12 @@ protected JupiterEngineExecutionContext createExecutionContext(ExecutionRequest
235250
}
236251

237252
private JupiterConfiguration getJupiterConfiguration(ExecutionRequest request) {
238-
JupiterEngineDescriptor engineDescriptor = (JupiterEngineDescriptor) request.getRootTestDescriptor();
239-
return engineDescriptor.getConfiguration();
253+
if ( request.getRootTestDescriptor() instanceof JupiterEngineDescriptor descriptor ) {
254+
return descriptor.getConfiguration();
255+
}
256+
else {
257+
return null;
258+
}
240259
}
241260

242261
public Optional<String> getGroupId() {

local-build-plugins/src/main/groovy/local.java-module.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dependencies {
5252
}
5353

5454
// JUnit dependencies made up of:
55-
// * JUnit 6
55+
// * JUnit (version 5 or later)
5656
// * the Jupiter engine which runs JUnit 6 based tests
5757
// * the "vintage" engine - which runs JUnit 3 and 4 based tests
5858
testImplementation testLibs.junitJupiterApi
@@ -212,6 +212,8 @@ tasks.withType( Test.class ).each { test ->
212212

213213
test.maxHeapSize = '3G'
214214

215+
// Enable bytecode enhanced engine:
216+
test.systemProperties['hibernate.testing.bytecode.enhancement.extension.engine.enabled'] = true
215217
test.systemProperties['hibernate.test.validatefailureexpected'] = true
216218
test.systemProperties['hibernate.highlight_sql'] = false
217219
test.systemProperties += System.properties.findAll { it.key.startsWith( "hibernate." ) }

test-case-guide.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There are a number of tenants that make up a good test case as opposed to a poor
1616
[[junit-jupiter]]
1717
== [[junit5]] JUnit Jupiter (6) extensions
1818

19-
JUnit 6 offers better support for integration, compared to JUnit 4, via https://junit.org/junit5/docs/current/user-guide/#extensions[extensions]. Hibernate builds on those concepts in its `hibernate-testing` module allowing set up of test fixtures using annotations. The following sections describe the Hibernate extensions.
19+
JUnit Jupiter offers better support for integration, compared to JUnit 4, via https://docs.junit.org/current/user-guide[extensions]. Hibernate builds on those concepts in its `hibernate-testing` module allowing set up of test fixtures using annotations. The following sections describe the Hibernate extensions.
2020

2121
NOTE: The extensions exist in the `org.hibernate.testing.orm.junit` package, as opposed to the older `org.hibernate.testing.junit4` package used with JUnit 4.
2222

@@ -29,7 +29,7 @@ Manages a `ServiceRegistry` as part of the test lifecycle. 2 in fact, depending
2929
`@BootstrapServiceRegistry`:: configures Hibernate's bootstrap `BootstrapServiceRegistry` which manages class-loading, etc. `@BootstrapServiceRegistry` is used to provide Java services and Hibernate `Integrator` implementations for the test.
3030
`@ServiceRegistry`:: configures Hibernate's standard `StandardServiceRegistry`. `@ServiceRegistry` is used to provide settings, contributors, services, etc.
3131

32-
Also exposes `ServiceRegistryScope` via JUnit 6 `ParameterResolver`. `ServiceRegistryScope` allows
32+
Also exposes `ServiceRegistryScope` via JUnit's `ParameterResolver`. `ServiceRegistryScope` allows
3333
access to the managed `ServiceRegistry` from tests and callbacks.
3434

3535
```

0 commit comments

Comments
 (0)