Skip to content

Commit 01e2215

Browse files
committed
flexing
1 parent e81f25f commit 01e2215

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

tests/test_languages/fixtures/java_tracer_e2e/src/main/java/com/example/Workload.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.example;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
public class Workload {
47

58
public static int computeSum(int n) {
@@ -10,15 +13,53 @@ public static int computeSum(int n) {
1013
return sum;
1114
}
1215

16+
public static String repeatString(String s, int count) {
17+
String result = "";
18+
for (int i = 0; i < count; i++) {
19+
result = result + s;
20+
}
21+
return result;
22+
}
23+
24+
public static List<Integer> filterEvens(List<Integer> numbers) {
25+
List<Integer> result = new ArrayList<>();
26+
for (int n : numbers) {
27+
if (n % 2 == 0) {
28+
result.add(n);
29+
}
30+
}
31+
return result;
32+
}
33+
34+
public int instanceMethod(int x, int y) {
35+
return x * y + computeSum(x);
36+
}
37+
1338
public static void main(String[] args) {
14-
// Run with large inputs so JFR can capture CPU samples.
39+
// Run methods with large inputs so JFR can capture CPU samples.
1540
// Small inputs finish too fast (<1ms) for JFR's 10ms sampling interval.
16-
for (int round = 0; round < 100; round++) {
41+
for (int round = 0; round < 1000; round++) {
1742
computeSum(100_000);
43+
repeatString("hello world ", 1000);
44+
45+
List<Integer> nums = new ArrayList<>();
46+
for (int i = 1; i <= 10_000; i++) nums.add(i);
47+
filterEvens(nums);
48+
49+
Workload w = new Workload();
50+
w.instanceMethod(100_000, 42);
1851
}
1952

2053
// Also call with small inputs for variety in traced args
2154
System.out.println("computeSum(100) = " + computeSum(100));
55+
System.out.println("repeatString(\"ab\", 3) = " + repeatString("ab", 3));
56+
57+
List<Integer> small = new ArrayList<>();
58+
for (int i = 1; i <= 10; i++) small.add(i);
59+
System.out.println("filterEvens(1..10) = " + filterEvens(small));
60+
61+
Workload w = new Workload();
62+
System.out.println("instanceMethod(5, 3) = " + w.instanceMethod(5, 3));
2263

2364
System.out.println("Workload complete.");
2465
}

tests/test_languages/test_java/test_java_tracer_e2e.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,14 @@ def test_agent_captures_invocations(self, compiled_workload: Path, trace_db: Pat
8181
conn = sqlite3.connect(str(trace_db))
8282
try:
8383
rows = conn.execute("SELECT function, classname, descriptor, length(args) FROM function_calls").fetchall()
84-
assert len(rows) >= 2, f"Expected at least 2 captured invocations, got {len(rows)}"
84+
assert len(rows) >= 5, f"Expected at least 5 captured invocations, got {len(rows)}"
8585

8686
# Check that specific methods were captured
8787
functions = {row[0] for row in rows}
8888
assert "computeSum" in functions
89+
assert "repeatString" in functions
90+
assert "filterEvens" in functions
91+
assert "instanceMethod" in functions
8992

9093
# Verify all rows have non-empty args blobs
9194
for row in rows:
@@ -94,7 +97,7 @@ def test_agent_captures_invocations(self, compiled_workload: Path, trace_db: Pat
9497
# Verify metadata
9598
metadata = dict(conn.execute("SELECT key, value FROM metadata").fetchall())
9699
assert "totalCaptures" in metadata
97-
assert int(metadata["totalCaptures"]) >= 2
100+
assert int(metadata["totalCaptures"]) >= 5
98101
finally:
99102
conn.close()
100103

@@ -133,7 +136,7 @@ def test_max_function_count_limit(self, compiled_workload: Path, trace_db: Path)
133136

134137
conn = sqlite3.connect(str(trace_db))
135138
try:
136-
# computeSum is called 2 times (direct calls in main)
139+
# computeSum is called 4 times (2 direct + 2 from instanceMethod)
137140
compute_count = conn.execute(
138141
"SELECT COUNT(*) FROM function_calls WHERE function = 'computeSum'"
139142
).fetchone()[0]
@@ -196,6 +199,7 @@ def test_generates_test_files(self, compiled_workload: Path, trace_db: Path, tmp
196199
assert "import org.junit.jupiter.api.Test;" in content
197200
assert "ReplayHelper" in content
198201
assert "replay_computeSum_0" in content
202+
assert "replay_repeatString_0" in content
199203

200204
def test_metadata_parsing(self, compiled_workload: Path, trace_db: Path, tmp_path: Path) -> None:
201205
"""Test that metadata comments are correctly parsed from generated tests."""
@@ -292,6 +296,7 @@ def test_full_trace_and_replay_generation(self, compiled_workload: Path, tmp_pat
292296
assert len(workload_files) == 1
293297
content = workload_files[0].read_text(encoding="utf-8")
294298
assert "replay_computeSum" in content
299+
assert "replay_instanceMethod" in content
295300

296301
def test_package_detection(self) -> None:
297302
"""Test that package detection finds Java packages from source files."""

tests/test_languages/test_java/test_java_tracer_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def test_discover_functions_from_replay_tests(self, traced_workload: tuple) -> N
8888
assert func.file_path == file_path
8989

9090
assert "computeSum" in all_func_names
91+
assert "repeatString" in all_func_names
9192

9293
def test_discover_tests_for_replay_tests(self, traced_workload: tuple) -> None:
9394
"""Test that test discovery maps replay tests to source functions."""
@@ -111,6 +112,7 @@ def test_discover_tests_for_replay_tests(self, traced_workload: tuple) -> None:
111112
matched_func_names.add(func_name)
112113

113114
assert "computeSum" in matched_func_names, f"computeSum not found in: {result.keys()}"
115+
assert "repeatString" in matched_func_names, f"repeatString not found in: {result.keys()}"
114116

115117
# Each function should have at least one test
116118
for func_name, test_infos in result.items():

0 commit comments

Comments
 (0)