Skip to content

Commit

Permalink
Sort out GRPC regression by having orderer
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Dec 19, 2024
1 parent 66daf33 commit 29568ba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
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;

/**
* A JUnit {@link ClassOrderer}, used to delegate to a custom implementations of {@link ClassOrderer} set by Quarkus
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 29568ba

Please sign in to comment.