Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'java-test-fixtures'
}

apply from: "$rootDir/gradle/java.gradle"
apply plugin: 'idea'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ public class JfpUtilsTest {
private static final String CONFIG_ENTRY = "jdk.ThreadAllocationStatistics#enabled";
private static final String CONFIG_OVERRIDE_ENTRY = "test.continuous.override#value";

public static final String OVERRIDES =
JfpUtilsTest.class.getClassLoader().getResource("overrides.jfp").getFile();
public static final String OVERRIDES_OLD_OBJECT_SAMPLE =
JfpUtilsTest.class.getClassLoader().getResource("overrides-oldobjectsample.jfp").getFile();
public static final String OVERRIDES_OBJECT_ALLOCATION =
JfpUtilsTest.class.getClassLoader().getResource("overrides-objectallocation.jfp").getFile();
public static final String OVERRIDES_NATIVE_METHOD_SAMPLE =
JfpUtilsTest.class.getClassLoader().getResource("overrides-nativemethodsample.jfp").getFile();

@Test
public void testLoadingInvalidOverride() throws IOException {
final String INVALID_OVERRIDE = "really_non_existent_file.jfp";
Expand All @@ -42,7 +33,8 @@ public void testLoadingContinuousConfig() throws IOException {

@Test
public void testLoadingContinuousConfigWithOverride() throws IOException {
final Map<String, String> config = JfpUtils.readJfpResources(JfpUtils.DEFAULT_JFP, OVERRIDES);
final Map<String, String> config =
JfpUtils.readJfpResources(JfpUtils.DEFAULT_JFP, JfpTestResources.overrides());
assertEquals("true", config.get(CONFIG_ENTRY));
assertEquals("200", config.get(CONFIG_OVERRIDE_ENTRY));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.datadog.profiling.controller.jfr;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.atomic.AtomicReference;

public final class JfpTestResources {
private static final AtomicReference<String> overrides = new AtomicReference<>();
private static final AtomicReference<String> overridesOldObjectSample = new AtomicReference<>();
private static final AtomicReference<String> overridesObjectAllocation = new AtomicReference<>();
private static final AtomicReference<String> overridesNativeMethodSample =
new AtomicReference<>();

private JfpTestResources() {}

public static String overrides() {
return get(overrides, "overrides.jfp");
}

public static String overridesOldObjectSample() {
return get(overridesOldObjectSample, "overrides-oldobjectsample.jfp");
}

public static String overridesObjectAllocation() {
return get(overridesObjectAllocation, "overrides-objectallocation.jfp");
}

public static String overridesNativeMethodSample() {
return get(overridesNativeMethodSample, "overrides-nativemethodsample.jfp");
}

private static String get(AtomicReference<String> ref, String resourceName) {
String v = ref.get();
if (v != null) {
return v;
}
String computed = extract(resourceName);
return ref.compareAndSet(null, computed) ? computed : ref.get();
}

// Resources packaged in the testFixtures jar are not directly accessible as filesystem paths.
// Extract to a temp file so callers can use the path with java.io.File.
private static String extract(String resourceName) {
try {
Path temp = Files.createTempFile(resourceName.replace('.', '_'), ".jfp");
temp.toFile().deleteOnExit();
try (InputStream is =
JfpTestResources.class.getClassLoader().getResourceAsStream(resourceName)) {
if (is == null) {
throw new IllegalStateException("Test resource not found on classpath: " + resourceName);
}
Files.copy(is, temp, StandardCopyOption.REPLACE_EXISTING);
}
return temp.toAbsolutePath().toString();
} catch (IOException e) {
throw new RuntimeException("Failed to extract test resource: " + resourceName, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {

testImplementation libs.bundles.junit5
testImplementation libs.bundles.mockito
testImplementation files(project(':dd-java-agent:agent-profiling:profiling-controller-jfr').sourceSets.test.output)
testImplementation(testFixtures(project(':dd-java-agent:agent-profiling:profiling-controller-jfr')))
testImplementation project(':dd-java-agent:agent-profiling')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import com.datadog.profiling.controller.ControllerContext;
import com.datadog.profiling.controller.jfr.JfpUtilsTest;
import com.datadog.profiling.controller.jfr.JfpTestResources;
import com.datadog.profiling.utils.ProfilingMode;
import datadog.environment.JavaVirtualMachine;
import datadog.trace.api.profiling.RecordingData;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void testHeapProfilerIsDisabledOnUnsupportedVersion() throws Exception {
@Test
public void testHeapProfilerIsStillOverriddenOnUnsupportedVersion() throws Exception {
Properties props = getConfigProperties();
props.put(PROFILING_TEMPLATE_OVERRIDE_FILE, JfpUtilsTest.OVERRIDES_OLD_OBJECT_SAMPLE);
props.put(PROFILING_TEMPLATE_OVERRIDE_FILE, JfpTestResources.overridesOldObjectSample());

ConfigProvider configProvider = ConfigProvider.withPropertiesOverride(props);

Expand Down Expand Up @@ -158,7 +158,7 @@ public void testAllocationProfilerIsDisabledOnUnsupportedVersion() throws Except
@Test
public void testAllocationProfilerIsStillOverriddenOnUnsupportedVersion() throws Exception {
Properties props = getConfigProperties();
props.put(PROFILING_TEMPLATE_OVERRIDE_FILE, JfpUtilsTest.OVERRIDES_OBJECT_ALLOCATION);
props.put(PROFILING_TEMPLATE_OVERRIDE_FILE, JfpTestResources.overridesObjectAllocation());
ConfigProvider configProvider = ConfigProvider.withPropertiesOverride(props);

OpenJdkController controller = new OpenJdkController(configProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies {

testImplementation libs.bundles.junit5
testImplementation libs.bundles.mockito
testImplementation files(project(':dd-java-agent:agent-profiling:profiling-controller-jfr').sourceSets.test.output)
testImplementation project(':dd-java-agent:agent-profiling')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))

testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

testImplementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
transitive = false
}

testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuiteForDir('latestDepTest', 'test')

dependencies {
testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

// We need to pull in this dependency to get the 'suspend span' instrumentation for spock tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuiteForDir('latestDepTest', 'test')

dependencies {
testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()

// We need to pull in this dependency to get the 'suspend span' instrumentation for spock tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies {
}

testImplementation testFixtures(project(':dd-java-agent:instrumentation:mongo:mongo-common'))
testImplementation project(':dd-java-agent:instrumentation:mongo:mongo-common').sourceSets.test.output
testImplementation group: 'org.testcontainers', name: 'mongodb', version: libs.versions.testcontainers.get()


Expand Down