|
@@ -295,15 +295,10 @@ public class HeapAttackIT extends ESRestTestCase {
|
|
|
* Returns many moderately long strings.
|
|
|
*/
|
|
|
public void testManyConcat() throws IOException {
|
|
|
+ int strings = 300;
|
|
|
initManyLongs();
|
|
|
- Response resp = manyConcat(300);
|
|
|
- Map<?, ?> map = responseAsMap(resp);
|
|
|
- ListMatcher columns = matchesList();
|
|
|
- for (int s = 0; s < 300; s++) {
|
|
|
- columns = columns.item(matchesMap().entry("name", "str" + s).entry("type", "keyword"));
|
|
|
- }
|
|
|
- MapMatcher mapMatcher = matchesMap();
|
|
|
- assertMap(map, mapMatcher.entry("columns", columns).entry("values", any(List.class)).entry("took", greaterThanOrEqualTo(0)));
|
|
|
+ Response resp = manyConcat("FROM manylongs", strings);
|
|
|
+ assertManyStrings(resp, strings);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -311,15 +306,24 @@ public class HeapAttackIT extends ESRestTestCase {
|
|
|
*/
|
|
|
public void testHugeManyConcat() throws IOException {
|
|
|
initManyLongs();
|
|
|
- assertCircuitBreaks(() -> manyConcat(2000));
|
|
|
+ assertCircuitBreaks(() -> manyConcat("FROM manylongs", 2000));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns many moderately long strings.
|
|
|
+ */
|
|
|
+ public void testManyConcatFromRow() throws IOException {
|
|
|
+ int strings = 2000;
|
|
|
+ Response resp = manyConcat("ROW a=9999, b=9999, c=9999, d=9999, e=9999", strings);
|
|
|
+ assertManyStrings(resp, strings);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Tests that generate many moderately long strings.
|
|
|
*/
|
|
|
- private Response manyConcat(int strings) throws IOException {
|
|
|
+ private Response manyConcat(String init, int strings) throws IOException {
|
|
|
StringBuilder query = startQuery();
|
|
|
- query.append("FROM manylongs | EVAL str = CONCAT(");
|
|
|
+ query.append(init).append(" | EVAL str = CONCAT(");
|
|
|
query.append(
|
|
|
Arrays.stream(new String[] { "a", "b", "c", "d", "e" })
|
|
|
.map(f -> "TO_STRING(" + f + ")")
|
|
@@ -344,7 +348,64 @@ public class HeapAttackIT extends ESRestTestCase {
|
|
|
query.append("str").append(s);
|
|
|
}
|
|
|
query.append("\"}");
|
|
|
- return query(query.toString(), null);
|
|
|
+ return query(query.toString(), "columns");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns many moderately long strings.
|
|
|
+ */
|
|
|
+ public void testManyRepeat() throws IOException {
|
|
|
+ int strings = 30;
|
|
|
+ initManyLongs();
|
|
|
+ Response resp = manyRepeat("FROM manylongs", strings);
|
|
|
+ assertManyStrings(resp, 30);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Hits a circuit breaker by building many moderately long strings.
|
|
|
+ */
|
|
|
+ public void testHugeManyRepeat() throws IOException {
|
|
|
+ initManyLongs();
|
|
|
+ assertCircuitBreaks(() -> manyRepeat("FROM manylongs", 75));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns many moderately long strings.
|
|
|
+ */
|
|
|
+ public void testManyRepeatFromRow() throws IOException {
|
|
|
+ int strings = 10000;
|
|
|
+ Response resp = manyRepeat("ROW a = 99", strings);
|
|
|
+ assertManyStrings(resp, strings);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests that generate many moderately long strings.
|
|
|
+ */
|
|
|
+ private Response manyRepeat(String init, int strings) throws IOException {
|
|
|
+ StringBuilder query = startQuery();
|
|
|
+ query.append(init).append(" | EVAL str = TO_STRING(a)");
|
|
|
+ for (int s = 0; s < strings; s++) {
|
|
|
+ query.append(",\nstr").append(s).append("=REPEAT(str, 10000)");
|
|
|
+ }
|
|
|
+ query.append("\n|KEEP ");
|
|
|
+ for (int s = 0; s < strings; s++) {
|
|
|
+ if (s != 0) {
|
|
|
+ query.append(", ");
|
|
|
+ }
|
|
|
+ query.append("str").append(s);
|
|
|
+ }
|
|
|
+ query.append("\"}");
|
|
|
+ return query(query.toString(), "columns");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void assertManyStrings(Response resp, int strings) throws IOException {
|
|
|
+ Map<?, ?> map = responseAsMap(resp);
|
|
|
+ ListMatcher columns = matchesList();
|
|
|
+ for (int s = 0; s < strings; s++) {
|
|
|
+ columns = columns.item(matchesMap().entry("name", "str" + s).entry("type", "keyword"));
|
|
|
+ }
|
|
|
+ MapMatcher mapMatcher = matchesMap();
|
|
|
+ assertMap(map, mapMatcher.entry("columns", columns));
|
|
|
}
|
|
|
|
|
|
public void testManyEval() throws IOException {
|