-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert redisscala tests from groovy to java #12553
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5a143b8
add ut
shalk e644f59
add ut
shalk 568ce4a
add spotless
shalk ff4303c
fix ut
shalk b95cb65
fix review
shalk 1d5d240
fix review
shalk b9c424c
fix SemconvStabilityUtil
shalk 5263e9a
fix review
shalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 0 additions & 145 deletions
145
instrumentation/rediscala-1.8/javaagent/src/test/groovy/RediscalaClientTest.groovy
This file was deleted.
Oops, something went wrong.
172 changes: 172 additions & 0 deletions
172
...c/test/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaClientTest.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,172 @@ | ||||||||
/* | ||||||||
* Copyright The OpenTelemetry Authors | ||||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||||
*/ | ||||||||
|
||||||||
package io.opentelemetry.javaagent.instrumentation.rediscala; | ||||||||
|
||||||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT; | ||||||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||||||||
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; | ||||||||
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemIncubatingValues.REDIS; | ||||||||
import static org.assertj.core.api.Assertions.assertThat; | ||||||||
import static org.awaitility.Awaitility.await; | ||||||||
|
||||||||
import com.google.common.util.concurrent.SettableFuture; | ||||||||
import io.opentelemetry.api.common.AttributeKey; | ||||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||||||||
import io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil; | ||||||||
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; | ||||||||
import java.time.Duration; | ||||||||
import org.junit.jupiter.api.AfterAll; | ||||||||
import org.junit.jupiter.api.BeforeAll; | ||||||||
import org.junit.jupiter.api.Test; | ||||||||
import org.junit.jupiter.api.extension.RegisterExtension; | ||||||||
import org.testcontainers.containers.GenericContainer; | ||||||||
import redis.ByteStringDeserializer; | ||||||||
import redis.ByteStringDeserializer$; | ||||||||
import redis.ByteStringSerializer; | ||||||||
import redis.ByteStringSerializer$; | ||||||||
import redis.RedisClient; | ||||||||
import redis.RedisDispatcher; | ||||||||
import scala.Option; | ||||||||
import scala.concurrent.Future; | ||||||||
|
||||||||
class RediscalaClientTest { | ||||||||
|
||||||||
@RegisterExtension | ||||||||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||||||||
|
||||||||
private static GenericContainer<?> redisServer; | ||||||||
|
||||||||
@SuppressWarnings("deprecation") // DB_OPERATION is deprecated | ||||||||
private static final AttributeKey<String> DB_OPERATION = | ||||||||
SemconvStabilityUtil.maybeStable(DbIncubatingAttributes.DB_OPERATION); | ||||||||
|
||||||||
private static Object system; | ||||||||
private static RedisClient redisClient; | ||||||||
|
||||||||
@BeforeAll | ||||||||
static void setUp() throws Exception { | ||||||||
redisServer = new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379); | ||||||||
redisServer.start(); | ||||||||
|
||||||||
String host = redisServer.getHost(); | ||||||||
Integer port = redisServer.getMappedPort(6379); | ||||||||
|
||||||||
try { | ||||||||
Class<?> clazz = Class.forName("akka.actor.ActorSystem"); | ||||||||
system = clazz.getMethod("create").invoke(null); | ||||||||
} catch (ClassNotFoundException exception) { | ||||||||
Class<?> clazz = Class.forName("org.apache.pekko.actor.ActorSystem"); | ||||||||
system = clazz.getMethod("create").invoke(null); | ||||||||
} | ||||||||
|
||||||||
try { | ||||||||
RedisClient.class.getMethod("username"); | ||||||||
redisClient = | ||||||||
(RedisClient) | ||||||||
RedisClient.class.getConstructors()[0].newInstance( | ||||||||
host, | ||||||||
port, | ||||||||
Option.apply(null), | ||||||||
Option.apply(null), | ||||||||
Option.apply(null), | ||||||||
"RedisClient", | ||||||||
Option.apply(null), | ||||||||
system, | ||||||||
new RedisDispatcher("rediscala.rediscala-client-worker-dispatcher")); | ||||||||
} catch (Exception e) { | ||||||||
redisClient = | ||||||||
(RedisClient) | ||||||||
RedisClient.class.getConstructors()[0].newInstance( | ||||||||
host, | ||||||||
port, | ||||||||
Option.apply(null), | ||||||||
Option.apply(null), | ||||||||
"RedisClient", | ||||||||
Option.apply(null), | ||||||||
system, | ||||||||
new RedisDispatcher("rediscala.rediscala-client-worker-dispatcher")); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
@AfterAll | ||||||||
static void tearDown() throws Exception { | ||||||||
redisServer.stop(); | ||||||||
if (system != null) { | ||||||||
system.getClass().getMethod("terminate").invoke(system); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
void testGetCommand() throws Exception { | ||||||||
SettableFuture<Future<Object>> writeFutureRef = SettableFuture.create(); | ||||||||
; | ||||||||
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
SettableFuture<Future<Option<String>>> valueFutureRef = SettableFuture.create(); | ||||||||
|
||||||||
testing.runWithSpan( | ||||||||
"parent", | ||||||||
() -> { | ||||||||
ByteStringSerializer<String> serializer = ByteStringSerializer$.MODULE$.String(); | ||||||||
ByteStringDeserializer<String> deserializer = ByteStringDeserializer$.MODULE$.String(); | ||||||||
writeFutureRef.set( | ||||||||
redisClient.set( | ||||||||
"bar", "baz", Option.apply(null), Option.apply(null), false, false, serializer)); | ||||||||
valueFutureRef.set(redisClient.get("bar", deserializer)); | ||||||||
}); | ||||||||
|
||||||||
await().atMost(Duration.ofSeconds(3)).until(() -> writeFutureRef.get().isCompleted()); | ||||||||
await().atMost(Duration.ofSeconds(3)).until(() -> valueFutureRef.get().isCompleted()); | ||||||||
assertThat(writeFutureRef.get().value().get().get()).isEqualTo(true); | ||||||||
assertThat(valueFutureRef.get().value().get().get().get()).isEqualTo("baz"); | ||||||||
|
||||||||
testing.waitAndAssertTraces( | ||||||||
trace -> | ||||||||
trace.hasSpansSatisfyingExactly( | ||||||||
span -> span.hasName("parent").hasNoParent(), | ||||||||
span -> | ||||||||
span.hasName("SET") | ||||||||
.hasKind(CLIENT) | ||||||||
.hasParent(trace.getSpan(0)) | ||||||||
.hasAttributesSatisfyingExactly( | ||||||||
equalTo(DB_SYSTEM, REDIS), equalTo(DB_OPERATION, "SET")), | ||||||||
span -> | ||||||||
span.hasName("GET") | ||||||||
.hasKind(CLIENT) | ||||||||
.hasParent(trace.getSpan(0)) | ||||||||
.hasAttributesSatisfyingExactly( | ||||||||
equalTo(DB_SYSTEM, REDIS), equalTo(DB_OPERATION, "GET")))); | ||||||||
} | ||||||||
|
||||||||
@Test | ||||||||
public void testSetCommand() { | ||||||||
ByteStringSerializer<String> serializer = ByteStringSerializer$.MODULE$.String(); | ||||||||
|
||||||||
Future<Object> value = | ||||||||
testing.runWithSpan( | ||||||||
"parent", | ||||||||
() -> | ||||||||
redisClient.set( | ||||||||
"foo", | ||||||||
"bar", | ||||||||
Option.apply(null), | ||||||||
Option.apply(null), | ||||||||
false, | ||||||||
false, | ||||||||
serializer)); | ||||||||
await().atMost(Duration.ofSeconds(3)).until(value::isCompleted); | ||||||||
assertThat(value.value().get().get()).isEqualTo(true); | ||||||||
testing.waitAndAssertTraces( | ||||||||
trace -> | ||||||||
trace.hasSpansSatisfyingExactly( | ||||||||
span -> span.hasName("parent").hasNoParent(), | ||||||||
span -> | ||||||||
span.hasName("SET") | ||||||||
.hasKind(CLIENT) | ||||||||
.hasParent(trace.getSpan(0)) | ||||||||
.hasAttributesSatisfying( | ||||||||
equalTo(DB_SYSTEM, REDIS), equalTo(DB_OPERATION, "SET")))); | ||||||||
} | ||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
groovy version also calls
redisServer.stop()