Skip to content

Commit

Permalink
Merge pull request #24767 from zakkak/fix-it-main-22.1
Browse files Browse the repository at this point in the history
Fix IT main for GraalVM >= 22.1
  • Loading branch information
geoand authored Apr 8, 2022
2 parents 4481bf0 + bc90454 commit b2700d0
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.quarkus.it.corestuff.serialization;

import java.util.ArrayList;
import java.util.List;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection(targets = { List.class, ArrayList.class, String.class }, serialization = true)
@RegisterForReflection(targets = { ArrayList.class, String.class }, serialization = true)
public class SerializationConfig {

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.DisableIfBuiltWithGraalVMNewerThan;
import io.quarkus.test.junit.DisableIfBuiltWithGraalVMOlderThan;
import io.quarkus.test.junit.GraalVMVersion;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;

Expand Down Expand Up @@ -35,7 +38,20 @@ public void testSelfWithNested() {
}

@Test
public void testTargetWithNested() {
@DisableIfBuiltWithGraalVMOlderThan(GraalVMVersion.GRAALVM_22_1)
public void testTargetWithNestedPost22_1() {
final String resourceC = BASE_PKG + ".ResourceC";

// Starting with GraalVM 22.1 ResourceC implicitly gets registered by GraalVM
// (see https://github.com/oracle/graal/pull/4414)
assertRegistration("ResourceC", resourceC);
assertRegistration("InaccessibleClassOfC", resourceC + "$InaccessibleClassOfC");
assertRegistration("OtherInaccessibleClassOfC", resourceC + "$InaccessibleClassOfC$OtherInaccessibleClassOfC");
}

@Test
@DisableIfBuiltWithGraalVMNewerThan(GraalVMVersion.GRAALVM_22_0)
public void testTargetWithNestedPre22_1() {
final String resourceC = BASE_PKG + ".ResourceC";

assertRegistration("FAILED", resourceC);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.test.junit;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Used to signal that a test class or method should be disabled if the version of GraalVM used to build the native binary
* under test was older than the supplied version.
*
* This annotation should only be used on a test classes annotated with {@link NativeImageTest} or
* {@link QuarkusIntegrationTest}. If it is used on other test classes, it will have no effect.
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisableIfBuiltWithGraalVMNewerThanCondition.class)
public @interface DisableIfBuiltWithGraalVMNewerThan {
GraalVMVersion value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.quarkus.test.junit;

import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties;
import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

public class DisableIfBuiltWithGraalVMNewerThanCondition implements ExecutionCondition {

private static final String QUARKUS_INTEGRATION_TEST_NAME = QuarkusIntegrationTest.class.getName();
private static final String NATIVE_IMAGE_TEST_NAME = NativeImageTest.class.getName();
private static final Set<String> SUPPORTED_INTEGRATION_TESTS = Set.of(QUARKUS_INTEGRATION_TEST_NAME,
NATIVE_IMAGE_TEST_NAME);

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<AnnotatedElement> element = context.getElement();
Optional<DisableIfBuiltWithGraalVMNewerThan> optional = findAnnotation(element,
DisableIfBuiltWithGraalVMNewerThan.class);
if (!optional.isPresent()) {
return ConditionEvaluationResult.enabled("@DisableIfBuiltWithGraalVMNewerThan was not found");
}
if (!isIntegrationTest(context.getRequiredTestClass())) {
return ConditionEvaluationResult.enabled("@DisableIfBuiltWithGraalVMNewerThan was added to an unsupported test");
}

GraalVMVersion annotationValue = optional.get().value();
Properties quarkusArtifactProperties = readQuarkusArtifactProperties(context);
try {
org.graalvm.home.Version version = org.graalvm.home.Version
.parse(quarkusArtifactProperties.getProperty("metadata.graalvm.version.version"));
int comparison = annotationValue.compareTo(version);
if (comparison < 0) {
return ConditionEvaluationResult.disabled("Native binary was built with GraalVM{version=" + version.toString()
+ "} but the test is disabled for GraalVM versions newer than " + annotationValue);
}
return ConditionEvaluationResult
.enabled("Native binary was built with a GraalVM version compatible with the required version by the test");
} catch (NumberFormatException e) {
return ConditionEvaluationResult
.disabled("Unable to determine the GraalVM version with which the native binary was built");
}
}

private boolean isIntegrationTest(Class<?> testClass) {
do {
Annotation[] annotations = testClass.getAnnotations();
for (Annotation annotation : annotations) {
Class<? extends Annotation> annotationType = annotation.annotationType();
String annotationTypeName = annotationType.getName();
if (SUPPORTED_INTEGRATION_TESTS.contains(annotationTypeName)) {
return true;
}
}
testClass = testClass.getSuperclass();
} while (testClass != Object.class);
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,5 @@
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisableIfBuiltWithGraalVMOlderThanCondition.class)
public @interface DisableIfBuiltWithGraalVMOlderThan {

GraalVMVersion value();

enum GraalVMVersion {
GRAALVM_21_0(org.graalvm.home.Version.create(21, 0));

private final org.graalvm.home.Version version;

GraalVMVersion(org.graalvm.home.Version version) {
this.version = version;
}

public org.graalvm.home.Version getVersion() {
return version;
}

/**
* Compares this version with another GraalVM version
*
* @return {@code -1} if this version is older than the other version,
* {@code +1} if it's newer and {@code 0} if they represent the same version
*/
public int compareTo(org.graalvm.home.Version version) {
return this.version.compareTo(version);
}

@Override
public String toString() {
return "GraalVMVersion{" +
"version=" + version.toString() +
'}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
Expand All @@ -20,8 +17,8 @@ public class DisableIfBuiltWithGraalVMOlderThanCondition implements ExecutionCon

private static final String QUARKUS_INTEGRATION_TEST_NAME = QuarkusIntegrationTest.class.getName();
private static final String NATIVE_IMAGE_TEST_NAME = NativeImageTest.class.getName();
private static final Set<String> SUPPORTED_INTEGRATION_TESTS = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList(QUARKUS_INTEGRATION_TEST_NAME, NATIVE_IMAGE_TEST_NAME)));
private static final Set<String> SUPPORTED_INTEGRATION_TESTS = Set.of(QUARKUS_INTEGRATION_TEST_NAME,
NATIVE_IMAGE_TEST_NAME);

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Expand All @@ -35,7 +32,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
return ConditionEvaluationResult.enabled("@DisableIfBuiltWithGraalVMOlderThan was added to an unsupported test");
}

DisableIfBuiltWithGraalVMOlderThan.GraalVMVersion annotationValue = optional.get().value();
GraalVMVersion annotationValue = optional.get().value();
Properties quarkusArtifactProperties = readQuarkusArtifactProperties(context);
try {
org.graalvm.home.Version version = org.graalvm.home.Version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.test.junit;

public enum GraalVMVersion {
GRAALVM_21_0(org.graalvm.home.Version.create(21, 0)),
GRAALVM_22_0(org.graalvm.home.Version.create(22, 0)),
GRAALVM_22_1(org.graalvm.home.Version.create(22, 1));

private final org.graalvm.home.Version version;

GraalVMVersion(org.graalvm.home.Version version) {
this.version = version;
}

public org.graalvm.home.Version getVersion() {
return version;
}

/**
* Compares this version with another GraalVM version
*
* @return {@code -1} if this version is older than the other version,
* {@code +1} if it's newer and {@code 0} if they represent the same version
*/
public int compareTo(org.graalvm.home.Version version) {
return this.version.compareTo(version);
}

@Override
public String toString() {
return "GraalVMVersion{" +
"version=" + version.toString() +
'}';
}
}

0 comments on commit b2700d0

Please sign in to comment.