Skip to content

Commit

Permalink
Migrate AkkaActorTest to scala (open-telemetry#5582)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored and RashmiRam committed May 23, 2022
1 parent 32d5e84 commit ee06a83
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

dependencies {
testImplementation("org.scala-lang:scala-library")
testImplementation("org.scala-lang.modules:scala-java8-compat_2.11")
}

tasks {
Expand Down
1 change: 1 addition & 0 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* 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)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public final void waitAndAssertTraces(Consumer<TraceAssert>... assertions) {
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}.
Expand Down

0 comments on commit ee06a83

Please sign in to comment.