77
88import static io .opentelemetry .api .trace .SpanKind .CLIENT ;
99import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .equalTo ;
10+ import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DB_SYSTEM ;
11+ import static io .opentelemetry .semconv .incubating .DbIncubatingAttributes .DbSystemIncubatingValues .REDIS ;
1012import static org .assertj .core .api .Assertions .assertThat ;
1113import static org .awaitility .Awaitility .await ;
1214
15+ import com .google .common .util .concurrent .SettableFuture ;
1316import io .opentelemetry .api .common .AttributeKey ;
1417import io .opentelemetry .instrumentation .testing .junit .AgentInstrumentationExtension ;
1518import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
1619import io .opentelemetry .instrumentation .testing .junit .db .SemconvStabilityUtil ;
1720import io .opentelemetry .semconv .incubating .DbIncubatingAttributes ;
21+ import java .time .Duration ;
1822import org .junit .jupiter .api .AfterAll ;
1923import org .junit .jupiter .api .BeforeAll ;
2024import org .junit .jupiter .api .Test ;
2125import org .junit .jupiter .api .extension .RegisterExtension ;
2226import org .testcontainers .containers .GenericContainer ;
23- import org .testcontainers .shaded .org .apache .commons .lang3 .tuple .Pair ;
2427import redis .ByteStringDeserializer ;
2528import redis .ByteStringDeserializer$ ;
2629import redis .ByteStringSerializer ;
@@ -98,31 +101,26 @@ static void tearDown() throws Exception {
98101 }
99102
100103 @ Test
101- void testGetCommand () {
102- Pair <Future <Object >, Future <Option <String >>> result =
103- testing .runWithSpan (
104- "parent" ,
105- () -> {
106- ByteStringSerializer <String > serializer = ByteStringSerializer$ .MODULE$ .String ();
107- ByteStringDeserializer <String > deserializer =
108- ByteStringDeserializer$ .MODULE$ .String ();
109- Future <Object > writeFuture =
110- redisClient .set (
111- "bar" ,
112- "baz" ,
113- Option .apply (null ),
114- Option .apply (null ),
115- false ,
116- false ,
117- serializer );
118- Future <Option <String >> valueFuture = redisClient .get ("bar" , deserializer );
119- return Pair .of (writeFuture , valueFuture );
120- });
121-
122- await ().atMost (java .time .Duration .ofSeconds (3 )).until (() -> result .getLeft ().isCompleted ());
123- await ().atMost (java .time .Duration .ofSeconds (3 )).until (() -> result .getRight ().isCompleted ());
124- assertThat (result .getLeft ().value ().get ().get ()).isEqualTo (true );
125- assertThat (result .getRight ().value ().get ().get ().get ()).isEqualTo ("baz" );
104+ void testGetCommand () throws Exception {
105+ SettableFuture <Future <Object >> writeFutureRef = SettableFuture .create ();
106+ ;
107+ SettableFuture <Future <Option <String >>> valueFutureRef = SettableFuture .create ();
108+
109+ testing .runWithSpan (
110+ "parent" ,
111+ () -> {
112+ ByteStringSerializer <String > serializer = ByteStringSerializer$ .MODULE$ .String ();
113+ ByteStringDeserializer <String > deserializer = ByteStringDeserializer$ .MODULE$ .String ();
114+ writeFutureRef .set (
115+ redisClient .set (
116+ "bar" , "baz" , Option .apply (null ), Option .apply (null ), false , false , serializer ));
117+ valueFutureRef .set (redisClient .get ("bar" , deserializer ));
118+ });
119+
120+ await ().atMost (Duration .ofSeconds (3 )).until (() -> writeFutureRef .get ().isCompleted ());
121+ await ().atMost (Duration .ofSeconds (3 )).until (() -> valueFutureRef .get ().isCompleted ());
122+ assertThat (writeFutureRef .get ().value ().get ().get ()).isEqualTo (true );
123+ assertThat (valueFutureRef .get ().value ().get ().get ().get ()).isEqualTo ("baz" );
126124
127125 testing .waitAndAssertTraces (
128126 trace ->
@@ -133,15 +131,13 @@ void testGetCommand() {
133131 .hasKind (CLIENT )
134132 .hasParent (trace .getSpan (0 ))
135133 .hasAttributesSatisfyingExactly (
136- equalTo (DbIncubatingAttributes .DB_SYSTEM , "redis" ),
137- equalTo (DB_OPERATION , "SET" )),
134+ equalTo (DB_SYSTEM , REDIS ), equalTo (DB_OPERATION , "SET" )),
138135 span ->
139136 span .hasName ("GET" )
140137 .hasKind (CLIENT )
141138 .hasParent (trace .getSpan (0 ))
142139 .hasAttributesSatisfyingExactly (
143- equalTo (DbIncubatingAttributes .DB_SYSTEM , "redis" ),
144- equalTo (DB_OPERATION , "GET" ))));
140+ equalTo (DB_SYSTEM , REDIS ), equalTo (DB_OPERATION , "GET" ))));
145141 }
146142
147143 @ Test
@@ -160,7 +156,7 @@ public void testSetCommand() {
160156 false ,
161157 false ,
162158 serializer ));
163- await ().atMost (java . time . Duration .ofSeconds (3 )).until (value ::isCompleted );
159+ await ().atMost (Duration .ofSeconds (3 )).until (value ::isCompleted );
164160 assertThat (value .value ().get ().get ()).isEqualTo (true );
165161 testing .waitAndAssertTraces (
166162 trace ->
@@ -171,7 +167,6 @@ public void testSetCommand() {
171167 .hasKind (CLIENT )
172168 .hasParent (trace .getSpan (0 ))
173169 .hasAttributesSatisfying (
174- equalTo (DbIncubatingAttributes .DB_SYSTEM , "redis" ),
175- equalTo (DB_OPERATION , "SET" ))));
170+ equalTo (DB_SYSTEM , REDIS ), equalTo (DB_OPERATION , "SET" ))));
176171 }
177172}
0 commit comments