2626 * End-to-end IT for {@code plugins.ppl.async.max_retained_results}, the limit on asynchronous PPL
2727 * results a node retains for polling.
2828 *
29- * <p>Results left by earlier test classes may still be retained on the node, so the test first
30- * finds the smallest limit at which the node admits a submit, which is one more than the number of
31- * results the node retains .
29+ * <p>Results left by earlier test classes may still be retained on the node. With a limit of one, a
30+ * submit is refused either at once, because such a result fills the limit, or after one result of
31+ * this test fills it .
3232 */
3333public class AsyncPPLRetainedResultLimitIT extends PPLIntegTestCase {
3434
3535 private static final String MAX_RESULTS = Key .PPL_ASYNC_MAX_RETAINED_RESULTS .getKeyValue ();
3636 private static final String QUERY = "source=" + TEST_INDEX_ACCOUNT + " | stats count() as c" ;
37-
3837 private static final long POLL_TIMEOUT_MILLIS = 30_000 ;
3938
4039 private final List <String > jobIds = new ArrayList <>();
@@ -48,7 +47,7 @@ protected void init() throws Exception {
4847
4948 @ After
5049 public void cleanUp () throws IOException {
51- setLimit (MAX_RESULTS , null );
50+ setLimit (null );
5251 for (String id : jobIds ) {
5352 try {
5453 deleteAsyncQuery (client (), id );
@@ -60,53 +59,21 @@ public void cleanUp() throws IOException {
6059 }
6160
6261 @ Test
63- public void retainedResultLimitRejectsSubmitWith429UntilAJobIsDeleted () throws Exception {
64- // The node retains one result less than this limit, so one more result fills it.
65- setLimit (MAX_RESULTS , smallestAdmittingLimit ());
66- String id = submitRetained ();
67- // Fetching the finished result with GET does not release it.
68- pollUntilTerminal (client (), id , POLL_TIMEOUT_MILLIS );
69-
70- ResponseException rejected =
71- Assert .assertThrows (ResponseException .class , () -> submitRetained ());
72- assertRejectedWith429 (rejected , MAX_RESULTS );
73-
74- deleteAsyncQuery (client (), id );
75- submitRetained ();
76- }
77-
78- /**
79- * Finds the smallest limit at which the node admits a submit, by binary search with submits that
80- * wait long enough to return their result inline, so they retain nothing.
81- */
82- private long smallestAdmittingLimit () throws IOException {
83- long admitting = 1 ;
84- while (!admits (admitting )) {
85- admitting *= 2 ;
86- }
87- long refusing = admitting / 2 ;
88- while (admitting - refusing > 1 ) {
89- long middle = refusing + (admitting - refusing ) / 2 ;
90- if (admits (middle )) {
91- admitting = middle ;
92- } else {
93- refusing = middle ;
94- }
95- }
96- return admitting ;
97- }
98-
99- private boolean admits (long limit ) throws IOException {
100- setLimit (MAX_RESULTS , limit );
101- JSONObject body =
102- new JSONObject ().put ("query" , QUERY ).put ("wait_for_completion_timeout" , "30s" );
62+ public void submitIsRejectedWith429WhileRetainedResultsReachTheLimit () throws Exception {
63+ setLimit (1 );
64+ ResponseException rejected ;
10365 try {
104- postPpl (client (), body );
105- return true ;
66+ String id = submitRetained ();
67+ // The retained result fills the limit once the query finishes, even after GET fetches it.
68+ pollUntilTerminal (client (), id , POLL_TIMEOUT_MILLIS );
69+ rejected = Assert .assertThrows (ResponseException .class , this ::submitRetained );
10670 } catch (ResponseException e ) {
107- assertRejectedWith429 (e , MAX_RESULTS );
108- return false ;
71+ rejected = e ;
10972 }
73+
74+ Assert .assertEquals (429 , rejected .getResponse ().getStatusLine ().getStatusCode ());
75+ String body = getResponseBody (rejected .getResponse (), true );
76+ Assert .assertTrue (body , body .contains (MAX_RESULTS ));
11077 }
11178
11279 /** Submits {@link #QUERY} with a zero wait and returns the id of the retained job. */
@@ -118,18 +85,13 @@ private String submitRetained() throws IOException {
11885 return id ;
11986 }
12087
121- private static void assertRejectedWith429 (ResponseException rejected , String setting )
122- throws IOException {
123- Assert .assertEquals (429 , rejected .getResponse ().getStatusLine ().getStatusCode ());
124- String body = getResponseBody (rejected .getResponse (), true );
125- Assert .assertTrue (body , body .contains (setting ));
126- }
127-
128- private void setLimit (String key , Object value ) throws IOException {
88+ private void setLimit (Integer limit ) throws IOException {
12989 Request request = new Request ("PUT" , "/_cluster/settings" );
13090 request .setJsonEntity (
13191 new JSONObject ()
132- .put ("transient" , new JSONObject ().put (key , value == null ? JSONObject .NULL : value ))
92+ .put (
93+ "transient" ,
94+ new JSONObject ().put (MAX_RESULTS , limit == null ? JSONObject .NULL : limit ))
13395 .toString ());
13496 client ().performRequest (request );
13597 }
0 commit comments