|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | + |
| 10 | +import io.lettuce.core.RedisClient; |
| 11 | +import io.lettuce.core.api.sync.RedisCommands; |
| 12 | +import io.opentelemetry.api.trace.SpanKind; |
| 13 | +import io.opentelemetry.instrumentation.lettuce.v5_1.AbstractLettuceClientTest; |
| 14 | +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
| 15 | +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
| 16 | +import java.net.InetAddress; |
| 17 | +import java.net.UnknownHostException; |
| 18 | +import org.junit.jupiter.api.AfterAll; |
| 19 | +import org.junit.jupiter.api.BeforeAll; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 22 | + |
| 23 | +class LettuceCompatibilityTest extends AbstractLettuceClientTest { |
| 24 | + @RegisterExtension |
| 25 | + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); |
| 26 | + |
| 27 | + @Override |
| 28 | + public InstrumentationExtension testing() { |
| 29 | + return testing; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + protected RedisClient createClient(String uri) { |
| 34 | + return RedisClient.create(uri); |
| 35 | + } |
| 36 | + |
| 37 | + private static RedisCommands<String, String> syncCommands; |
| 38 | + |
| 39 | + @BeforeAll |
| 40 | + void setUp() throws UnknownHostException { |
| 41 | + redisServer.start(); |
| 42 | + |
| 43 | + host = redisServer.getHost(); |
| 44 | + ip = InetAddress.getByName(host).getHostAddress(); |
| 45 | + port = redisServer.getMappedPort(6379); |
| 46 | + embeddedDbUri = "redis://" + host + ":" + port + "/" + DB_INDEX; |
| 47 | + |
| 48 | + redisClient = createClient(embeddedDbUri); |
| 49 | + |
| 50 | + connection = redisClient.connect(); |
| 51 | + syncCommands = connection.sync(); |
| 52 | + |
| 53 | + syncCommands.set("TESTKEY", "TESTVAL"); |
| 54 | + } |
| 55 | + |
| 56 | + @AfterAll |
| 57 | + static void cleanUp() { |
| 58 | + connection.close(); |
| 59 | + redisClient.shutdown(); |
| 60 | + redisServer.stop(); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void testInstrumentationDisabled() { |
| 65 | + String res = |
| 66 | + testing().runWithSpan("parent", () -> syncCommands.set("TESTSETKEY", "TESTSETVAL")); |
| 67 | + assertThat(res).isEqualTo("OK"); |
| 68 | + testing() |
| 69 | + .waitAndAssertTraces( |
| 70 | + trace -> |
| 71 | + trace.hasSpansSatisfyingExactly( |
| 72 | + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent())); |
| 73 | + } |
| 74 | +} |
0 commit comments