From 29568ba18621516fc8b1d0b7125d5a802b92bc40 Mon Sep 17 00:00:00 2001 From: Holly Cummins Date: Thu, 19 Dec 2024 10:43:11 +0000 Subject: [PATCH] Sort out GRPC regression by having orderer --- .../test/config/QuarkusClassOrderer.java | 47 ++++++++++++++----- .../QuarkusTestProfileAwareClassOrderer.java | 1 + 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/test-framework/junit5-config/src/main/java/io/quarkus/test/config/QuarkusClassOrderer.java b/test-framework/junit5-config/src/main/java/io/quarkus/test/config/QuarkusClassOrderer.java index 38e4b2d408602..5c0c728c34a19 100644 --- a/test-framework/junit5-config/src/main/java/io/quarkus/test/config/QuarkusClassOrderer.java +++ b/test-framework/junit5-config/src/main/java/io/quarkus/test/config/QuarkusClassOrderer.java @@ -1,9 +1,13 @@ package io.quarkus.test.config; +import java.util.NoSuchElementException; + import org.eclipse.microprofile.config.ConfigProvider; import org.junit.jupiter.api.ClassOrderer; import org.junit.jupiter.api.ClassOrdererContext; +import org.junit.platform.commons.util.ReflectionUtils; +import io.quarkus.deployment.dev.testing.TestConfig; import io.smallrye.config.SmallRyeConfig; /** @@ -11,25 +15,42 @@ * config. */ public class QuarkusClassOrderer implements ClassOrderer { - private final ClassOrderer delegate; + // TODO reinstate final + private ClassOrderer delegate; public QuarkusClassOrderer() { System.out.println("HOLLY class orderer TCCL is " + Thread.currentThread().getContextClassLoader()); System.out.println("HOLLY I AM " + this.getClass().getClassLoader()); - ClassLoader original = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + // ClassLoader original = Thread.currentThread().getContextClassLoader(); + // Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class); + // TODO obviously a bad idea, diagnostic - delegate = EMPTY; - // TestConfig testConfig = config.getConfigMapping(TestConfig.class); - // - // delegate = testConfig.classOrderer() - // .map(klass -> ReflectionUtils.tryToLoadClass(klass) - // .andThenTry(ReflectionUtils::newInstance) - // .andThenTry(instance -> (ClassOrderer) instance) - // .toOptional().orElse(EMPTY)) - // .orElse(EMPTY); - Thread.currentThread().setContextClassLoader(original); + // delegate = EMPTY; + + try { + TestConfig testConfig = config.getConfigMapping(TestConfig.class); + + delegate = testConfig.classOrderer() + .map(klass -> ReflectionUtils.tryToLoadClass(klass) + .andThenTry(ReflectionUtils::newInstance) + .andThenTry(instance -> (ClassOrderer) instance) + .toOptional() + .orElse(EMPTY)) + .orElse(EMPTY); + } catch (NoSuchElementException e) { + e.printStackTrace(); + // TODO this is a huge hack, fix this + // FIXME On the gradle tests, and maybe some others, the config is not there + System.out.println("HOLLY BAD BAD could not get config mapping for orderer, hardcoding a default"); + String klass = "io.quarkus.test.junit.util.QuarkusTestProfileAwareClassOrderer"; + delegate = ReflectionUtils.tryToLoadClass(klass) + .andThenTry(ReflectionUtils::newInstance) + .andThenTry(instance -> (ClassOrderer) instance) + .toOptional() + .orElse(EMPTY); + } + // Thread.currentThread().setContextClassLoader(original); } @Override diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java index 69778c36a348b..3409fc8de82aa 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java @@ -106,6 +106,7 @@ public QuarkusTestProfileAwareClassOrderer() { @Override public void orderClasses(ClassOrdererContext context) { + System.out.println("HOLLY YUP YUP ordering classes"); // don't do anything if there is just one test class or the current order request is for @Nested tests if (context.getClassDescriptors() .size() <= 1 || context.getClassDescriptors()