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 9, 2025
1 parent 524622a commit 3506f0f
Show file tree
Hide file tree
Showing 275 changed files with 12,141 additions and 6,715 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;
}
}
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/se/config/introduction.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

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 Down Expand Up @@ -248,7 +248,7 @@ You can retrieve a `ConfigValue<T>` using the following `as` methods in `Config`
ConfigValue<T> can be used to obtain:
* an `Optional<T>` value _from a single node_,
* the `T` value _from a single node_ interpreted as a basic Java type (primitive or simple object) already known to the config system (such as a `boolean` or a `Double`), or
* the `N` value _from a single node_ interpreted as a basic Java type (primitive or simple object) already known to the config system (such as a `boolean` or a `Double`), or
* a complex Java type _from a subtree_ of the config tree.
+
The config system automatically knows how to return `List` and `Map` complex types, and you can provide _config mappers_ to convert a config subtree to whatever
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/se/fault-tolerance.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2020, 2024 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 Down Expand Up @@ -93,7 +93,7 @@ The sample code above will retry calls to the supplier `this::retryOnFailure`
for up to 3 times with a 100-millisecond delay between them.
NOTE: The return type of method `retryOnFailure` in the example above must
be some `T` and the parameter to the retry handler's `invoke`
be some `N` and the parameter to the retry handler's `invoke`
method `Supplier<? extends T>`.
If the call to the supplier provided completes exceptionally, it will be treated as
Expand Down Expand Up @@ -130,7 +130,7 @@ we may fall back to the last result obtained from that service at an
earlier time.
A `Fallback` instance is created by providing a function that takes a `Throwable`
and produces some `T` to be used when the intended method failed to return a value:
and produces some `N` to be used when the intended method failed to return a value:
[source,java]
----
Expand Down Expand Up @@ -219,7 +219,7 @@ being at maximum capacity.
=== Asynchronous
Asynchronous tasks can be created or forked by using an `Async` instance. A supplier of type
`T` is provided as the argument when invoking this handler. For example:
`N` is provided as the argument when invoking this handler. For example:
[source,java]
----
Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/se/guides/upgrade.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2020, 2024 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 Down Expand Up @@ -30,7 +30,7 @@ include::{rootdir}/includes/guides/upgrade.adoc[]
== Getters
Some methods that act as getters of type `T` have been modified to return `Optional<T>`. You will
Some methods that act as getters of type `N` have been modified to return `Optional<T>`. You will
need to change your code to handle the `Optional` return type. For example `ServerRequest.spanContext()`
in 1.x had a return type of `SpanContext`. In 2.x it has a return type of `Optional<SpanContext>`.
So if you had code like:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/se/sse.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2023, 2024 Oracle and/or its affiliates.
Copyright (c) 2023, 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 @@ -143,7 +143,7 @@ include::{sourcedir}/se/SseSnippets.java[tag=snippet_4, indent=0]
----
The `SseSource` type defines other methods such as `onOpen`, `onClose` and `onError`. The following example
waits for zero or more string events until the connection is closed. A `CountDownLatch` is a convenient
waits for zero or more string events until the connection is closed. A `MaskingLatch` is a convenient
way to asynchronously wait until all the events are received.
[source,java]
Expand Down
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) 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 Down Expand Up @@ -43,6 +43,7 @@
import org.eclipse.microprofile.lra.annotation.LRAStatus;
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
Expand All @@ -54,6 +55,7 @@
@AddBean(TestLraCoordinator.class)
@AddExtension(LraCdiExtension.class)
@AddExtension(ConfigCdiExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Path("/test/internal")
public class LraDisabledDiscoveryResourceTest {

Expand Down
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 Down Expand Up @@ -45,6 +45,7 @@
import org.eclipse.microprofile.lra.annotation.LRAStatus;
import org.eclipse.microprofile.lra.annotation.ws.rs.LRA;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
Expand All @@ -55,6 +56,7 @@
@AddConfig(key = "server.sockets.0.port", value = "0")
@AddConfig(key = "server.sockets.0.bind-address", value = "localhost")
@AddBean(TestLraCoordinator.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@Path("/test/multi-port")
public class LraMultiPortTest {

Expand Down
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 Down Expand Up @@ -34,6 +34,7 @@
import org.eclipse.microprofile.reactive.messaging.Outgoing;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import static io.helidon.messaging.connectors.mock.MockConnector.CONNECTOR_NAME;
import static org.eclipse.microprofile.reactive.messaging.spi.ConnectorFactory.INCOMING_PREFIX;
Expand All @@ -54,6 +55,7 @@
@AddConfig(key = INCOMING_PREFIX + "test-channel-5.mock-data-type", value = "java.lang.Long")
@AddConfig(key = INCOMING_PREFIX + "test-channel-5.mock-data", value = "9,10,11,12")
@AddConfig(key = OUTGOING_PREFIX + "test-channel-6.connector", value = CONNECTOR_NAME)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class MockConnectorTest {

private static final Duration TIMEOUT = Duration.ofSeconds(5);
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,13 +42,10 @@

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

static final long TWO_SEC_MILLIS = 2 * 1000L;
Expand Down
Loading

0 comments on commit 3506f0f

Please sign in to comment.