EQL: small improvements to the testing base class

Extract request settings into dedicated methods for easier adjustments

(cherry picked from commit 4f93591cc561c7f8ff7c2f070dd1180f209810b7)
(cherry picked from commit ff7e8427345c304f5a37612c870b48555484b692)
This commit is contained in:
Costin Leau 2020-11-14 16:37:46 +02:00
parent f7cc570c4f
commit 9551cb3420
1 changed files with 29 additions and 6 deletions

View File

@ -112,14 +112,16 @@ public abstract class BaseEqlSpecTestCase extends ESRestTestCase {
protected EqlSearchResponse runQuery(String index, String query) throws Exception { protected EqlSearchResponse runQuery(String index, String query) throws Exception {
EqlSearchRequest request = new EqlSearchRequest(index, query); EqlSearchRequest request = new EqlSearchRequest(index, query);
request.eventCategoryField(eventCategory());
request.timestampField(timestamp());
String tiebreaker = tiebreaker(); String tiebreaker = tiebreaker();
if (tiebreaker != null) { if (tiebreaker != null) {
request.tiebreakerField(tiebreaker()); request.tiebreakerField(tiebreaker());
} }
// some queries return more than 10 results request.size(requestSize());
request.size(50); request.fetchSize(requestFetchSize());
request.fetchSize(randomIntBetween(2, 50)); request.resultPosition(requestResultPosition());
request.resultPosition(randomBoolean() ? "head" : "tail");
return runRequest(eqlClient(), request); return runRequest(eqlClient(), request);
} }
@ -199,9 +201,30 @@ public abstract class BaseEqlSpecTestCase extends ESRestTestCase {
return builder.build(); return builder.build();
} }
protected TimeValue timeout() { protected String timestamp() {
return TimeValue.timeValueSeconds(10); return "@timestamp";
};
private String eventCategory() {
return "event.category";
} }
protected abstract String tiebreaker(); protected abstract String tiebreaker();
protected int requestSize() {
// some queries return more than 10 results
return 50;
}
protected int requestFetchSize() {
return randomIntBetween(2, requestSize());
}
protected String requestResultPosition() {
return randomBoolean() ? "head" : "tail";
}
protected TimeValue timeout() {
return TimeValue.timeValueSeconds(10);
}
} }