Skip to content

Commit

Permalink
Improved Helidon MP testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-grecourt committed Jan 15, 2025
1 parent 524622a commit 34e3ca2
Show file tree
Hide file tree
Showing 266 changed files with 12,909 additions and 6,743 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04 ]
moduleSet: [ core, it, dbclient, dbclient-oracle, others ]
moduleSet: [ core, it, jpa, jpa-oracle, dbclient, dbclient-oracle, others ]
include:
- { os: ubuntu-20.04, platform: linux }
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,11 @@
<artifactId>helidon-common-testing-virtual-threads</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-junit5</artifactId>
Expand Down
5 changes: 3 additions & 2 deletions common/testing/virtual-threads/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
* Copyright (c) 2024, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,8 @@
module io.helidon.common.testing.vitualthreads {
requires jdk.jfr;
exports io.helidon.common.testing.virtualthreads to
io.helidon.microprofile.testing,
io.helidon.microprofile.testing.junit5,
io.helidon.microprofile.testing.testng,
io.helidon.webserver.testing.junit5;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024 Oracle and/or its affiliates.
* Copyright (c) 2018, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
import java.util.stream.Stream;

import io.helidon.microprofile.testing.junit5.AddBean;
Expand All @@ -36,17 +37,18 @@
*/
@AddBean(RetryBean.class)
@AddBean(SyntheticRetryBean.class)
public class RetryTest extends FaultToleranceTest {
class RetryTest extends FaultToleranceTest {

static Stream<Arguments> createBeans() {
return Stream.of(
Arguments.of(newBean(RetryBean.class), "ManagedRetryBean"),
Arguments.of(newNamedBean(SyntheticRetryBean.class), "SyntheticRetryBean"));
Arguments.of((Supplier<RetryBean>) () -> newBean(RetryBean.class), "ManagedRetryBean"),
Arguments.of((Supplier<RetryBean>) () -> newNamedBean(SyntheticRetryBean.class), "SyntheticRetryBean"));
}

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryBean(RetryBean bean, String unused) {
void testRetryBean(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
assertThat(bean.getInvocations(), is(0));
bean.retry();
Expand All @@ -55,7 +57,8 @@ public void testRetryBean(RetryBean bean, String unused) {

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryBeanFallback(RetryBean bean, String unused) {
void testRetryBeanFallback(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
assertThat(bean.getInvocations(), is(0));
String value = bean.retryWithFallback();
Expand All @@ -65,7 +68,8 @@ public void testRetryBeanFallback(RetryBean bean, String unused) {

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryAsync(RetryBean bean, String unused) throws Exception {
void testRetryAsync(Supplier<RetryBean> supplier, String unused) throws Exception {
RetryBean bean = supplier.get();
bean.reset();
CompletableFuture<String> future = bean.retryAsync();
future.get();
Expand All @@ -74,7 +78,8 @@ public void testRetryAsync(RetryBean bean, String unused) throws Exception {

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryWithDelayAndJitter(RetryBean bean, String unused) throws Exception {
void testRetryWithDelayAndJitter(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
long millis = System.currentTimeMillis();
bean.retryWithDelayAndJitter();
Expand All @@ -84,13 +89,13 @@ public void testRetryWithDelayAndJitter(RetryBean bean, String unused) throws Ex
/**
* Inspired by a TCK test which makes sure failed executions propagate correctly.
*
* @param bean the bean to invoke
* @param supplier supplier of the bean to invoke
* @param unused bean name to use for the specific test invocation
* @throws Exception
*/
@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryWithException(RetryBean bean, String unused) throws Exception {
void testRetryWithException(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
CompletionStage<String> future = bean.retryWithException();
assertCompleteExceptionally(future.toCompletableFuture(), IOException.class, "Simulated error");
Expand All @@ -99,15 +104,17 @@ public void testRetryWithException(RetryBean bean, String unused) throws Excepti

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryCompletionStageWithEventualSuccess(RetryBean bean, String unused) {
void testRetryCompletionStageWithEventualSuccess(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
assertCompleteOk(bean.retryWithUltimateSuccess(), "success");
assertThat(bean.getInvocations(), is(3));
}

@ParameterizedTest(name = "{1}")
@MethodSource("createBeans")
public void testRetryWithCustomRuntimeException(RetryBean bean, String unused) {
void testRetryWithCustomRuntimeException(Supplier<RetryBean> supplier, String unused) {
RetryBean bean = supplier.get();
bean.reset();
assertThat(bean.getInvocations(), is(0));
assertCompleteOk(bean.retryOnCustomRuntimeException(), "success");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Copyright (c) 2021, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,6 +52,7 @@
import io.helidon.microprofile.testing.junit5.AddBean;
import io.helidon.microprofile.testing.junit5.AddConfig;
import io.helidon.microprofile.testing.junit5.AddExtension;
import io.helidon.microprofile.testing.junit5.AddJaxRs;
import io.helidon.microprofile.testing.junit5.DisableDiscovery;
import io.helidon.microprofile.testing.junit5.HelidonTest;
import io.helidon.webclient.http1.Http1Client;
Expand All @@ -66,11 +67,11 @@
import jakarta.ws.rs.core.UriBuilder;
import org.eclipse.microprofile.lra.annotation.LRAStatus;
import org.eclipse.microprofile.lra.annotation.ParticipantStatus;
import org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -88,11 +89,9 @@
*/
@HelidonTest
@DisableDiscovery
@AddJaxRs
// Helidon MP
@AddExtension(ConfigCdiExtension.class)
@AddExtension(ServerCdiExtension.class)
@AddExtension(JaxRsCdiExtension.class)
@AddExtension(CdiComponentProvider.class)
// LRA client
@AddExtension(LraCdiExtension.class)
// resources
Expand Down Expand Up @@ -126,6 +125,7 @@
@AddConfig(key = "server.sockets.2.name", value = CoordinatorClusterDeploymentService.COORDINATOR_B_NAME)
@AddConfig(key = "server.sockets.2.port", value = "0")
@AddConfig(key = "server.sockets.2.bind-address", value = "localhost")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class LoadBalancedCoordinatorTest {

private static final System.Logger LOGGER = System.getLogger(LoadBalancedCoordinatorTest.class.getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
* Copyright (c) 2021, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,9 +24,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import io.helidon.microprofile.testing.junit5.AddBean;
import io.helidon.microprofile.testing.junit5.AddBeans;
import io.helidon.microprofile.testing.junit5.AddExtension;
import io.helidon.microprofile.testing.junit5.AddExtensions;
import io.helidon.microprofile.testing.junit5.Configuration;
import io.helidon.microprofile.testing.junit5.DisableDiscovery;
import io.helidon.microprofile.testing.junit5.HelidonTest;
Expand All @@ -35,6 +33,7 @@

import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -43,12 +42,8 @@

@HelidonTest
@DisableDiscovery
@AddBeans({
@AddBean(ScheduledBean.class)
})
@AddExtensions({
@AddExtension(SchedulingCdiExtension.class),
})
@AddBean(ScheduledBean.class)
@AddExtension(SchedulingCdiExtension.class)
@Configuration(configSources = "test.properties")
public class SchedulingTest {

Expand Down
11 changes: 7 additions & 4 deletions microprofile/testing/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
</description>

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.server</groupId>
<artifactId>helidon-microprofile-server</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.helidon.common.testing</groupId>
Expand All @@ -50,7 +54,7 @@
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -67,9 +71,8 @@
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,37 +17,45 @@

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.context.ApplicationScoped;

/**
* Add a bean.
* This is intended for test sources where we do not want to add {@code beans.xml} as this would add
* all test classes as beans.
* The bean will be added by default with {@link jakarta.enterprise.context.ApplicationScoped}.
* The class will be instantiated using CDI and will be available for injection into test classes and other beans.
* Add a CDI bean to the container.
* <p>
* This annotation can be repeated.
* <p>
* If used on a method, the container will be reset regardless of the test lifecycle.
* <p>
* The bean scope is defined as follows:
* <ul>
* <li>If a scope is set with {@link #value()}, it overrides any scope defined on the bean</li>
* <li>Otherwise, the scope defined on the bean is used</li>
* <li>If the bean does not define a scope, {@link jakarta.enterprise.context.ApplicationScoped ApplicationScoped}
* is used</li>
* </ul>
* @deprecated Use {@link io.helidon.microprofile.testing.AddBean} instead
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Repeatable(AddBeans.class)
@Deprecated(since = "4.2.0")
public @interface AddBean {
/**
* Class of the bean.
* @return the class of a bean
* The bean class.
*
* @return bean class
*/
Class<?> value();

/**
* Scope of the bean.
* Only {@link jakarta.inject.Singleton}, {@link jakarta.enterprise.context.ApplicationScoped}
* and {@link jakarta.enterprise.context.RequestScoped} scopes are supported.
* Override the bean scope.
*
* @return scope of the bean
* @return scope class
*/
Class<? extends Annotation> scope() default ApplicationScoped.class;
Class<? extends Annotation> scope() default Annotation.class;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,21 +16,34 @@
package io.helidon.microprofile.testing.junit5;

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

/**
* A repeatable container for {@link io.helidon.microprofile.testing.junit5.AddBean}.
* No need to use this annotation, just repeat {@link io.helidon.microprofile.testing.junit5.AddBean} annotation
* on test class.
* A repeatable container for {@link AddBean}.
* <p>
* This annotation is optional, you can instead repeat {@link AddBean}.
* <p>
* E.g.
* <pre>
* &#64;AddBean(FooBean.class)
* &#64;AddBean(BarBean.class)
* class MyTest {
* }
* </pre>
* @deprecated Use {@link io.helidon.microprofile.testing.AddBeans} instead
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Deprecated(since = "4.2.0")
public @interface AddBeans {
/**
* Beans to be added.
* @return add bean annotations
* Get the contained annotations.
*
* @return annotations
*/
AddBean[] value();
}
Loading

0 comments on commit 34e3ca2

Please sign in to comment.