Fix redisson latest dep test (#9707)

This commit is contained in:
Lauri Tulmin 2023-10-18 23:52:36 +03:00 committed by GitHub
parent 80ca9ee0c3
commit ccb2955a55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 24 deletions

View File

@ -12,4 +12,9 @@ public class RedissonClientTest extends AbstractRedissonClientTest {
protected boolean useRedisProtocol() { protected boolean useRedisProtocol() {
return true; return true;
} }
@Override
protected boolean lockHas3Traces() {
return Boolean.getBoolean("testLatestDeps");
}
} }

View File

@ -11,17 +11,19 @@ import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.or
import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static java.util.regex.Pattern.compile;
import static java.util.regex.Pattern.quote;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.testing.assertj.TraceAssert;
import io.opentelemetry.semconv.SemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer;
import org.junit.Assume; import org.junit.Assume;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -75,7 +77,7 @@ public abstract class AbstractRedissonClientTest {
} }
@BeforeEach @BeforeEach
void setup() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { void setup() throws InvocationTargetException, IllegalAccessException {
String newAddress = address; String newAddress = address;
if (useRedisProtocol()) { if (useRedisProtocol()) {
// Newer versions of redisson require scheme, older versions forbid it // Newer versions of redisson require scheme, older versions forbid it
@ -91,8 +93,7 @@ public abstract class AbstractRedissonClientTest {
.getClass() .getClass()
.getMethod("setPingConnectionInterval", int.class) .getMethod("setPingConnectionInterval", int.class)
.invoke(singleServerConfig, 0); .invoke(singleServerConfig, 0);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException ignored) {
logger.warn("no setPingConnectionInterval method", e);
} }
redisson = Redisson.create(config); redisson = Redisson.create(config);
testing.clearData(); testing.clearData();
@ -364,24 +365,9 @@ public abstract class AbstractRedissonClientTest {
} finally { } finally {
lock.unlock(); lock.unlock();
} }
// Use .* to match the actual script, since it changes between redisson versions
// everything that does not change is quoted so that it's matched literally
String lockPattern = compile("^" + quote("EVAL ") + ".*" + quote(" 1 lock ? ?")).toString();
String unlockPattern = List<Consumer<TraceAssert>> traceAsserts = new ArrayList<>();
compile( traceAsserts.add(
"^"
+ quote("EVAL ")
+ ".*"
+ quote(" 2 lock ")
+ "\\S+"
+ "("
+ quote(" ?")
+ ")+$")
.toString();
testing.waitAndAssertSortedTraces(
orderByRootSpanKind(SpanKind.CLIENT),
trace -> trace ->
trace.hasSpansSatisfyingExactly( trace.hasSpansSatisfyingExactly(
span -> span ->
@ -395,7 +381,8 @@ public abstract class AbstractRedissonClientTest {
equalTo(SemanticAttributes.DB_OPERATION, "EVAL"), equalTo(SemanticAttributes.DB_OPERATION, "EVAL"),
satisfies( satisfies(
SemanticAttributes.DB_STATEMENT, SemanticAttributes.DB_STATEMENT,
stringAssert -> stringAssert.containsPattern(lockPattern)))), stringAssert -> stringAssert.startsWith("EVAL")))));
traceAsserts.add(
trace -> trace ->
trace.hasSpansSatisfyingExactly( trace.hasSpansSatisfyingExactly(
span -> span ->
@ -409,13 +396,36 @@ public abstract class AbstractRedissonClientTest {
equalTo(SemanticAttributes.DB_OPERATION, "EVAL"), equalTo(SemanticAttributes.DB_OPERATION, "EVAL"),
satisfies( satisfies(
SemanticAttributes.DB_STATEMENT, SemanticAttributes.DB_STATEMENT,
stringAssert -> stringAssert.containsPattern(unlockPattern))))); stringAssert -> stringAssert.startsWith("EVAL")))));
if (lockHas3Traces()) {
traceAsserts.add(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("DEL")
.hasKind(CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
equalTo(SemanticAttributes.NET_SOCK_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, (long) port),
equalTo(SemanticAttributes.DB_SYSTEM, "redis"),
equalTo(SemanticAttributes.DB_OPERATION, "DEL"),
satisfies(
SemanticAttributes.DB_STATEMENT,
stringAssert -> stringAssert.startsWith("DEL")))));
}
testing.waitAndAssertSortedTraces(orderByRootSpanKind(SpanKind.CLIENT), traceAsserts);
} }
protected boolean useRedisProtocol() { protected boolean useRedisProtocol() {
return Boolean.getBoolean("testLatestDeps"); return Boolean.getBoolean("testLatestDeps");
} }
protected boolean lockHas3Traces() {
return false;
}
protected RBatch createBatch(RedissonClient redisson) { protected RBatch createBatch(RedissonClient redisson) {
return redisson.createBatch(BatchOptions.defaults()); return redisson.createBatch(BatchOptions.defaults());
} }