Migrate AkkaActorTest to scala
MODIFY
conventions/src/main/kotlin/otel.scala-conventions.gradle.kts
conventions/src/main/kotlin/otel.scala-conventions.gradle.kts
@@ -6,6 +6,7 @@ plugins {
dependencies {
testImplementation("org.scala-lang:scala-library")
+ testImplementation("org.scala-lang.modules:scala-java8-compat_2.11")
}
tasks {

MODIFY
dependencyManagement/build.gradle.kts
dependencyManagement/build.gradle.kts
@@ -116,6 +116,7 @@ val DEPENDENCIES = listOf(
"org.spockframework:spock-core:2.2-M1-groovy-4.0",
"org.spockframework:spock-junit4:2.2-M1-groovy-4.0",
"org.scala-lang:scala-library:2.11.12",
+ "org.scala-lang.modules:scala-java8-compat_2.11:1.0.2",
// Note that this is only referenced as "org.springframework.boot" in build files, not the artifact name.
"org.springframework.boot:spring-boot-dependencies:2.3.1.RELEASE"
)

DELETE
instrumentation/akka/akka-actor-2.5/javaagent/src/test/groovy/AkkaActorTest.groovy
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
-
-class AkkaActorTest extends AgentInstrumentationSpecification {
-
- def "akka #testMethod #count"() {
- setup:
- AkkaActors akkaTester = new AkkaActors()
- count.times {
- akkaTester."$testMethod"()
- }
-
- expect:
- assertTraces(count) {
- count.times {
- trace(it, 2) {
- span(0) {
- name "parent"
- attributes {
- }
- }
- span(1) {
- name "$expectedGreeting, Akka"
- childOf span(0)
- attributes {
- }
- }
- }
- }
- }
-
- where:
- testMethod | expectedGreeting | count
- "basicTell" | "Howdy" | 1
- "basicAsk" | "Howdy" | 1
- "basicForward" | "Hello" | 1
- "basicTell" | "Howdy" | 150
- "basicAsk" | "Howdy" | 150
- "basicForward" | "Hello" | 150
- }
-}

ADD
instrumentation/akka/akka-actor-2.5/javaagent/src/test/scala/io/opentelemetry/instrumentation/akkaactor/AkkaActorTest.scala
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.akkaactor
+
+import collection.JavaConverters._
+import io.opentelemetry.api.common.Attributes
+import io.opentelemetry.instrumentation.testing.junit.{
+ AgentInstrumentationExtension,
+ InstrumentationExtension
+}
+import io.opentelemetry.sdk.testing.assertj.{SpanDataAssert, TraceAssert}
+import org.junit.jupiter.api.TestInstance
+import org.junit.jupiter.api.extension.RegisterExtension
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
+import scala.compat.java8.FunctionConverters._
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+class AkkaActorTest {
+
+ @RegisterExtension val testing: InstrumentationExtension =
+ AgentInstrumentationExtension.create
+
+ @ParameterizedTest
+ @ValueSource(ints = Array(1, 150))
+ def basicTell(count: Int): Unit = {
+ val tester = new AkkaActors
+ (1 to count).foreach { _ =>
+ tester.basicTell()
+ }
+
+ val assertions = (1 to count)
+ .map(_ =>
+ ((trace: TraceAssert) => {
+ trace.hasSpansSatisfyingExactly(
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("parent")
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava,
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("Howdy, Akka")
+ .hasParent(trace.getSpan(0))
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava
+ )
+ ()
+ }).asJava
+ )
+ .asJava
+
+ testing.waitAndAssertTraces(assertions)
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = Array(1, 150))
+ def basicAsk(count: Int): Unit = {
+ val tester = new AkkaActors
+ (1 to count).foreach { _ =>
+ tester.basicAsk()
+ }
+
+ val assertions = (1 to count)
+ .map(_ =>
+ ((trace: TraceAssert) => {
+ trace.hasSpansSatisfyingExactly(
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("parent")
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava,
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("Howdy, Akka")
+ .hasParent(trace.getSpan(0))
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava
+ )
+ ()
+ }).asJava
+ )
+ .asJava
+
+ testing.waitAndAssertTraces(assertions)
+ }
+
+ @ParameterizedTest
+ @ValueSource(ints = Array(1, 150))
+ def basicForward(count: Int): Unit = {
+ val tester = new AkkaActors
+ (1 to count).foreach { _ =>
+ tester.basicForward()
+ }
+
+ val assertions = (1 to count)
+ .map(_ =>
+ ((trace: TraceAssert) => {
+ trace.hasSpansSatisfyingExactly(
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("parent")
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava,
+ ((span: SpanDataAssert) => {
+ span
+ .hasName("Hello, Akka")
+ .hasParent(trace.getSpan(0))
+ .hasAttributes(Attributes.empty())
+ ()
+ }).asJava
+ )
+ ()
+ }).asJava
+ )
+ .asJava
+
+ testing.waitAndAssertTraces(assertions)
+ }
+}

RENAME
instrumentation/akka/akka-actor-2.5/javaagent/src/test/scala/AkkaActors.scala
instrumentation/akka/akka-actor-2.5/javaagent/src/test/scala/io/opentelemetry/instrumentation/akkaactor/AkkaActors.scala
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.akkaactor
+
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0

MODIFY
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java
testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java
@@ -115,6 +115,10 @@ public abstract class InstrumentationExtension
testRunner.waitAndAssertTraces(assertions);
}
+ public final void waitAndAssertTraces(Iterable<? extends Consumer<TraceAssert>> assertions) {
+ testRunner.waitAndAssertTraces(assertions);
+ }
+
/**
* Runs the provided {@code callback} inside the scope of an INTERNAL span with name {@code
* spanName}.

Migrate AkkaActorTest to scala (#5582)