Skip to content

Commit ad5d7c7

Browse files
committed
use tabletest and custom type converter
1 parent 3ec47ca commit ad5d7c7

2 files changed

Lines changed: 70 additions & 164 deletions

File tree

dd-trace-core/src/test/java/datadog/trace/core/CoreTracerTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,21 +393,25 @@ void verifyConfigurationPollingWithCustomTags(
393393
}
394394
}
395395

396+
static final String ACTION_JSON =
397+
"'{\"action\": \"enable\", \"lib_config\":"
398+
+ "{\"tracing_sampling_rate\": null,"
399+
+ " \"log_injection_enabled\": null, "
400+
+ "\"tracing_header_tags\": null,"
401+
+ " \"runtime_metrics_enabled\": null,"
402+
+ "\"tracing_debug\": null,"
403+
+ " \"tracing_service_mapping\": null,"
404+
+ "\"tracing_sampling_rules\": null,"
405+
+ " \"span_sampling_rules\": null,"
406+
+ "\"data_streams_enabled\": null,"
407+
+ " \"tracing_enabled\": false}}'";
408+
396409
@TableTest({
397410
"scenario | json | expectedValue ",
398411
"tracing disabled | '{\"lib_config\":{\"tracing_enabled\": false}}' | false ",
399412
"tracing enabled | '{\"lib_config\":{\"tracing_enabled\": true}}' | true ",
400-
"action with tracing disabled | '{\"action\": \"enable\", \"lib_config\": ",
401-
"{\"tracing_sampling_rate\": null, ",
402-
" \"log_injection_enabled\": null, ",
403-
"\"tracing_header_tags\": null, ",
404-
" \"runtime_metrics_enabled\": null, ",
405-
"\"tracing_debug\": null, ",
406-
" \"tracing_service_mapping\": null, ",
407-
"\"tracing_sampling_rules\": null, ",
408-
" \"span_sampling_rules\": null, ",
409-
"\"data_streams_enabled\": null, ",
410-
" \"tracing_enabled\": false}}' | false "
413+
"action with tracing disabled | ",
414+
" | false "
411415
})
412416
void verifyConfigurationPollingWithTracingEnabled(
413417
String scenario, String json, boolean expectedValue) throws Exception {

dd-trace-core/src/test/java/datadog/trace/core/DDSpanContextPropagationTagsTest.java

Lines changed: 55 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
import static datadog.trace.api.sampling.SamplingMechanism.DEFAULT;
1010
import static datadog.trace.api.sampling.SamplingMechanism.MANUAL;
1111
import static org.junit.jupiter.api.Assertions.assertEquals;
12-
import static org.junit.jupiter.params.provider.Arguments.arguments;
1312

1413
import datadog.trace.api.DDTraceId;
1514
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
1615
import datadog.trace.common.writer.ListWriter;
1716
import datadog.trace.core.propagation.ExtractedContext;
1817
import datadog.trace.core.propagation.PropagationTags;
19-
import java.util.HashMap;
18+
import datadog.trace.junit.utils.tabletest.TableTestTypeConverters;
2019
import java.util.Map;
21-
import java.util.stream.Stream;
2220
import org.junit.jupiter.api.BeforeEach;
23-
import org.junit.jupiter.params.ParameterizedTest;
24-
import org.junit.jupiter.params.provider.Arguments;
25-
import org.junit.jupiter.params.provider.MethodSource;
21+
import org.tabletest.junit.TableTest;
22+
import org.tabletest.junit.TypeConverter;
23+
import org.tabletest.junit.TypeConverterSources;
2624

25+
@TypeConverterSources(TableTestTypeConverters.class)
2726
public class DDSpanContextPropagationTagsTest extends DDCoreJavaSpecification {
2827

2928
private ListWriter writer;
@@ -35,8 +34,14 @@ void setup() {
3534
tracer = tracerBuilder().writer(writer).build();
3635
}
3736

38-
@ParameterizedTest()
39-
@MethodSource("updateSpanPropagationTagsArguments")
37+
@TableTest({
38+
"scenario | priority | header | newPriority | newMechanism | newHeader | tagMap ",
39+
"UNSET->USER_KEEP | UNSET | _dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123] ",
40+
"UNSET->SAMPLER_DROP | UNSET | _dd.p.usr=123 | SAMPLER_DROP | DEFAULT | _dd.p.usr=123 | [_dd.p.usr: 123] ",
41+
"SAMPLER_KEEP->USER_KEEP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | [_dd.p.dm: 9bf3439f2f-1, _dd.p.usr: 123]",
42+
"SAMPLER_KEEP->USER_DROP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | USER_DROP | MANUAL | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | [_dd.p.dm: 9bf3439f2f-1, _dd.p.usr: 123]",
43+
"SAMPLER_KEEP->USER_KEEP no dm | SAMPLER_KEEP | _dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.usr=123 | [_dd.p.usr: 123] "
44+
})
4045
void updateSpanPropagationTags(
4146
String scenario,
4247
int priority,
@@ -61,53 +66,14 @@ void updateSpanPropagationTags(
6166
assertEquals(tagMap, dd.createTagMap());
6267
}
6368

64-
static Stream<Arguments> updateSpanPropagationTagsArguments() {
65-
return Stream.of(
66-
arguments(
67-
"UNSET->USER_KEEP",
68-
UNSET,
69-
"_dd.p.usr=123",
70-
USER_KEEP,
71-
MANUAL,
72-
"_dd.p.dm=-4,_dd.p.usr=123",
73-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
74-
arguments(
75-
"UNSET->SAMPLER_DROP",
76-
UNSET,
77-
"_dd.p.usr=123",
78-
SAMPLER_DROP,
79-
DEFAULT,
80-
"_dd.p.usr=123",
81-
buildMap("_dd.p.usr", "123")),
82-
// decision has already been made, propagate as-is
83-
arguments(
84-
"SAMPLER_KEEP->USER_KEEP with dm",
85-
SAMPLER_KEEP,
86-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
87-
USER_KEEP,
88-
MANUAL,
89-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
90-
buildMap("_dd.p.dm", "9bf3439f2f-1", "_dd.p.usr", "123")),
91-
arguments(
92-
"SAMPLER_KEEP->USER_DROP with dm",
93-
SAMPLER_KEEP,
94-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
95-
USER_DROP,
96-
MANUAL,
97-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
98-
buildMap("_dd.p.dm", "9bf3439f2f-1", "_dd.p.usr", "123")),
99-
arguments(
100-
"SAMPLER_KEEP->USER_KEEP no dm",
101-
SAMPLER_KEEP,
102-
"_dd.p.usr=123",
103-
USER_KEEP,
104-
MANUAL,
105-
"_dd.p.usr=123",
106-
buildMap("_dd.p.usr", "123")));
107-
}
108-
109-
@ParameterizedTest
110-
@MethodSource("updateTracePropagationTagsArguments")
69+
@TableTest({
70+
"scenario | priority | header | newPriority | newMechanism | rootHeader | rootTagMap ",
71+
"UNSET->USER_KEEP | UNSET | _dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123] ",
72+
"UNSET->SAMPLER_DROP | UNSET | _dd.p.usr=123 | SAMPLER_DROP | DEFAULT | _dd.p.usr=123 | [_dd.p.usr: 123] ",
73+
"SAMPLER_KEEP->USER_KEEP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | [_dd.p.dm: 9bf3439f2f-1, _dd.p.usr: 123]",
74+
"SAMPLER_KEEP->USER_DROP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | USER_DROP | MANUAL | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | [_dd.p.dm: 9bf3439f2f-1, _dd.p.usr: 123]",
75+
"SAMPLER_KEEP->USER_KEEP no dm | SAMPLER_KEEP | _dd.p.usr=123 | USER_KEEP | MANUAL | _dd.p.usr=123 | [_dd.p.usr: 123] "
76+
})
11177
void updateTracePropagationTags(
11278
String scenario,
11379
int priority,
@@ -133,53 +99,12 @@ void updateTracePropagationTags(
13399
assertEquals(rootTagMap, ddRoot.createTagMap());
134100
}
135101

136-
static Stream<Arguments> updateTracePropagationTagsArguments() {
137-
return Stream.of(
138-
arguments(
139-
"UNSET->USER_KEEP",
140-
UNSET,
141-
"_dd.p.usr=123",
142-
USER_KEEP,
143-
MANUAL,
144-
"_dd.p.dm=-4,_dd.p.usr=123",
145-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
146-
arguments(
147-
"UNSET->SAMPLER_DROP",
148-
UNSET,
149-
"_dd.p.usr=123",
150-
SAMPLER_DROP,
151-
DEFAULT,
152-
"_dd.p.usr=123",
153-
buildMap("_dd.p.usr", "123")),
154-
// decision has already been made, propagate as-is
155-
arguments(
156-
"SAMPLER_KEEP->USER_KEEP with dm",
157-
SAMPLER_KEEP,
158-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
159-
USER_KEEP,
160-
MANUAL,
161-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
162-
buildMap("_dd.p.dm", "9bf3439f2f-1", "_dd.p.usr", "123")),
163-
arguments(
164-
"SAMPLER_KEEP->USER_DROP with dm",
165-
SAMPLER_KEEP,
166-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
167-
USER_DROP,
168-
MANUAL,
169-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
170-
buildMap("_dd.p.dm", "9bf3439f2f-1", "_dd.p.usr", "123")),
171-
arguments(
172-
"SAMPLER_KEEP->USER_KEEP no dm",
173-
SAMPLER_KEEP,
174-
"_dd.p.usr=123",
175-
USER_KEEP,
176-
MANUAL,
177-
"_dd.p.usr=123",
178-
buildMap("_dd.p.usr", "123")));
179-
}
180-
181-
@ParameterizedTest
182-
@MethodSource("forceKeepSpanPropagationTagsArguments")
102+
@TableTest({
103+
"scenario | priority | header | newHeader | tagMap ",
104+
"UNSET | UNSET | _dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]",
105+
"SAMPLER_KEEP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]",
106+
"SAMPLER_KEEP no dm | SAMPLER_KEEP | _dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]"
107+
})
183108
void forceKeepSpanPropagationTags(
184109
String scenario, int priority, String header, String newHeader, Map<String, String> tagMap) {
185110
PropagationTags propagationTags =
@@ -198,30 +123,12 @@ void forceKeepSpanPropagationTags(
198123
assertEquals(tagMap, dd.createTagMap());
199124
}
200125

201-
static Stream<Arguments> forceKeepSpanPropagationTagsArguments() {
202-
return Stream.of(
203-
arguments(
204-
"UNSET",
205-
UNSET,
206-
"_dd.p.usr=123",
207-
"_dd.p.dm=-4,_dd.p.usr=123",
208-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
209-
arguments(
210-
"SAMPLER_KEEP with dm",
211-
SAMPLER_KEEP,
212-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
213-
"_dd.p.dm=-4,_dd.p.usr=123",
214-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
215-
arguments(
216-
"SAMPLER_KEEP no dm",
217-
SAMPLER_KEEP,
218-
"_dd.p.usr=123",
219-
"_dd.p.dm=-4,_dd.p.usr=123",
220-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")));
221-
}
222-
223-
@ParameterizedTest
224-
@MethodSource("forceKeepTracePropagationTagsArguments")
126+
@TableTest({
127+
"scenario | priority | header | newHeader | tagMap ",
128+
"UNSET | UNSET | _dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]",
129+
"SAMPLER_KEEP with dm | SAMPLER_KEEP | _dd.p.dm=9bf3439f2f-1,_dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]",
130+
"SAMPLER_KEEP no dm | SAMPLER_KEEP | _dd.p.usr=123 | _dd.p.dm=-4,_dd.p.usr=123 | [_dd.p.dm: -4, _dd.p.usr: 123]"
131+
})
225132
void forceKeepTracePropagationTags(
226133
String scenario,
227134
int priority,
@@ -245,33 +152,28 @@ void forceKeepTracePropagationTags(
245152
assertEquals(rootTagMap, ddRoot.createTagMap());
246153
}
247154

248-
static Stream<Arguments> forceKeepTracePropagationTagsArguments() {
249-
return Stream.of(
250-
arguments(
251-
"UNSET",
252-
UNSET,
253-
"_dd.p.usr=123",
254-
"_dd.p.dm=-4,_dd.p.usr=123",
255-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
256-
arguments(
257-
"SAMPLER_KEEP with dm",
258-
SAMPLER_KEEP,
259-
"_dd.p.dm=9bf3439f2f-1,_dd.p.usr=123",
260-
"_dd.p.dm=-4,_dd.p.usr=123",
261-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")),
262-
arguments(
263-
"SAMPLER_KEEP no dm",
264-
SAMPLER_KEEP,
265-
"_dd.p.usr=123",
266-
"_dd.p.dm=-4,_dd.p.usr=123",
267-
buildMap("_dd.p.dm", "-4", "_dd.p.usr", "123")));
268-
}
269-
270-
private static Map<String, String> buildMap(String... keyValues) {
271-
Map<String, String> map = new HashMap<>();
272-
for (int i = 0; i < keyValues.length; i += 2) {
273-
map.put(keyValues[i], keyValues[i + 1]);
155+
@TypeConverter
156+
public static int toInt(String value) {
157+
if (value == null) {
158+
throw new IllegalArgumentException("Value cannot be null");
159+
}
160+
switch (value) {
161+
case "UNSET":
162+
return UNSET;
163+
case "SAMPLER_KEEP":
164+
return SAMPLER_KEEP;
165+
case "SAMPLER_DROP":
166+
return SAMPLER_DROP;
167+
case "USER_DROP":
168+
return USER_DROP;
169+
case "USER_KEEP":
170+
return USER_KEEP;
171+
case "MANUAL":
172+
return MANUAL;
173+
case "DEFAULT":
174+
return DEFAULT;
175+
default:
176+
throw new IllegalArgumentException("Value is invalid for " + value);
274177
}
275-
return map;
276178
}
277179
}

0 commit comments

Comments
 (0)