From 98976e9edbf203f68874d56a07a4f0122214492b Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Mon, 9 Oct 2023 07:27:16 -0400 Subject: [PATCH] Convert internal-lambda test from groovy to java (#9611) --- .../groovy/LambdaInstrumentationTest.groovy | 21 ---------------- .../lambda/LambdaInstrumentationTest.java | 24 +++++++++++++++++++ .../internal/lambda}/TestLambda.java | 2 ++ 3 files changed, 26 insertions(+), 21 deletions(-) delete mode 100644 instrumentation/internal/internal-lambda/javaagent/src/test/groovy/LambdaInstrumentationTest.groovy create mode 100644 instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/LambdaInstrumentationTest.java rename instrumentation/internal/internal-lambda/javaagent/src/test/java/{ => io/opentelemetry/javaagent/instrumentation/internal/lambda}/TestLambda.java (74%) diff --git a/instrumentation/internal/internal-lambda/javaagent/src/test/groovy/LambdaInstrumentationTest.groovy b/instrumentation/internal/internal-lambda/javaagent/src/test/groovy/LambdaInstrumentationTest.groovy deleted file mode 100644 index aa3e5e027fc4..000000000000 --- a/instrumentation/internal/internal-lambda/javaagent/src/test/groovy/LambdaInstrumentationTest.groovy +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker - -class LambdaInstrumentationTest extends AgentInstrumentationSpecification { - - def "test transform Runnable lambda"() { - setup: - Runnable runnable = TestLambda.makeRunnable() - - expect: - // RunnableInstrumentation adds a VirtualField to all implementors of Runnable. If lambda class - // is transformed then it must have context store marker interface. - runnable instanceof VirtualFieldInstalledMarker - !VirtualFieldInstalledMarker.isAssignableFrom(Runnable) - } -} diff --git a/instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/LambdaInstrumentationTest.java b/instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/LambdaInstrumentationTest.java new file mode 100644 index 000000000000..01bbb39b6921 --- /dev/null +++ b/instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/LambdaInstrumentationTest.java @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.internal.lambda; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker; +import org.junit.jupiter.api.Test; + +class LambdaInstrumentationTest { + + @Test + void testTransformRunnableLambda() { + Runnable runnable = TestLambda.makeRunnable(); + + // RunnableInstrumentation adds a VirtualField to all implementors of Runnable. If lambda class + // is transformed then it must have context store marker interface. + assertThat(runnable).isInstanceOf(VirtualFieldInstalledMarker.class); + assertThat(VirtualFieldInstalledMarker.class.isAssignableFrom(Runnable.class)).isFalse(); + } +} diff --git a/instrumentation/internal/internal-lambda/javaagent/src/test/java/TestLambda.java b/instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/TestLambda.java similarity index 74% rename from instrumentation/internal/internal-lambda/javaagent/src/test/java/TestLambda.java rename to instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/TestLambda.java index 8ea194b6a12f..f1a5cea094cb 100644 --- a/instrumentation/internal/internal-lambda/javaagent/src/test/java/TestLambda.java +++ b/instrumentation/internal/internal-lambda/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/TestLambda.java @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +package io.opentelemetry.javaagent.instrumentation.internal.lambda; + public class TestLambda { static Runnable makeRunnable() {