-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test earliest spring boot version (#11474)
- Loading branch information
1 parent
e07ef6f
commit 40cea5e
Showing
24 changed files
with
246 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
alias(springBoot32.plugins.versions) | ||
id("org.graalvm.buildtools.native") | ||
} | ||
|
||
description = "smoke-tests-otel-starter-spring-boot-3.2" | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_17) | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
implementation("org.springframework.boot:spring-boot-starter-data-jdbc") | ||
runtimeOnly("com.h2database:h2") | ||
implementation("org.apache.commons:commons-dbcp2") | ||
implementation("org.springframework.kafka:spring-kafka") | ||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb") | ||
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) | ||
|
||
implementation(project(":smoke-tests-otel-starter:spring-boot-common")) | ||
testImplementation("org.springframework.boot:spring-boot-starter-test") | ||
} | ||
|
||
springBoot { | ||
mainClass = "io.opentelemetry.spring.smoketest.OtelSpringStarterSmokeTestApplication" | ||
} | ||
|
||
tasks { | ||
compileAotJava { | ||
with(options) { | ||
compilerArgs.add("-Xlint:-deprecation,-unchecked,none") | ||
// To disable warnings/failure coming from the Java compiler during the Spring AOT processing | ||
// -deprecation,-unchecked and none are required (none is not enough) | ||
} | ||
} | ||
compileAotTestJava { | ||
with(options) { | ||
compilerArgs.add("-Xlint:-deprecation,-unchecked,none") | ||
// To disable warnings/failure coming from the Java compiler during the Spring AOT processing | ||
// -deprecation,-unchecked and none are required (none is not enough) | ||
} | ||
} | ||
checkstyleAot { | ||
isEnabled = false | ||
} | ||
checkstyleAotTest { | ||
isEnabled = false | ||
} | ||
} | ||
|
||
// To be able to execute the tests as GraalVM native executables | ||
configurations.configureEach { | ||
exclude("org.apache.groovy", "groovy") | ||
exclude("org.apache.groovy", "groovy-json") | ||
exclude("org.spockframework", "spock-core") | ||
} | ||
|
||
graalvmNative { | ||
binaries.all { | ||
// Workaround for https://github.com/junit-team/junit5/issues/3405 | ||
buildArgs.add("--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig") | ||
buildArgs.add("--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter") | ||
} | ||
|
||
// See https://github.com/graalvm/native-build-tools/issues/572 | ||
metadataRepository { | ||
enabled.set(false) | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
setForkEvery(1) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...rc/main/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.spring.smoketest; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.ImportRuntimeHints; | ||
|
||
@SpringBootApplication | ||
@ImportRuntimeHints(RuntimeHints.class) | ||
public class OtelSpringStarterSmokeTestApplication { | ||
|
||
public OtelSpringStarterSmokeTestApplication() {} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(OtelSpringStarterSmokeTestApplication.class); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...starter/spring-boot-3.2/src/main/java/io/opentelemetry/spring/smoketest/RuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.spring.smoketest; | ||
|
||
import org.springframework.aot.hint.MemberCategory; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.aot.hint.TypeReference; | ||
|
||
// Necessary for GraalVM native test | ||
public class RuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints( | ||
org.springframework.aot.hint.RuntimeHints hints, ClassLoader classLoader) { | ||
hints.resources().registerResourceBundle("org.apache.commons.dbcp2.LocalStrings"); | ||
|
||
// To avoid Spring native issue with MongoDB: java.lang.ClassNotFoundException: | ||
// org.springframework.data.mongodb.core.aggregation.AggregationOperation | ||
hints | ||
.reflection() | ||
.registerType( | ||
TypeReference.of( | ||
"org.springframework.data.mongodb.core.aggregation.AggregationOperation"), | ||
hint -> { | ||
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); | ||
}); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...-boot-3.2/src/test/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.spring.smoketest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.sdk.testing.assertj.TraceAssert; | ||
import io.opentelemetry.semconv.HttpAttributes; | ||
import io.opentelemetry.semconv.UrlAttributes; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.web.client.RestClient; | ||
|
||
@SpringBootTest( | ||
classes = { | ||
OtelSpringStarterSmokeTestApplication.class, | ||
AbstractOtelSpringStarterSmokeTest.TestConfiguration.class, | ||
SpringSmokeOtelConfiguration.class | ||
}, | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class OtelSpringStarterSmokeTest extends AbstractSpringStarterSmokeTest { | ||
|
||
@Autowired RestClient.Builder restClientBuilder; | ||
@LocalServerPort private int port; | ||
|
||
@Test | ||
void restClient() { | ||
testing.clearAllExportedData(); | ||
|
||
RestClient client = restClientBuilder.baseUrl("http://localhost:" + port).build(); | ||
assertThat( | ||
client | ||
.get() | ||
.uri(OtelSpringStarterSmokeTestController.PING) | ||
.retrieve() | ||
.body(String.class)) | ||
.isEqualTo("pong"); | ||
|
||
if (System.getProperty("org.graalvm.nativeimage.imagecode") != null) { | ||
// ignore the trace for creating the db table | ||
testing.waitAndAssertTraces(trace -> {}, OtelSpringStarterSmokeTest::assertClient); | ||
} else { | ||
testing.waitAndAssertTraces(OtelSpringStarterSmokeTest::assertClient); | ||
} | ||
} | ||
|
||
private static void assertClient(TraceAssert traceAssert) { | ||
traceAssert.hasSpansSatisfyingExactly( | ||
nestedClientSpan -> | ||
nestedClientSpan | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfying( | ||
a -> assertThat(a.get(UrlAttributes.URL_FULL)).endsWith("/ping")), | ||
nestedServerSpan -> | ||
nestedServerSpan | ||
.hasKind(SpanKind.SERVER) | ||
.hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.