Skip to content

Commit caae0f7

Browse files
authored
Migrate dd-trace-core groovy files to java part 3 (#11085)
Migrate dd-trace-core groovy files to java part 3 we migrate 3 small tests: - BlackholeSpanTest - LongRunningTracesTrackerTest - TraceCorrelationTest using new SpanConfigExtension for injecting config replace injectSysConfig by @WithConfig spotless replace tabletest by valuesource for single param Co-authored-by: jean-philippe.bempel <jean-philippe.bempel@datadoghq.com>
1 parent 693449b commit caae0f7

File tree

11 files changed

+408
-345
lines changed

11 files changed

+408
-345
lines changed

.claude/skills/migrate-groovy-to-java/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ When converting Groovy code to Java code, make sure that:
2020
- `@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup.
2121
- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`.
2222
- If `@TableTest` is not viable for the test at all, use `@MethodSource` only.
23+
- If `@TableTest` was successfully used and if the `@ParameterizedTest` is not used to specify the test name, `@ParameterizedTest` can then be removed as `@TableTest` replace it fully.
2324
- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import.
2425
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.arguments(...)` value or index the test case
2526
- When converting tuples, create a light dedicated structure instead to keep the typing system

dd-trace-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ dependencies {
107107
testImplementation group: 'com.amazonaws', name: 'aws-lambda-java-events', version:'3.11.0'
108108
testImplementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.14.0'
109109
testImplementation libs.testcontainers
110+
testImplementation project(':utils:junit-utils')
110111

111112
traceAgentTestImplementation libs.testcontainers
112113
}

dd-trace-core/src/main/java/datadog/trace/core/LongRunningTracesTracker.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,14 @@ private void flushStats() {
139139
write = 0;
140140
expired = 0;
141141
}
142+
143+
// @VisibleForTesting
144+
int trackedCount() {
145+
return traceArray.size();
146+
}
147+
148+
// @VisibleForTesting
149+
int getDropped() {
150+
return dropped;
151+
}
142152
}

dd-trace-core/src/main/java/datadog/trace/core/PendingTrace.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ boolean compareAndSetLongRunningState(int expected, int newState) {
223223
return LONG_RUNNING_STATE.compareAndSet(this, expected, newState);
224224
}
225225

226+
// @VisibleForTesting
227+
int getLongRunningTrackedState() {
228+
return longRunningTrackedState;
229+
}
230+
231+
// @VisibleForTesting
232+
void setLongRunningTrackedState(int state) {
233+
LONG_RUNNING_STATE.set(this, state);
234+
}
235+
226236
boolean empty() {
227237
return 0 >= COMPLETED_SPAN_COUNT.get(this) + PENDING_REFERENCE_COUNT.get(this);
228238
}

dd-trace-core/src/main/java/datadog/trace/core/PendingTraceBuffer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public interface Element {
5454
boolean writeOnBufferFull();
5555
}
5656

57-
private static class DelayingPendingTraceBuffer extends PendingTraceBuffer {
57+
static class DelayingPendingTraceBuffer extends PendingTraceBuffer {
5858
private static final long FORCE_SEND_DELAY_MS = TimeUnit.SECONDS.toMillis(5);
5959
private static final long SEND_DELAY_NS = TimeUnit.MILLISECONDS.toNanos(500);
6060
private static final long SLEEP_TIME_MS = 100;
@@ -303,6 +303,11 @@ public DelayingPendingTraceBuffer(
303303
config, bufferSize, sharedCommunicationObjects, healthMetrics)
304304
: null;
305305
}
306+
307+
// @VisibleForTesting
308+
LongRunningTracesTracker getRunningTracesTracker() {
309+
return runningTracesTracker;
310+
}
306311
}
307312

308313
static class DiscardingPendingTraceBuffer extends PendingTraceBuffer {

dd-trace-core/src/test/groovy/datadog/trace/core/BlackholeSpanTest.groovy

Lines changed: 0 additions & 51 deletions
This file was deleted.

dd-trace-core/src/test/groovy/datadog/trace/core/LongRunningTracesTrackerTest.groovy

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)