Skip to content

Commit

Permalink
Fix jlink packaging test
Browse files Browse the repository at this point in the history
  • Loading branch information
tvallin committed Dec 17, 2024
1 parent f4cf944 commit 89f4138
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/actions/common/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -354,6 +354,7 @@ public static Optional<Path> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,12 +41,13 @@ public class InMemorySpanExporter implements SpanExporter {
*/
public List<SpanData> 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)));
}

Expand All @@ -57,6 +56,7 @@ public void reset() {
}

@Override
@SuppressWarnings("NullableProblems")
public CompletableResultCode export(Collection<SpanData> spans) {
if (isStopped) {
return CompletableResultCode.ofFailure();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,14 +13,14 @@
* 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;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
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) {
Expand All @@ -31,4 +31,4 @@ public SpanExporter createExporter(final ConfigProperties config) {
public String getName() {
return "in-memory";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -72,7 +68,6 @@ void setup() {

@Test
void spanHierarchy() {

assertThat(webTarget.path("mixed").request().get().getStatus(), is(Response.Status.OK.getStatusCode()));

List<SpanData> spanItems = spanExporter.getFinishedSpanItems(4);
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.microprofile.telemetry;

import java.util.List;
import java.util.stream.Collectors;

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;

Expand All @@ -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;

Expand All @@ -70,7 +70,6 @@ void setup() {

@Test
void spanNaming() {

assertThat(webTarget.path("named").request().get().getStatus(), is(Response.Status.OK.getStatusCode()));

List<String> names = spanExporter.getFinishedSpanItems(2)
Expand All @@ -95,4 +94,4 @@ public Response mixedSpan() {
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -467,7 +468,17 @@ private static final class JlinkRunner extends ProcessRunner {
@Override
protected List<String> command(List<String> opts, List<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -29,7 +27,6 @@ ExecMode execMode() {
}

@Test
@DisabledOnOs(value = OS.WINDOWS, disabledReason = "application is not a valid Win32 application")
void testApp() {
doTestApp();
}
Expand Down
Loading

0 comments on commit 89f4138

Please sign in to comment.