-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert lettuce 5.1 SyncClientAuthTest from groovy to java (#10045)
- Loading branch information
Showing
7 changed files
with
135 additions
and
126 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
.../io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceSyncClientAuthTest.groovy
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...va/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceSyncClientAuthTest.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,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.opentelemetry.instrumentation.lettuce.v5_1.AbstractLettuceSyncClientTest; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class LettuceSyncClientAuthTest extends AbstractLettuceSyncClientTest { | ||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Override | ||
public InstrumentationExtension getInstrumentationExtension() { | ||
return testing; | ||
} | ||
|
||
@Override | ||
protected RedisClient createClient(String uri) { | ||
return RedisClient.create(uri); | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
...est/groovy/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceSyncClientAuthTest.groovy
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...rc/test/java/io/opentelemetry/instrumentation/lettuce/v5_1/LettuceSyncClientAuthTest.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,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.lettuce.v5_1; | ||
|
||
import io.lettuce.core.RedisClient; | ||
import io.lettuce.core.resource.ClientResources; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class LettuceSyncClientAuthTest extends AbstractLettuceSyncClientAuthTest { | ||
@RegisterExtension | ||
static InstrumentationExtension testing = LibraryInstrumentationExtension.create(); | ||
|
||
@Override | ||
public InstrumentationExtension getInstrumentationExtension() { | ||
return testing; | ||
} | ||
|
||
@Override | ||
protected RedisClient createClient(String uri) { | ||
return RedisClient.create( | ||
ClientResources.builder() | ||
.tracing( | ||
LettuceTelemetry.create(getInstrumentationExtension().getOpenTelemetry()) | ||
.newTracing()) | ||
.build(), | ||
uri); | ||
} | ||
} |
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
86 changes: 0 additions & 86 deletions
86
...vy/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.groovy
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...java/io/opentelemetry/instrumentation/lettuce/v5_1/AbstractLettuceSyncClientAuthTest.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,75 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.lettuce.v5_1; | ||
|
||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.lettuce.core.api.sync.RedisCommands; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; | ||
import io.opentelemetry.semconv.SemanticAttributes; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public abstract class AbstractLettuceSyncClientAuthTest extends AbstractLettuceClientTest { | ||
|
||
@BeforeAll | ||
void setUp() { | ||
redisServer = redisServer.withCommand("redis-server", "--requirepass password"); | ||
redisServer.start(); | ||
|
||
host = redisServer.getHost(); | ||
port = redisServer.getMappedPort(6379); | ||
embeddedDbUri = "redis://" + host + ":" + port + "/" + DB_INDEX; | ||
|
||
redisClient = createClient(embeddedDbUri); | ||
redisClient.setOptions(LettuceTestUtil.CLIENT_OPTIONS); | ||
} | ||
|
||
@AfterAll | ||
static void cleanUp() { | ||
redisClient.shutdown(); | ||
redisServer.stop(); | ||
|
||
// Set back so other tests don't fail due to NOAUTH error | ||
redisServer = redisServer.withCommand("redis-server", "--requirepass \"\""); | ||
} | ||
|
||
@Test | ||
void testAuthCommand() throws Exception { | ||
Class<?> commandsClass = RedisCommands.class; | ||
java.lang.reflect.Method authMethod; | ||
// the auth() argument type changed between 5.x -> 6.x | ||
try { | ||
authMethod = commandsClass.getMethod("auth", String.class); | ||
} catch (NoSuchMethodException unused) { | ||
authMethod = commandsClass.getMethod("auth", CharSequence.class); | ||
} | ||
|
||
String result = (String) authMethod.invoke(redisClient.connect().sync(), "password"); | ||
|
||
assertThat(result).isEqualTo("OK"); | ||
|
||
getInstrumentationExtension() | ||
.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("AUTH") | ||
.hasKind(SpanKind.CLIENT) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), | ||
equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), | ||
equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), | ||
equalTo(SemanticAttributes.DB_SYSTEM, "redis"), | ||
equalTo(SemanticAttributes.DB_STATEMENT, "AUTH ?")) | ||
.hasEventsSatisfyingExactly( | ||
event -> event.hasName("redis.encode.start"), | ||
event -> event.hasName("redis.encode.end")))); | ||
} | ||
} |