-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert jedis test from groovy to java (#7731)
related to #7195
- Loading branch information
1 parent
7091719
commit c9a0462
Showing
6 changed files
with
452 additions
and
431 deletions.
There are no files selected for viewing
137 changes: 0 additions & 137 deletions
137
instrumentation/jedis/jedis-1.4/javaagent/src/test/groovy/JedisClientTest.groovy
This file was deleted.
Oops, something went wrong.
133 changes: 133 additions & 0 deletions
133
.../src/test/java/io/opentelemetry/javaagent/instrumentation/jedis/v1_4/JedisClientTest.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,133 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jedis.v1_4; | ||
|
||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.testcontainers.containers.GenericContainer; | ||
import redis.clients.jedis.Jedis; | ||
|
||
class JedisClientTest { | ||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
static GenericContainer<?> redisServer = | ||
new GenericContainer<>("redis:6.2.3-alpine").withExposedPorts(6379); | ||
|
||
static int port; | ||
|
||
static Jedis jedis; | ||
|
||
@BeforeAll | ||
static void setupSpec() { | ||
redisServer.start(); | ||
port = redisServer.getMappedPort(6379); | ||
jedis = new Jedis("localhost", port); | ||
} | ||
|
||
@AfterAll | ||
static void cleanupSpec() { | ||
redisServer.stop(); | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
jedis.flushAll(); | ||
testing.clearData(); | ||
} | ||
|
||
@Test | ||
void setCommand() { | ||
jedis.set("foo", "bar"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("SET") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), | ||
equalTo(SemanticAttributes.DB_OPERATION, "SET"), | ||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), | ||
equalTo(SemanticAttributes.NET_PEER_PORT, port)))); | ||
} | ||
|
||
@Test | ||
void getCommand() { | ||
jedis.set("foo", "bar"); | ||
String value = jedis.get("foo"); | ||
|
||
assertThat(value).isEqualTo("bar"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("SET") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), | ||
equalTo(SemanticAttributes.DB_OPERATION, "SET"), | ||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), | ||
equalTo(SemanticAttributes.NET_PEER_PORT, port))), | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("GET") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "GET foo"), | ||
equalTo(SemanticAttributes.DB_OPERATION, "GET"), | ||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), | ||
equalTo(SemanticAttributes.NET_PEER_PORT, port)))); | ||
} | ||
|
||
@Test | ||
void commandWithNoArguments() { | ||
jedis.set("foo", "bar"); | ||
String value = jedis.randomKey(); | ||
|
||
assertThat(value).isEqualTo("foo"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("SET") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "SET foo ?"), | ||
equalTo(SemanticAttributes.DB_OPERATION, "SET"), | ||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), | ||
equalTo(SemanticAttributes.NET_PEER_PORT, port))), | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("RANDOMKEY") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "RANDOMKEY"), | ||
equalTo(SemanticAttributes.DB_OPERATION, "RANDOMKEY"), | ||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), | ||
equalTo(SemanticAttributes.NET_PEER_PORT, port)))); | ||
} | ||
} |
Oops, something went wrong.