Skip to content

Commit 6d6e57a

Browse files
committed
HHH-19832 Disable BytecodeEnhancedTestEngine by default
1 parent aa4d85c commit 6d6e57a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
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,10 @@ 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".formatted( descriptor ) );
31+
}
2732
if ( root instanceof BytecodeEnhancedEngineDescriptor ) {
2833
if ( !isEnhanced ) {
2934
return FilterResult.excluded( "Not bytecode enhanced." );

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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." ) }

0 commit comments

Comments
 (0)