From 89f41383e51144178567a3fa5bf09fe6131f44c2 Mon Sep 17 00:00:00 2001 From: tvallin Date: Thu, 14 Nov 2024 16:03:25 +0100 Subject: [PATCH] Fix jlink packaging test --- .github/actions/common/action.yml | 2 +- .github/workflows/validate.yml | 7 +--- .../io/helidon/inject/tools/ModuleUtils.java | 5 ++- .../telemetry/TestTracerAtStartup.java | 3 ++ .../telemetry/InMemorySpanExporter.java | 18 ++++----- .../InMemorySpanExporterProvider.java | 6 +-- .../telemetry/RestSpanHierarchyTest.java | 38 ++++++++----------- .../telemetry/TestFullUrlName.java | 17 ++++----- .../integration/harness/ProcessRunner.java | 13 ++++++- .../packaging/inject/InjectJlinkTestIT.java | 4 -- .../packaging/mp1/Mp1JlinkTestIT.java | 3 -- .../packaging/mp3/Mp3JlinkTestIT.java | 4 -- .../packaging/se1/Se1JlinkTestIT.java | 4 -- 13 files changed, 56 insertions(+), 68 deletions(-) diff --git a/.github/actions/common/action.yml b/.github/actions/common/action.yml index ddb043049bc..122ce62a049 100644 --- a/.github/actions/common/action.yml +++ b/.github/actions/common/action.yml @@ -141,7 +141,7 @@ runs: shell: bash - name: Archive test results # https://github.com/actions/upload-artifact/issues/240 - if: ${{ inputs.test-artifact-name != '' && runner.os != 'Windows' && always() }} + if: ${{ inputs.test-artifact-name != '' && always() }} uses: actions/upload-artifact@v4 with: if-no-files-found: 'ignore' diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index fd618851f78..21c4aff6ea8 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -78,10 +78,7 @@ jobs: run: etc/scripts/shellcheck.sh build: timeout-minutes: 15 - strategy: - matrix: - os: [ ubuntu-20.04, windows-2022 ] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 with: @@ -116,7 +113,7 @@ jobs: - uses: ./.github/actions/common with: build-cache: read-only - test-artifact-name: tests-${{ matrix.moduleSet }} + test-artifact-name: tests-${{ matrix.moduleSet }}-${{ matrix.platform }} run: | mvn ${MAVEN_ARGS} \ -DreactorRule=tests \ diff --git a/inject/tools/src/main/java/io/helidon/inject/tools/ModuleUtils.java b/inject/tools/src/main/java/io/helidon/inject/tools/ModuleUtils.java index d5d9ad48edd..29aaff42555 100644 --- a/inject/tools/src/main/java/io/helidon/inject/tools/ModuleUtils.java +++ b/inject/tools/src/main/java/io/helidon/inject/tools/ModuleUtils.java @@ -68,8 +68,8 @@ public class ModuleUtils { public static final String APPLICATION_PACKAGE_FILE_NAME = "app-package-name.txt"; static final System.Logger LOGGER = System.getLogger(ModuleUtils.class.getName()); static final String SERVICE_PROVIDER_MODULE_INFO_HBS = "module-info.hbs"; - static final String SRC_MAIN_JAVA_DIR = File.separator + "src" + File.separator + "main" + File.separator + "java"; - static final String SRC_TEST_JAVA_DIR = File.separator + "src" + File.separator + "test" + File.separator + "java"; + static final String SRC_MAIN_JAVA_DIR = "/src/main/java"; + static final String SRC_TEST_JAVA_DIR = "/src/test/java"; static final ModuleInfoItem MODULE_COMPONENT_MODULE_INFO = ModuleInfoItem.builder() .provides(true) .target(ModuleComponent.class.getName()) @@ -354,6 +354,7 @@ public static Optional toSourcePath(Path filePath, * @return the base path */ public static Path toBasePath(String sourcePath) { + sourcePath = sourcePath.replace(File.separator, "/"); int pos = sourcePath.lastIndexOf(SRC_MAIN_JAVA_DIR); if (pos < 0) { pos = sourcePath.lastIndexOf(SRC_TEST_JAVA_DIR); diff --git a/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestTracerAtStartup.java b/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestTracerAtStartup.java index b8a4556a476..715648f6981 100644 --- a/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestTracerAtStartup.java +++ b/microprofile/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestTracerAtStartup.java @@ -19,6 +19,8 @@ import io.helidon.microprofile.testing.junit5.HelidonTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -29,6 +31,7 @@ class TestTracerAtStartup { @Test + @DisabledOnOs(value = OS.WINDOWS, disabledReason = "https://github.com/helidon-io/helidon/issues/9513") void checkForFullFeaturedTracerAtStartup() { assertThat("Global tracer from start-up extension", TestExtension.globalTracerAtStartup.unwrap(io.opentelemetry.api.trace.Tracer.class).getClass().getName(), diff --git a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporter.java b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporter.java index 045134ebee0..c06c35052b6 100644 --- a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporter.java +++ b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporter.java @@ -13,26 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.helidon.microprofile.telemetry; -import static java.util.Comparator.comparingLong; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.hamcrest.MatcherAssert.assertThat; - import java.util.Collection; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; -import org.awaitility.Awaitility; - import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; import jakarta.enterprise.context.ApplicationScoped; +import org.awaitility.Awaitility; import org.hamcrest.Matchers; +import static java.util.Comparator.comparingLong; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.hamcrest.MatcherAssert.assertThat; + @ApplicationScoped public class InMemorySpanExporter implements SpanExporter { private boolean isStopped = false; @@ -43,12 +41,13 @@ public class InMemorySpanExporter implements SpanExporter { */ public List getFinishedSpanItems(int spanCount) { assertSpanCount(spanCount); - return finishedSpanItems.stream().sorted(comparingLong(SpanData::getEndEpochNanos)) + return finishedSpanItems.stream().sorted(comparingLong(SpanData::getStartEpochNanos).reversed()) .collect(Collectors.toList()); } public void assertSpanCount(int spanCount) { - Awaitility.await().pollDelay(3, SECONDS).atMost(10, SECONDS) + Awaitility.await() + .pollDelay(3, SECONDS).atMost(10, SECONDS) .untilAsserted(() -> assertThat(finishedSpanItems.size(), Matchers.is(spanCount))); } @@ -57,6 +56,7 @@ public void reset() { } @Override + @SuppressWarnings("NullableProblems") public CompletableResultCode export(Collection spans) { if (isStopped) { return CompletableResultCode.ofFailure(); diff --git a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporterProvider.java b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporterProvider.java index 089cfbefaea..310637c6182 100644 --- a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporterProvider.java +++ b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/InMemorySpanExporterProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 2024 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.helidon.microprofile.telemetry; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; @@ -21,6 +20,7 @@ import io.opentelemetry.sdk.trace.export.SpanExporter; import jakarta.enterprise.inject.spi.CDI; +@SuppressWarnings("NullableProblems") public class InMemorySpanExporterProvider implements ConfigurableSpanExporterProvider { @Override public SpanExporter createExporter(final ConfigProperties config) { @@ -31,4 +31,4 @@ public SpanExporter createExporter(final ConfigProperties config) { public String getName() { return "in-memory"; } -} \ No newline at end of file +} diff --git a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/RestSpanHierarchyTest.java b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/RestSpanHierarchyTest.java index 1966edbf482..ec56704e27a 100644 --- a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/RestSpanHierarchyTest.java +++ b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/RestSpanHierarchyTest.java @@ -13,31 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package io.helidon.microprofile.telemetry; import java.util.List; -import io.helidon.http.Status; -import io.helidon.microprofile.telemetry.InMemorySpanExporterProvider; 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.AddConfigBlock; import io.helidon.microprofile.testing.junit5.HelidonTest; +import io.helidon.tracing.Span; +import io.helidon.tracing.Tracer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.instrumentation.annotations.WithSpan; import io.opentelemetry.sdk.trace.data.SpanData; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.Application; import jakarta.ws.rs.core.Response; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,10 +47,12 @@ @AddBean(RestSpanHierarchyTest.SpanResource.class) @AddBean(InMemorySpanExporter.class) @AddBean(InMemorySpanExporterProvider.class) -@AddConfig(key = "otel.service.name", value = "helidon-mp-telemetry") -@AddConfig(key = "otel.sdk.disabled", value = "false") -@AddConfig(key = "telemetry.span.full.url", value = "false") -@AddConfig(key = "otel.traces.exporter", value = "in-memory") +@AddConfigBlock(""" + otel.service.name=helidon-mp-telemetry + otel.sdk.disabled=false + otel.traces.exporter=in-memory + telemetry.span.full.url=false + """) public class RestSpanHierarchyTest { @Inject @@ -72,7 +68,6 @@ void setup() { @Test void spanHierarchy() { - assertThat(webTarget.path("mixed").request().get().getStatus(), is(Response.Status.OK.getStatusCode())); List spanItems = spanExporter.getFinishedSpanItems(4); @@ -81,12 +76,10 @@ void spanHierarchy() { assertThat(spanItems.get(0).getAttributes().get(AttributeKey.stringKey("attribute")), is("value")); assertThat(spanItems.get(0).getParentSpanId(), is(spanItems.get(1).getSpanId())); - assertThat(spanItems.get(1).getKind(), is(INTERNAL)); assertThat(spanItems.get(1).getName(), is("mixed_parent")); assertThat(spanItems.get(1).getParentSpanId(), is(spanItems.get(2).getSpanId())); - assertThat(spanItems.get(2).getKind(), is(SERVER)); assertThat(spanItems.get(2).getName(), is("/mixed")); } @@ -119,17 +112,16 @@ void spanHierarchyInjected() { public static class SpanResource { @Inject - private io.helidon.tracing.Tracer helidonTracerInjected; - + private Tracer helidonTracerInjected; @GET @Path("mixed") @WithSpan("mixed_parent") public Response mixedSpan() { - io.helidon.tracing.Tracer helidonTracer = io.helidon.tracing.Tracer.global(); - io.helidon.tracing.Span mixedSpan = helidonTracer.spanBuilder("mixed_inner") - .kind(io.helidon.tracing.Span.Kind.SERVER) + Tracer helidonTracer = Tracer.global(); + Span mixedSpan = helidonTracer.spanBuilder("mixed_inner") + .kind(Span.Kind.SERVER) .tag("attribute", "value") .start(); mixedSpan.end(); @@ -142,8 +134,8 @@ public Response mixedSpan() { @WithSpan("mixed_parent_injected") public Response mixedSpanInjected() { - io.helidon.tracing.Span mixedSpan = helidonTracerInjected.spanBuilder("mixed_inner_injected") - .kind(io.helidon.tracing.Span.Kind.SERVER) + Span mixedSpan = helidonTracerInjected.spanBuilder("mixed_inner_injected") + .kind(Span.Kind.SERVER) .tag("attribute", "value") .start(); mixedSpan.end(); diff --git a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestFullUrlName.java b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestFullUrlName.java index a0b8b763658..281dcbc5561 100644 --- a/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestFullUrlName.java +++ b/microprofile/tests/telemetry/src/test/java/io/helidon/microprofile/telemetry/TestFullUrlName.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package io.helidon.microprofile.telemetry; import java.util.List; @@ -21,6 +20,7 @@ import io.helidon.microprofile.testing.junit5.AddBean; import io.helidon.microprofile.testing.junit5.AddConfig; +import io.helidon.microprofile.testing.junit5.AddConfigBlock; import io.helidon.microprofile.testing.junit5.AddExtension; import io.helidon.microprofile.testing.junit5.HelidonTest; @@ -46,17 +46,17 @@ @AddBean(InMemorySpanExporter.class) @AddBean(InMemorySpanExporterProvider.class) @AddExtension(TelemetryCdiExtension.class) -@AddConfig(key = "otel.service.name", value = "helidon-mp-telemetry") -@AddConfig(key = "otel.sdk.disabled", value = "false") -@AddConfig(key = "telemetry.span.full.url", value = "true") -@AddConfig(key = "otel.traces.exporter", value = "in-memory") +@AddConfigBlock(""" + otel.service.name=helidon-mp-telemetry + otel.sdk.disabled=false + otel.traces.exporter=in-memory + telemetry.span.full.url=true + """) public class TestFullUrlName { - @Inject WebTarget webTarget; - @Inject InMemorySpanExporter spanExporter; @@ -70,7 +70,6 @@ void setup() { @Test void spanNaming() { - assertThat(webTarget.path("named").request().get().getStatus(), is(Response.Status.OK.getStatusCode())); List names = spanExporter.getFinishedSpanItems(2) @@ -95,4 +94,4 @@ public Response mixedSpan() { } } -} \ No newline at end of file +} diff --git a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java index e26fc0fe572..f86f82430f5 100644 --- a/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java +++ b/tests/integration/harness/src/main/java/io/helidon/tests/integration/harness/ProcessRunner.java @@ -31,6 +31,7 @@ import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static java.util.Objects.requireNonNull; @@ -467,7 +468,17 @@ private static final class JlinkRunner extends ProcessRunner { @Override protected List command(List opts, List args) { Objects.requireNonNull(finalName, "finalName is null"); - return new CommandBuilder("target/" + finalName + "-jri/bin/start" + (IS_WINDOWS ? ".ps1" : "")) + if (IS_WINDOWS) { + return new CommandBuilder("powershell") + .append("-File") + .append("target/" + finalName + "-jri/bin/start.ps1") + .append("--jvm", opts.stream() + .map(option -> String.format("'%s'", option)) + .collect(Collectors.joining(" "))) + .append(args) + .command(); + } + return new CommandBuilder("target/" + finalName + "-jri/bin/start") .append("--jvm", String.join(" ", opts)) .append(args) .command(); diff --git a/tests/integration/packaging/inject/src/test/java/io/helidon/tests/integration/packaging/inject/InjectJlinkTestIT.java b/tests/integration/packaging/inject/src/test/java/io/helidon/tests/integration/packaging/inject/InjectJlinkTestIT.java index 6d955360d69..8516a4bfd15 100644 --- a/tests/integration/packaging/inject/src/test/java/io/helidon/tests/integration/packaging/inject/InjectJlinkTestIT.java +++ b/tests/integration/packaging/inject/src/test/java/io/helidon/tests/integration/packaging/inject/InjectJlinkTestIT.java @@ -18,8 +18,6 @@ import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; class InjectJlinkTestIT extends InjectPackagingTestIT { @@ -29,13 +27,11 @@ ExecMode execMode() { } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testExitOnStarted() { doTestExitOnStarted(); } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testWebClientService() { doTestWebClientService(); } diff --git a/tests/integration/packaging/mp-1/src/test/java/io/helidon/tests/integration/packaging/mp1/Mp1JlinkTestIT.java b/tests/integration/packaging/mp-1/src/test/java/io/helidon/tests/integration/packaging/mp1/Mp1JlinkTestIT.java index 1e487c05b9d..4990051f946 100644 --- a/tests/integration/packaging/mp-1/src/test/java/io/helidon/tests/integration/packaging/mp1/Mp1JlinkTestIT.java +++ b/tests/integration/packaging/mp-1/src/test/java/io/helidon/tests/integration/packaging/mp1/Mp1JlinkTestIT.java @@ -18,8 +18,6 @@ import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; class Mp1JlinkTestIT extends Mp1PackagingTestIT { @@ -29,7 +27,6 @@ ExecMode execMode() { } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testApp() { doTestApp(); } diff --git a/tests/integration/packaging/mp-3/src/test/java/io/helidon/tests/integration/packaging/mp3/Mp3JlinkTestIT.java b/tests/integration/packaging/mp-3/src/test/java/io/helidon/tests/integration/packaging/mp3/Mp3JlinkTestIT.java index 6e760b72cf2..035d5a1a533 100644 --- a/tests/integration/packaging/mp-3/src/test/java/io/helidon/tests/integration/packaging/mp3/Mp3JlinkTestIT.java +++ b/tests/integration/packaging/mp-3/src/test/java/io/helidon/tests/integration/packaging/mp3/Mp3JlinkTestIT.java @@ -18,8 +18,6 @@ import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; class Mp3JlinkTestIT extends Mp3PackagingTestIT { @@ -29,13 +27,11 @@ ExecMode execMode() { } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testExitOnStarted() { doTestExitOnStarted(); } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testGreetResource() { doTestGreetResource(); } diff --git a/tests/integration/packaging/se-1/src/test/java/io/helidon/tests/integration/packaging/se1/Se1JlinkTestIT.java b/tests/integration/packaging/se-1/src/test/java/io/helidon/tests/integration/packaging/se1/Se1JlinkTestIT.java index 92cd7bf5dc1..f5fbd612518 100644 --- a/tests/integration/packaging/se-1/src/test/java/io/helidon/tests/integration/packaging/se1/Se1JlinkTestIT.java +++ b/tests/integration/packaging/se-1/src/test/java/io/helidon/tests/integration/packaging/se1/Se1JlinkTestIT.java @@ -18,8 +18,6 @@ import io.helidon.tests.integration.harness.ProcessRunner.ExecMode; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledOnOs; -import org.junit.jupiter.api.condition.OS; class Se1JlinkTestIT extends Se1PackagingTestIT { @@ -29,13 +27,11 @@ ExecMode execMode() { } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testExitOnStarted() { doTestExitOnStarted(); } @Test - @DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application") void testWebClientService() { doTestWebClientService(); }