Skip to content

Commit 3ec47ca

Browse files
committed
convert to table test
1 parent 9bce9c0 commit 3ec47ca

2 files changed

Lines changed: 53 additions & 86 deletions

File tree

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,15 @@ void buildContextFromExtractedContextWithIgnoreBehavior() {
419419
assertTrue(span.getLinks().isEmpty());
420420
}
421421

422-
static Stream<TagContext> tagContextShouldPopulateDefaultSpanDetailsArguments() {
423-
return Stream.of(
424-
new TagContext(null, TagMap.fromMap(Collections.<String, Object>emptyMap())),
425-
new TagContext(
426-
"some-origin",
427-
TagMap.fromMap(Collections.<String, Object>singletonMap("asdf", "qwer"))));
428-
}
429-
430-
@ParameterizedTest
431-
@MethodSource("tagContextShouldPopulateDefaultSpanDetailsArguments")
432-
void tagContextShouldPopulateDefaultSpanDetails(TagContext tagContext) {
422+
@TableTest({
423+
"scenario | origin | tagMap ",
424+
"empty tag map | | [:] ",
425+
"some origin | some-origin | [asdf: qwer]"
426+
})
427+
void tagContextShouldPopulateDefaultSpanDetails(
428+
String scenario, String origin, Map<String, String> tagMap) {
433429
Thread thread = Thread.currentThread();
430+
TagContext tagContext = new TagContext(origin, TagMap.fromMap(tagMap));
434431
DDSpan span = (DDSpan) tracer.buildSpan("test", "op name").asChildOf(tagContext).start();
435432

436433
assertNotEquals(DDTraceId.ZERO, span.getTraceId());
@@ -462,8 +459,14 @@ static Stream<Arguments> globalSpanTagsPopulatedOnEachSpanArguments() {
462459
arguments("a:1,b-c:d", buildStringMap("a", "1", "b-c", "d")));
463460
}
464461

465-
@ParameterizedTest
466-
@MethodSource("globalSpanTagsPopulatedOnEachSpanArguments")
462+
@TableTest({
463+
"scenario | tagString | tags ",
464+
"empty | '' | [:] ",
465+
"column | is:val:id | [is: 'val:id']",
466+
"single | a:x | [a: x] ",
467+
"same multi-values | a:a,a:b,a:c | [a: c] ",
468+
"multi values | a:1,b-c:d | [a: 1, b-c: d]"
469+
})
467470
void globalSpanTagsPopulatedOnEachSpan(String tagString, Map<String, String> tags) {
468471
injectSysConfig("dd.trace.span.tags", tagString);
469472
CoreTracer customTracer = tracerBuilder().writer(writer).build();

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

Lines changed: 37 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.junit.jupiter.api.Assertions.assertNotNull;
88
import static org.junit.jupiter.api.Assertions.assertNull;
99
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
1011
import static org.mockito.ArgumentMatchers.any;
1112
import static org.mockito.ArgumentMatchers.eq;
1213
import static org.mockito.Mockito.doAnswer;
@@ -45,23 +46,19 @@
4546
import java.util.Map;
4647
import java.util.concurrent.CopyOnWriteArrayList;
4748
import java.util.concurrent.TimeUnit;
48-
import java.util.stream.Stream;
4949
import okhttp3.HttpUrl;
5050
import okhttp3.OkHttpClient;
51-
import org.junit.jupiter.api.Assumptions;
5251
import org.junit.jupiter.api.BeforeAll;
5352
import org.junit.jupiter.api.Test;
5453
import org.junit.jupiter.api.Timeout;
55-
import org.junit.jupiter.params.ParameterizedTest;
56-
import org.junit.jupiter.params.provider.MethodSource;
5754
import org.tabletest.junit.TableTest;
5855

5956
@Timeout(value = 10, unit = TimeUnit.SECONDS)
6057
public class CoreTracerTest extends DDCoreJavaSpecification {
6158

6259
@BeforeAll
6360
static void checkJvm() {
64-
Assumptions.assumeFalse(
61+
assumeFalse(
6562
JavaVirtualMachine.isOracleJDK8(),
6663
"Oracle JDK 1.8 did not merge the fix in JDK-8058322, leading to the JVM failing to"
6764
+ " correctly extract method parameters without args, when the code is compiled on a"
@@ -118,8 +115,11 @@ void verifyUdsWindows() {
118115
}
119116
}
120117

121-
@ParameterizedTest
122-
@MethodSource("verifyMappingConfigsOnTracerArguments")
118+
@TableTest({
119+
"scenario | mapString | map ",
120+
"duplicate keys | a:one, a:two, a:three | [a: three] ",
121+
"empty value | a:b,c:d,e: | [a: b, c: d]"
122+
})
123123
void verifyMappingConfigsOnTracer(String scenario, String mapString, Map<String, String> map) {
124124
injectSysConfig(TracerConfig.SERVICE_MAPPING, mapString);
125125
injectSysConfig(TracerConfig.SPAN_TAGS, mapString);
@@ -134,14 +134,11 @@ void verifyMappingConfigsOnTracer(String scenario, String mapString, Map<String,
134134
}
135135
}
136136

137-
static Stream<Object[]> verifyMappingConfigsOnTracerArguments() {
138-
return Stream.of(
139-
new Object[] {"duplicate keys", "a:one, a:two, a:three", buildStringMap("a", "three")},
140-
new Object[] {"empty value", "a:b,c:d,e:", buildStringMap("a", "b", "c", "d")});
141-
}
142-
143-
@ParameterizedTest
144-
@MethodSource("verifyBaggageMappingConfigsOnTracerArguments")
137+
@TableTest({
138+
"scenario | mapString | map ",
139+
"duplicate keys | a:one, a:two, a:three | [a: three] ",
140+
"empty value | a:b,c:d,e: | [a: b, c: d]"
141+
})
145142
void verifyBaggageMappingConfigsOnTracer(
146143
String scenario, String mapString, Map<String, String> map) {
147144
injectSysConfig(TracerConfig.BAGGAGE_MAPPING, mapString);
@@ -153,12 +150,6 @@ void verifyBaggageMappingConfigsOnTracer(
153150
}
154151
}
155152

156-
static Stream<Object[]> verifyBaggageMappingConfigsOnTracerArguments() {
157-
return Stream.of(
158-
new Object[] {"duplicate keys", "a:one, a:two, a:three", buildStringMap("a", "three")},
159-
new Object[] {"empty value", "a:b,c:d,e:", buildStringMap("a", "b", "c", "d")});
160-
}
161-
162153
@Test
163154
@WithConfig(key = "agent.host", value = "somethingelse")
164155
void verifyOverridingHost() {
@@ -353,8 +344,15 @@ void verifyConfigurationPolling() throws Exception {
353344
}
354345
}
355346

356-
@ParameterizedTest
357-
@MethodSource("verifyConfigurationPollingWithCustomTagsArguments")
347+
@TableTest({
348+
"scenario | json | expectedValue ",
349+
"a:b c:d e:f | '{\"lib_config\":{\"tracing_tags\": [\"a:b\", \"c:d\", \"e:f\"]}}' | [a: b, c: d, e: f]",
350+
"empty and c:d | '{\"lib_config\":{\"tracing_tags\": [\"\", \"c:d\", \"\"]}}' | [c: d] ",
351+
":b c: e:f | '{\"lib_config\":{\"tracing_tags\": [\":b\", \"c:\", \"e:f\"]}}' | [e: f] ",
352+
": c: e:f | '{\"lib_config\":{\"tracing_tags\": [\":\", \"c:\", \"e:f\"]}}' | [e: f] ",
353+
": c: empty | '{\"lib_config\":{\"tracing_tags\": [\":\", \"c:\", \"\"]}}' | [:] ",
354+
"empty array | '{\"lib_config\":{\"tracing_tags\": []}}' | [:] "
355+
})
358356
void verifyConfigurationPollingWithCustomTags(
359357
String scenario, String json, Map<String, String> expectedValue) throws Exception {
360358
ParsedConfigKey key = ParsedConfigKey.parse("datadog/2/APM_TRACING/config_overrides/config");
@@ -395,40 +393,22 @@ void verifyConfigurationPollingWithCustomTags(
395393
}
396394
}
397395

398-
static Stream<Object[]> verifyConfigurationPollingWithCustomTagsArguments() {
399-
return Stream.of(
400-
new Object[] {
401-
"a:b c:d e:f",
402-
"{\"lib_config\":{\"tracing_tags\": [\"a:b\", \"c:d\", \"e:f\"]}}",
403-
buildStringMap("a", "b", "c", "d", "e", "f")
404-
},
405-
new Object[] {
406-
"empty and c:d",
407-
"{\"lib_config\":{\"tracing_tags\": [\"\", \"c:d\", \"\"]}}",
408-
buildStringMap("c", "d")
409-
},
410-
new Object[] {
411-
":b c: e:f",
412-
"{\"lib_config\":{\"tracing_tags\": [\":b\", \"c:\", \"e:f\"]}}",
413-
buildStringMap("e", "f")
414-
},
415-
new Object[] {
416-
": c: e:f",
417-
"{\"lib_config\":{\"tracing_tags\": [\":\", \"c:\", \"e:f\"]}}",
418-
buildStringMap("e", "f")
419-
},
420-
new Object[] {
421-
": c: empty",
422-
"{\"lib_config\":{\"tracing_tags\": [\":\", \"c:\", \"\"]}}",
423-
Collections.emptyMap()
424-
},
425-
new Object[] {
426-
"empty array", "{\"lib_config\":{\"tracing_tags\": []}}", Collections.emptyMap()
427-
});
428-
}
429-
430-
@ParameterizedTest
431-
@MethodSource("verifyConfigurationPollingWithTracingEnabledArguments")
396+
@TableTest({
397+
"scenario | json | expectedValue ",
398+
"tracing disabled | '{\"lib_config\":{\"tracing_enabled\": false}}' | false ",
399+
"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 "
411+
})
432412
void verifyConfigurationPollingWithTracingEnabled(
433413
String scenario, String json, boolean expectedValue) throws Exception {
434414
ParsedConfigKey key = ParsedConfigKey.parse("datadog/2/APM_TRACING/config_overrides/config");
@@ -462,22 +442,6 @@ void verifyConfigurationPollingWithTracingEnabled(
462442
}
463443
}
464444

465-
static Stream<Object[]> verifyConfigurationPollingWithTracingEnabledArguments() {
466-
return Stream.of(
467-
new Object[] {"tracing disabled", "{\"lib_config\":{\"tracing_enabled\": false}}", false},
468-
new Object[] {"tracing enabled", "{\"lib_config\":{\"tracing_enabled\": true}}", true},
469-
new Object[] {
470-
"action with tracing disabled",
471-
"{\"action\": \"enable\", \"lib_config\": {\"tracing_sampling_rate\": null,"
472-
+ " \"log_injection_enabled\": null, \"tracing_header_tags\": null,"
473-
+ " \"runtime_metrics_enabled\": null, \"tracing_debug\": null,"
474-
+ " \"tracing_service_mapping\": null, \"tracing_sampling_rules\": null,"
475-
+ " \"span_sampling_rules\": null, \"data_streams_enabled\": null,"
476-
+ " \"tracing_enabled\": false}}",
477-
false
478-
});
479-
}
480-
481445
@TableTest({
482446
"scenario | preferred | expected",
483447
"no pref | | test ",

0 commit comments

Comments
 (0)