apparently perfomance fix that doesn't bring regreesions, NOT SURE
This commit is contained in:
@@ -140,4 +140,26 @@ class StrictFqnMatchingEngineTest {
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMatchValueOfWithCorrectEnum() {
|
||||
Event smEvent = Event.of("PAY", "com.example.OrderEvents.PAY");
|
||||
TriggerPoint triggerPoint = TriggerPoint.builder()
|
||||
.event("OrderEvents.valueOf(str)")
|
||||
.eventTypeFqn("com.example.OrderEvents")
|
||||
.build();
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotMatchValueOfWithIncorrectEnum() {
|
||||
Event smEvent = Event.of("PAY", "com.example.InvoiceEvents.PAY");
|
||||
TriggerPoint triggerPoint = TriggerPoint.builder()
|
||||
.event("OrderEvents.valueOf(str)")
|
||||
.eventTypeFqn("com.example.OrderEvents")
|
||||
.build();
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ class EnterpriseBugsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindPathsUsingInterfaceImplementationFallback(@TempDir Path tempDir) throws IOException {
|
||||
void shouldFindPathsUsingEagerEntryPointExpansion(@TempDir Path tempDir) throws IOException {
|
||||
String apiSrc = """
|
||||
package com.example;
|
||||
public interface OrderApi {
|
||||
@@ -201,66 +201,45 @@ class EnterpriseBugsTest {
|
||||
context.scan(tempDir);
|
||||
|
||||
HeuristicCallGraphEngine engine = new HeuristicCallGraphEngine(context);
|
||||
var graph = engine.buildCallGraph();
|
||||
|
||||
CallGraphPathFinder pathFinder = new CallGraphPathFinder(context);
|
||||
List<List<String>> paths = pathFinder.findAllPaths("com.example.OrderApi.submit", "com.example.OrderService.trigger", graph, new java.util.HashSet<>());
|
||||
EntryPoint entryPoint = EntryPoint.builder()
|
||||
.className("com.example.OrderApi")
|
||||
.methodName("submit")
|
||||
.build();
|
||||
TriggerPoint triggerPoint = TriggerPoint.builder()
|
||||
.className("com.example.OrderService")
|
||||
.methodName("trigger")
|
||||
.event("EVENT")
|
||||
.build();
|
||||
|
||||
assertThat(paths).hasSize(1);
|
||||
assertThat(paths.get(0)).containsExactly(
|
||||
"com.example.OrderApi.submit",
|
||||
"com.example.OrderController.submit",
|
||||
"com.example.OrderService.trigger"
|
||||
List<CallChain> chains = engine.findChains(List.of(entryPoint), List.of(triggerPoint));
|
||||
|
||||
assertThat(chains).hasSize(1);
|
||||
assertThat(chains.get(0).getMethodChain()).contains(
|
||||
"com.example.OrderController.submit"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotPolymorphicallyExpandFunctionalInterfaceCalls(@TempDir Path tempDir) throws IOException {
|
||||
String taskSrc = """
|
||||
package com.example;
|
||||
@FunctionalInterface
|
||||
public interface MyTask {
|
||||
void run();
|
||||
}
|
||||
""";
|
||||
String spuriousSrc = """
|
||||
package com.example;
|
||||
public class SpuriousTask implements MyTask {
|
||||
private UnrelatedService service;
|
||||
public void run() {
|
||||
service.doSomething();
|
||||
}
|
||||
}
|
||||
""";
|
||||
String unrelatedSrc = """
|
||||
package com.example;
|
||||
public class UnrelatedService {
|
||||
public void doSomething() {}
|
||||
}
|
||||
""";
|
||||
void shouldNotPolymorphicallyExpandExternalInterfacesWithManyImpls(@TempDir Path tempDir) throws IOException {
|
||||
String impl1 = "package com.example; public class R1 implements java.lang.Runnable { public void run() {} }";
|
||||
String impl2 = "package com.example; public class R2 implements java.lang.Runnable { public void run() {} }";
|
||||
String impl3 = "package com.example; public class R3 implements java.lang.Runnable { public void run() {} }";
|
||||
String impl4 = "package com.example; public class R4 implements java.lang.Runnable { public void run() {} }";
|
||||
String executorSrc = """
|
||||
package com.example;
|
||||
public class ExecutorService {
|
||||
public void execute(MyTask task) {
|
||||
public void execute(java.lang.Runnable task) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
""";
|
||||
String mainSrc = """
|
||||
package com.example;
|
||||
public class MainService {
|
||||
private ExecutorService executor;
|
||||
public void runJob() {
|
||||
executor.execute(() -> {});
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
Files.writeString(tempDir.resolve("MyTask.java"), taskSrc);
|
||||
Files.writeString(tempDir.resolve("SpuriousTask.java"), spuriousSrc);
|
||||
Files.writeString(tempDir.resolve("UnrelatedService.java"), unrelatedSrc);
|
||||
Files.writeString(tempDir.resolve("R1.java"), impl1);
|
||||
Files.writeString(tempDir.resolve("R2.java"), impl2);
|
||||
Files.writeString(tempDir.resolve("R3.java"), impl3);
|
||||
Files.writeString(tempDir.resolve("R4.java"), impl4);
|
||||
Files.writeString(tempDir.resolve("ExecutorService.java"), executorSrc);
|
||||
Files.writeString(tempDir.resolve("MainService.java"), mainSrc);
|
||||
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
@@ -268,13 +247,14 @@ class EnterpriseBugsTest {
|
||||
HeuristicCallGraphEngine engine = new HeuristicCallGraphEngine(context);
|
||||
var graph = engine.buildCallGraph();
|
||||
|
||||
// The execute method calls task.run(). Since MyTask is a functional interface,
|
||||
// it should NOT resolve task.run() to SpuriousTask.run()
|
||||
// The execute method calls task.run(). Since java.lang.Runnable is external (td == null) and has > 3 impls,
|
||||
// it should NOT resolve task.run() to R1.run(), R2.run(), etc.
|
||||
var edges = graph.get("com.example.ExecutorService.execute");
|
||||
if (edges != null) {
|
||||
for (var edge : edges) {
|
||||
assertThat(edge.getTargetMethod()).isNotEqualTo("com.example.SpuriousTask.run");
|
||||
assertThat(edge.getTargetMethod()).isNotEqualTo("com.example.R1.run");
|
||||
}
|
||||
assertThat(edges).extracting("targetMethod").containsExactly("java.lang.Runnable.run");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +270,6 @@ class EnterpriseBugsTest {
|
||||
.event("OrderEvents.valueOf(someVar)")
|
||||
.build();
|
||||
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isFalse();
|
||||
assertThat(engine.matches(smEvent, triggerPoint)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user