EQL: Polish testing infra (#64205)

Add tie-breaker inside request creation
Add configurable timeout

(cherry picked from commit ff281d7b6fd7b4cd2f08bac49aa0b354b6812940)
(cherry picked from commit 34bd76fc2987b1ad0b6275ac4358e362a0ba7fb0)
This commit is contained in:
Costin Leau 2020-10-27 16:15:30 +02:00 committed by Costin Leau
parent ce4ec307a2
commit 2363c4be4b
3 changed files with 32 additions and 5 deletions

View File

@ -6,10 +6,13 @@
package org.elasticsearch.test.eql;
import org.apache.http.HttpHost;
import org.elasticsearch.client.EqlClient;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.eql.EqlSearchRequest;
import org.elasticsearch.client.eql.EqlSearchResponse;
@ -18,6 +21,8 @@ import org.elasticsearch.client.eql.EqlSearchResponse.Hits;
import org.elasticsearch.client.eql.EqlSearchResponse.Sequence;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.AfterClass;
import org.junit.Before;
@ -106,7 +111,10 @@ public abstract class BaseEqlSpecTestCase extends ESRestTestCase {
protected EqlSearchResponse runQuery(String index, String query) throws Exception {
EqlSearchRequest request = new EqlSearchRequest(index, query);
request.tiebreakerField("event.sequence");
String tiebreaker = tiebreaker();
if (tiebreaker != null) {
request.tiebreakerField(tiebreaker());
}
// some queries return more than 10 results
request.size(50);
request.fetchSize(randomIntBetween(2, 50));
@ -136,7 +144,7 @@ public abstract class BaseEqlSpecTestCase extends ESRestTestCase {
final int len = events.size();
final long[] ids = new long[len];
for (int i = 0; i < len; i++) {
Object field = events.get(i).sourceAsMap().get(sequenceField());
Object field = events.get(i).sourceAsMap().get(tiebreaker());
ids[i] = ((Number) field).longValue();
}
return ids;
@ -167,5 +175,24 @@ public abstract class BaseEqlSpecTestCase extends ESRestTestCase {
return true;
}
protected abstract String sequenceField();
@Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureClient(builder, settings);
int timeout = Math.toIntExact(timeout().millis());
builder.setRequestConfigCallback(
requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout)
.setSocketTimeout(timeout)
);
builder.setStrictDeprecationMode(true);
return builder.build();
}
protected TimeValue timeout() {
return TimeValue.timeValueSeconds(10);
}
protected abstract String tiebreaker();
}

View File

@ -25,7 +25,7 @@ public abstract class EqlExtraSpecTestCase extends BaseEqlSpecTestCase {
}
@Override
protected String sequenceField() {
protected String tiebreaker() {
return "sequence";
}
}

View File

@ -47,7 +47,7 @@ public abstract class EqlSpecTestCase extends BaseEqlSpecTestCase {
}
@Override
protected String sequenceField() {
protected String tiebreaker() {
return "serial_event_id";
}