Skip to content

Commit 1a2504f

Browse files
committed
Added more config tests
1 parent 01c0d41 commit 1a2504f

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/view/InMemoryViewService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public class InMemoryViewService extends ViewService {
2222
private ViewMetadata metadata;
2323

2424
public InMemoryViewService(EsqlFunctionRegistry functionRegistry) {
25-
super(functionRegistry, ViewServiceConfig.DEFAULT);
25+
this(functionRegistry, ViewServiceConfig.DEFAULT);
26+
}
27+
28+
public InMemoryViewService(EsqlFunctionRegistry functionRegistry, ViewServiceConfig config) {
29+
super(functionRegistry, config);
2630
this.metadata = ViewMetadata.EMPTY;
2731
}
2832

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/view/InMemoryViewServiceTests.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,47 @@ public void testViewDepthExceeded() throws Exception {
5353
addView("view9", "from view8");
5454
addView("view10", "from view9");
5555
addView("view11", "from view10");
56-
LogicalPlan plan = statement("from view11");
57-
Exception e = expectThrows(VerificationException.class, () -> viewService.replaceViews(plan, telemetry, EsqlTestUtils.TEST_CFG));
56+
57+
// FROM view11 should fail
58+
Exception e = expectThrows(
59+
VerificationException.class,
60+
() -> viewService.replaceViews(statement("from view11"), telemetry, EsqlTestUtils.TEST_CFG)
61+
);
5862
assertThat(e.getMessage(), startsWith("The maximum allowed view depth of 10 has been exceeded"));
63+
64+
// But FROM view10 should work
65+
LogicalPlan rewritten = viewService.replaceViews(statement("from view10"), telemetry, EsqlTestUtils.TEST_CFG);
66+
assertThat(rewritten, equalTo(statement("from emp")));
67+
}
68+
69+
public void testModifiedViewDepth() {
70+
var config = new ViewService.ViewServiceConfig(100, 10_000, 1);
71+
InMemoryViewService customViewService = new InMemoryViewService(functionRegistry, config);
72+
try {
73+
addView("view1", "from emp", customViewService);
74+
addView("view2", "from view1", customViewService);
75+
addView("view3", "from view2", customViewService);
76+
77+
// FROM view2 should fail
78+
Exception e = expectThrows(
79+
VerificationException.class,
80+
() -> customViewService.replaceViews(statement("from view2"), telemetry, EsqlTestUtils.TEST_CFG)
81+
);
82+
assertThat(e.getMessage(), startsWith("The maximum allowed view depth of 1 has been exceeded"));
83+
84+
// But FROM view1 should work
85+
LogicalPlan rewritten = customViewService.replaceViews(statement("from view1"), telemetry, EsqlTestUtils.TEST_CFG);
86+
assertThat(rewritten, equalTo(statement("from emp")));
87+
} catch (Exception e) {
88+
throw new AssertionError("unexpected exception", e);
89+
}
5990
}
6091

6192
private void addView(String name, String query) throws Exception {
93+
addView(name, query, viewService);
94+
}
95+
96+
private void addView(String name, String query, ViewService viewService) throws Exception {
6297
viewService.put(name, new View(query), ActionListener.noop(), EsqlTestUtils.TEST_CFG);
6398
}
6499

0 commit comments

Comments
 (0)