Skip to content

Migrate utils module Groovy tests to Java tests#11569

Open
sarahchen6 wants to merge 6 commits into
masterfrom
sarahchen6/migrate-utils-tests
Open

Migrate utils module Groovy tests to Java tests#11569
sarahchen6 wants to merge 6 commits into
masterfrom
sarahchen6/migrate-utils-tests

Conversation

@sarahchen6
Copy link
Copy Markdown
Contributor

What Does This Do

Migrate Groovy tests in the utils module to Java without changing any functionality

Introduce TableTest converter for boxed values

Motivation

This is part of a broader initiative to migrate all testing in this repo to JUnit

Additional Notes

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level (note: the PR still needs to be mergeable, this will only skip the pre-merge build)
    • Get more information in this doc

Jira ticket: [PROJ-IDENT]

@sarahchen6 sarahchen6 added comp: testing Testing tag: no release notes Changes to exclude from release notes tag: ai generated Largely based on code generated by an AI or LLM labels Jun 4, 2026
}

@ParameterizedTest
@MethodSource("convertIterableMapAndBitSetArguments")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't sure how to convert this to a TableTest in a simple manner since the method takes multiple types... let me know if you have recommendations!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass strings and do simple parsing? Or introduce convertion function?

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 4, 2026

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.96 s 13.98 s [-1.0%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.84 s 12.99 s [-2.0%; -0.3%] (maybe better)
startup:petclinic:appsec:Agent 16.52 s 16.23 s [+0.9%; +2.7%] (maybe worse)
startup:petclinic:iast:Agent 16.62 s 16.55 s [-1.0%; +1.7%] (no difference)
startup:petclinic:profiling:Agent 16.26 s 16.47 s [-2.8%; +0.3%] (no difference)
startup:petclinic:tracing:Agent 15.71 s 15.11 s [-4.8%; +12.7%] (unstable)

Commit: 54ccc2aa · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

StableConfigSource stableConfigSource =
new StableConfigSource(filePath.toString(), ConfigOrigin.LOCAL_STABLE_CONFIG);

// Create ConfigProvider via reflection (constructor is private)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternative was having this test file a stableconfig subfolder so that package-private safeToString() can be accessed 🤔

// spotless:on

@ParameterizedTest
@MethodSource("containerInfoParsedFromFileContentArguments")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This MethodSource was kept for readability -- TableTest requires inputs to be on one line

@datadog-datadog-prod-us1-2

This comment has been minimized.

@sarahchen6 sarahchen6 marked this pull request as ready for review June 4, 2026 20:55
@sarahchen6 sarahchen6 requested review from a team as code owners June 4, 2026 20:55
@sarahchen6 sarahchen6 requested a review from mhlidd June 4, 2026 20:55
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54ccc2aa75

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


@TableTest({
"configId | defaultConfigs ",
"'' | [:] ",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Assert parsed stable config values

For the non-empty stable-config case, this test now only checks that constructing StableConfigSource returns an object, so it would pass even if StableConfigSource silently ignored every apm_configuration_default entry. The migrated Groovy test exercised stableCfg.get(...) for each default key; keeping that assertion is important because this is the case that protects stable-config defaults from being parsed but then dropped before consumers read them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left minor comments about code style

import java.util.Map;
import org.junit.jupiter.api.Test;

public class CapturedEnvironmentTest extends DDJavaSpecification {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to extends DDJavaSpecification here? Or am I missing where it used?

Comment on lines +21 to +93
@Test
void nonAutodetectedServiceNameWithNullCommand() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties("null");

assertNull(serviceName);
}

@Test
void nonAutodetectedServiceNameWithEmptyCommand() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties("");

assertNull(serviceName);
}

@Test
void nonAutodetectedServiceNameWithAllBlanksCommand() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties(" ");

assertNull(serviceName);
}

@Test
void setServiceNameBySyspropSunJavaCommandWithClass() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties("org.example.App -Dfoo=bar arg2 arg3");

assertEquals("org.example.App", serviceName);
}

@Test
void setServiceNameBySyspropSunJavaCommandWithJar() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties("foo/bar/example.jar -Dfoo=bar arg2 arg3");

assertEquals("example", serviceName);
}

@Test
void setServiceNameWithRealSunJavaCommandProperty() throws IOException, InterruptedException {
String serviceName = forkAndRunProperties(null);

assertEquals(ServiceNamePrinter.class.getName(), serviceName);
}

@Test
void useAzureSiteNameInAzure() throws IOException, InterruptedException {
HashMap<String, String> azureEnvVars = new HashMap<>();
azureEnvVars.put("DD_AZURE_APP_SERVICES", "1");
azureEnvVars.put("WEBSITE_SITE_NAME", "siteService");

String serviceName =
forkAndRunProperties("foo/bar/example.jar -Dfoo=bar arg2 arg3", azureEnvVars);

assertEquals("siteService", serviceName);
}

@Test
void dontUseSiteNameWhenNotInAzure() throws IOException, InterruptedException {
String serviceName =
forkAndRunProperties(
"foo/bar/example.jar -Dfoo=bar arg2 arg3",
Collections.singletonMap("WEBSITE_SITE_NAME", "siteService"));

assertEquals("example", serviceName);
}

@Test
void dontUseAzureSiteNameWhenNull() throws IOException, InterruptedException {
String serviceName =
forkAndRunProperties(
"foo/bar/example.jar -Dfoo=bar arg2 arg3",
Collections.singletonMap("DD_AZURE_APP_SERVICES", "true"));

assertEquals("example", serviceName);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have feeling that all this tests can be refactored to @TableTest

Comment on lines +21 to +34
@TableTest({
"scenario | key1 | key2 | value1 | value2 | origin1 | origin2 ",
"equal | key | key | value | value | DEFAULT | DEFAULT ",
"different key | key | key2 | value | value | ENV | ENV ",
"different value | key | key | value2 | value | JVM_PROP | JVM_PROP",
"different origin | key | key | value | value | ENV | DEFAULT "
})
void supportsEqualityCheck(
String key1,
String key2,
Object value1,
Object value2,
ConfigOrigin origin1,
ConfigOrigin origin2) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: may be re-group a bit: k1, v1, o1, k2, v2, o2? WDYT?

Comment on lines +35 to +50
// when
ConfigSetting cs1 = ConfigSetting.of(key1, value1, origin1);
ConfigSetting cs2 = ConfigSetting.of(key2, value2, origin2);

// then
if (key1.equals(key2) && value1.equals(value2) && origin1 == origin2) {
assertEquals(cs1.hashCode(), cs2.hashCode());
assertEquals(cs1, cs2);
assertEquals(cs2, cs1);
assertEquals(cs1.toString(), cs2.toString());
} else {
assertNotEquals(cs1.hashCode(), cs2.hashCode());
assertNotEquals(cs1, cs2);
assertNotEquals(cs2, cs1);
assertNotEquals(cs1.toString(), cs2.toString());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 1. such //when & //then comments make almost no sense.
nit: 2. Probably instead of if (key1.equals(key2) && value1.equals(value2) && origin1 == origin2) {} else {}
better to introduce one more param smth. like expectedEqual and check it instead.

}

@ParameterizedTest
@MethodSource("convertIterableMapAndBitSetArguments")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pass strings and do simple parsing? Or introduce convertion function?

assertTrue(exception.getMessage().contains("Invalid boolean value:"));
}

// spotless:off
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotless failed here? If yes, can you manually align table columns?

expected,
ConfigConverter.parseMapWithOptionalMappings(mapString, "test", defaultPrefix, lowercaseKeys));
}
// spotless:on
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to do on/off in small blocks as possible.

import java.util.Map;
import org.tabletest.junit.TableTest;

public class ConfigConverterTest extends DDJavaSpecification {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same DDJavaSpecification question... here and all similar places.

} catch (NumberFormatException ignored) {
}
return s;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add empty lines between if... to improve readability...

    if (source == null) return null;
    
    String s = source.toString();
    if (s.isEmpty()) return null;
    
    if ("true".equals(s)) return Boolean.TRUE;

    if ("false".equals(s)) return Boolean.FALSE;

    if (s.endsWith("f")) {
...


public class TimeUtilsTest extends DDJavaSpecification {

// spotless:off
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotless should work with TableTest...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: testing Testing tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants