Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugging/tracing for PublicFieldAccessInheritanceTest #43074

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci-actions-incremental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ jobs:
path: |
build-reports.zip
retention-days: 7
- name: Upload test-produced debug dumps
uses: actions/upload-artifact@v4
# We need this as soon as there's a matching file
# -- even in case of success, as some flaky tests won't fail the build
if: always()
with:
name: "debug-${{ github.run_attempt }}-JVM Tests - JDK ${{matrix.java.name}}"
path: "**/target/debug/**"
if-no-files-found: ignore # If we're not currently debugging any test, it's fine.
retention-days: 28 # We don't get notified for flaky tests, so let's give maintainers time to get back to it
- name: Upload build.log (if build failed)
uses: actions/upload-artifact@v4
if: ${{ failure() || cancelled() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public GeneratedClassGizmoAdaptor(BuildProducer<GeneratedClassBuildItem> generat
Predicate<String> applicationClassPredicate) {
this.generatedClasses = generatedClasses;
this.applicationClassPredicate = applicationClassPredicate;
this.sources = BootstrapDebug.DEBUG_SOURCES_DIR != null ? new ConcurrentHashMap<>() : null;
this.sources = BootstrapDebug.debugSourcesDir() != null ? new ConcurrentHashMap<>() : null;
}

public GeneratedClassGizmoAdaptor(BuildProducer<GeneratedClassBuildItem> generatedClasses,
Expand All @@ -44,7 +44,7 @@ public boolean test(String s) {
return isApplicationClass(generatedToBaseNameFunction.apply(s));
}
};
this.sources = BootstrapDebug.DEBUG_SOURCES_DIR != null ? new ConcurrentHashMap<>() : null;
this.sources = BootstrapDebug.debugSourcesDir() != null ? new ConcurrentHashMap<>() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ private byte[] transformClass(String className, List<BiFunction<String, ClassVis
} else {
data = classData;
}
if (BootstrapDebug.DEBUG_TRANSFORMED_CLASSES_DIR != null) {
File debugPath = new File(BootstrapDebug.DEBUG_TRANSFORMED_CLASSES_DIR);
var debugTransformedClassesDir = BootstrapDebug.transformedClassesDir();
if (debugTransformedClassesDir != null) {
File debugPath = new File(debugTransformedClassesDir);
if (!debugPath.exists()) {
debugPath.mkdir();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private Map<Path, List<SbomResult>> getSboms(List<SbomBuildItem> sbomBuildItems)
}

private void writeDebugSourceFile(BuildResult result) {
String debugSourcesDir = BootstrapDebug.DEBUG_SOURCES_DIR;
String debugSourcesDir = BootstrapDebug.debugSourcesDir();
if (debugSourcesDir != null) {
for (GeneratedClassBuildItem i : result.consumeMulti(GeneratedClassBuildItem.class)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,10 @@ private static Map<String, byte[]> extractGeneratedResources(BuildResult buildRe
for (GeneratedClassBuildItem i : buildResult.consumeMulti(GeneratedClassBuildItem.class)) {
if (i.isApplicationClass() == applicationClasses) {
data.put(fromClassNameToResourceName(i.getName()), i.getClassData());
if (BootstrapDebug.DEBUG_CLASSES_DIR != null) {
var debugClassesDir = BootstrapDebug.debugClassesDir();
if (debugClassesDir != null) {
try {
File debugPath = new File(BootstrapDebug.DEBUG_CLASSES_DIR);
File debugPath = new File(debugClassesDir);
if (!debugPath.exists()) {
debugPath.mkdir();
}
Expand All @@ -409,7 +410,7 @@ private static Map<String, byte[]> extractGeneratedResources(BuildResult buildRe
}
}

String debugSourcesDir = BootstrapDebug.DEBUG_SOURCES_DIR;
String debugSourcesDir = BootstrapDebug.debugSourcesDir();
if (debugSourcesDir != null) {
try {
if (i.getSource() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public boolean test(BeanInfo bean) {
builder.setTransformPrivateInjectedFields(arcConfig.transformPrivateInjectedFields);
builder.setFailOnInterceptedPrivateMethod(arcConfig.failOnInterceptedPrivateMethod);
builder.setJtaCapabilities(capabilities.isPresent(Capability.TRANSACTIONS));
builder.setGenerateSources(BootstrapDebug.DEBUG_SOURCES_DIR != null);
builder.setGenerateSources(BootstrapDebug.debugSourcesDir() != null);
builder.setAllowMocking(launchModeBuildItem.getLaunchMode() == LaunchMode.TEST);
builder.setStrictCompatibility(arcConfig.strictCompatibility);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GeneratedBeanGizmoAdaptor implements ClassOutput {

public GeneratedBeanGizmoAdaptor(BuildProducer<GeneratedBeanBuildItem> classOutput) {
this.classOutput = classOutput;
this.sources = BootstrapDebug.DEBUG_SOURCES_DIR != null ? new ConcurrentHashMap<>() : null;
this.sources = BootstrapDebug.debugSourcesDir() != null ? new ConcurrentHashMap<>() : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.LogManager;

import jakarta.inject.Inject;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager;
Expand All @@ -16,6 +21,7 @@
import jakarta.transaction.UserTransaction;

import org.hibernate.Hibernate;
import org.jboss.logmanager.Level;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -27,14 +33,51 @@
*/
public class PublicFieldAccessInheritanceTest {

// FIXME Temporary debug options for https://github.com/quarkusio/quarkus/issues/42479
// Needs to be set very early (e.g. as system properties) in order to affect the build;
// see https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Build.20logs
private static final Map<String, String> DEBUG_PROPERTIES = Map.of(
"quarkus.debug.transformed-classes-dir", "target/debug/${testRunId}/transformed-classes",
"quarkus.debug.generated-classes-dir", "target/debug/${testRunId}/generated-classes");
// FIXME Temporary trace categories for https://github.com/quarkusio/quarkus/issues/42479
// Needs to be set very early (e.g. programmatically) in order to affect the build;
// needs to be set programmatically in order to not leak to other tests.
// See https://quarkusio.zulipchat.com/#narrow/stream/187038-dev/topic/Build.20logs
// See https://github.com/quarkusio/quarkus/issues/43180
private static final List<String> TRACE_CATEGORIES = List.of("org.hibernate", "io.quarkus.hibernate", "io.quarkus.panache");

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClass(MyMappedSuperclass.class)
.addClass(MyAbstractEntity.class)
.addClass(MyConcreteEntity.class)
.addClass(FieldAccessEnhancedDelegate.class))
.withConfigurationResource("application.properties");
.withConfigurationResource("application.properties")
// FIXME Temporary debug options for https://github.com/quarkusio/quarkus/issues/42479
.overrideConfigKey("quarkus.hibernate-orm.log.sql", "true")
// Not doing this because it has side effects on other tests for some reason;
// see https://github.com/quarkusio/quarkus/issues/43180
// It's not necessary anyway as the only effect of this config property is to change
// the logging level for a specific "org.hibernate.something" category, which we already do below.
//.overrideConfigKey("quarkus.hibernate-orm.log.bind-parameters", "true")
.setBeforeAllCustomizer(() -> {
// Used to differentiate reruns of flaky tests in Maven
var testRunId = PublicFieldAccessInheritanceTest.class + "/" + UUID.randomUUID();
System.out.println("Test run ID: " + testRunId);
DEBUG_PROPERTIES.forEach((key, value) -> System.setProperty(key, value.replace("${testRunId}", testRunId)));
for (String category : TRACE_CATEGORIES) {
LogManager.getLogManager().getLogger(category)
.setLevel(Level.TRACE);
}
})
.setAfterAllCustomizer(() -> {
DEBUG_PROPERTIES.keySet().forEach(System::clearProperty);
for (String category : TRACE_CATEGORIES) {
LogManager.getLogManager().getLogger(category)
.setLevel(null);
}
});

@Inject
EntityManager em;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,39 @@

public final class BootstrapDebug {

public static final String DEBUG_SOURCES_DIR = System.getProperty("quarkus.debug.generated-sources-dir");

/**
* @deprecated Use {@link #debugClassesDir()} instead for more flexibility when testing.
*/
@Deprecated
public static final String DEBUG_CLASSES_DIR = System.getProperty("quarkus.debug.generated-classes-dir");

/**
* @deprecated Use {@link #transformedClassesDir()} instead for more flexibility when testing.
*/
@Deprecated
public static final String DEBUG_TRANSFORMED_CLASSES_DIR = System.getProperty("quarkus.debug.transformed-classes-dir");

/**
* @deprecated Use {@link #debugSourcesDir()} instead for more flexibility when testing.
*/
@Deprecated
public static final String DEBUG_SOURCES_DIR = System.getProperty("quarkus.debug.generated-sources-dir");

// We're exposing the configuration properties as methods and not constants,
// because in the case of tests, the system property could change over the life of the JVM.

public static String debugClassesDir() {
return System.getProperty("quarkus.debug.generated-classes-dir");
}

public static String transformedClassesDir() {
return System.getProperty("quarkus.debug.transformed-classes-dir");
}

public static String debugSourcesDir() {
return System.getProperty("quarkus.debug.generated-sources-dir");
}

private BootstrapDebug() {
}

Expand Down
Loading