@@ -89,11 +89,61 @@ public void testModifiedViewDepth() {
8989 }
9090 }
9191
92- private void addView (String name , String query ) throws Exception {
92+ public void testViewCountExceeded () throws Exception {
93+ for (int i = 0 ; i < ViewService .ViewServiceConfig .DEFAULT .maxViews (); i ++) {
94+ addView ("view" + i , "from emp" );
95+ }
96+
97+ // FROM view11 should fail
98+ Exception e = expectThrows (IllegalArgumentException .class , () -> addView ("viewX" , "from emp" ));
99+ assertThat (e .getMessage (), startsWith ("cannot add view, the maximum number of views is reached: 100" ));
100+ }
101+
102+ public void testModifiedViewCount () {
103+ var config = new ViewService .ViewServiceConfig (1 , 10_000 , 10 );
104+ InMemoryViewService customViewService = new InMemoryViewService (functionRegistry , config );
105+ try {
106+ addView ("view1" , "from emp" , customViewService );
107+
108+ // View2 should fail
109+ Exception e = expectThrows (IllegalArgumentException .class , () -> addView ("view2" , "from emp" , customViewService ));
110+ assertThat (e .getMessage (), startsWith ("cannot add view, the maximum number of views is reached: 1" ));
111+ } catch (Exception e ) {
112+ throw new AssertionError ("unexpected exception" , e );
113+ }
114+ }
115+
116+ public void testViewLengthExceeded () throws Exception {
117+ addView ("view1" , "from short" );
118+
119+ // Long view definition should fail
120+ StringBuilder longView = new StringBuilder ("from " );
121+ for (int i = 0 ; i < ViewService .ViewServiceConfig .DEFAULT .maxViewSize (); i ++) {
122+ longView .append ("a" );
123+ }
124+ Exception e = expectThrows (IllegalArgumentException .class , () -> addView ("viewX" , longView .toString ()));
125+ assertThat (e .getMessage (), startsWith ("view query is too large: 10005 characters, the maximum allowed is 10000" ));
126+ }
127+
128+ public void testModifiedViewLength () {
129+ var config = new ViewService .ViewServiceConfig (100 , 6 , 10 );
130+ InMemoryViewService customViewService = new InMemoryViewService (functionRegistry , config );
131+ try {
132+ addView ("view1" , "from a" , customViewService );
133+
134+ // Just one character longer should fail
135+ Exception e = expectThrows (IllegalArgumentException .class , () -> addView ("view2" , "from aa" , customViewService ));
136+ assertThat (e .getMessage (), startsWith ("view query is too large: 7 characters, the maximum allowed is 6" ));
137+ } catch (Exception e ) {
138+ throw new AssertionError ("unexpected exception" , e );
139+ }
140+ }
141+
142+ private void addView (String name , String query ) {
93143 addView (name , query , viewService );
94144 }
95145
96- private void addView (String name , String query , ViewService viewService ) throws Exception {
146+ private void addView (String name , String query , ViewService viewService ) {
97147 viewService .put (name , new View (query ), ActionListener .noop (), EsqlTestUtils .TEST_CFG );
98148 }
99149
0 commit comments