Skip to content

Commit 2e2980b

Browse files
authored
[TRANSFORM] Remove HLRC from continuous tests (#84430)
1 parent 713958f commit 2e2980b

13 files changed

+607
-532
lines changed

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/LatestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import static org.hamcrest.Matchers.hasSize;
3333
import static org.hamcrest.Matchers.is;
3434

35-
public class LatestIT extends TransformIntegTestCase {
35+
public class LatestIT extends TransformRestTestCase {
3636

3737
private static final String SOURCE_INDEX_NAME = "basic-crud-latest-reviews";
3838
private static final int NUM_USERS = 28;

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TestFeatureResetIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import static org.hamcrest.Matchers.not;
3535
import static org.hamcrest.Matchers.nullValue;
3636

37-
public class TestFeatureResetIT extends TransformIntegTestCase {
37+
public class TestFeatureResetIT extends TransformRestTestCase {
3838

3939
@Before
4040
public void setLogging() throws IOException {

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import static org.hamcrest.Matchers.oneOf;
4343

4444
@SuppressWarnings("removal")
45-
public class TransformIT extends TransformIntegTestCase {
45+
public class TransformIT extends TransformRestTestCase {
4646

4747
private static final int NUM_USERS = 28;
4848

@@ -425,6 +425,7 @@ private void indexMoreDocs(long timestamp, long userId, String index) throws Exc
425425
""".formatted(userId, i, business, stars, timestamp);
426426
bulkBuilder.append(source);
427427
}
428+
bulkBuilder.append("\r\n");
428429
doBulk(bulkBuilder.toString(), true);
429430
}
430431
}
Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.xcontent.XContentBuilder;
3535
import org.elasticsearch.xcontent.XContentFactory;
3636
import org.elasticsearch.xcontent.XContentParser;
37+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3738
import org.elasticsearch.xcontent.XContentType;
3839
import org.elasticsearch.xpack.core.transform.TransformField;
3940
import org.elasticsearch.xpack.core.transform.transforms.DestConfig;
@@ -66,7 +67,7 @@
6667
import static org.hamcrest.Matchers.hasSize;
6768
import static org.hamcrest.core.Is.is;
6869

69-
public abstract class TransformIntegTestCase extends ESRestTestCase {
70+
public abstract class TransformRestTestCase extends ESRestTestCase {
7071

7172
protected static String TRANSFORM_ENDPOINT = "/_transform/";
7273

@@ -212,6 +213,14 @@ protected void deleteTransform(String id) throws IOException {
212213
assertOK(adminClient().performRequest(request));
213214
}
214215

216+
protected void deleteTransform(String id, boolean force) throws IOException {
217+
Request request = new Request("DELETE", TRANSFORM_ENDPOINT + id);
218+
if (force) {
219+
request.addParameter("force", "true");
220+
}
221+
assertOK(adminClient().performRequest(request));
222+
}
223+
215224
protected void putTransform(String id, String config, RequestOptions options) throws IOException {
216225
if (createdTransformIds.contains(id)) {
217226
throw new IllegalArgumentException("transform [" + id + "] is already registered");
@@ -292,7 +301,20 @@ protected DateHistogramGroupSource createDateHistogramGroupSourceWithCalendarInt
292301
return new DateHistogramGroupSource(field, null, false, new DateHistogramGroupSource.CalendarInterval(interval), zone);
293302
}
294303

295-
protected GroupConfig createGroupConfig(Map<String, SingleGroupSource> groups) throws IOException {
304+
/**
305+
* GroupConfig has 2 internal representations - source and a map
306+
* of SingleGroupSource, both need to be present.
307+
* The fromXContent parser populates both so the trick here is
308+
* to JSON serialise {@code groups} and build the
309+
* GroupConfig from JSON.
310+
*
311+
* @param groups Agg factory
312+
* @param xContentRegistry registry
313+
* @return GroupConfig
314+
* @throws IOException on parsing
315+
*/
316+
public static GroupConfig createGroupConfig(Map<String, SingleGroupSource> groups, NamedXContentRegistry xContentRegistry)
317+
throws IOException {
296318
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
297319
builder.startObject();
298320
for (Map.Entry<String, SingleGroupSource> entry : groups.entrySet()) {
@@ -304,22 +326,43 @@ protected GroupConfig createGroupConfig(Map<String, SingleGroupSource> groups) t
304326

305327
try (
306328
XContentParser sourceParser = XContentType.JSON.xContent()
307-
.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, BytesReference.bytes(builder).streamInput())
329+
.createParser(
330+
XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
331+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
332+
BytesReference.bytes(builder).streamInput()
333+
)
308334
) {
309335
return GroupConfig.fromXContent(sourceParser, false);
310336
}
311337
}
312338
}
313339

314-
protected AggregationConfig createAggConfig(AggregatorFactories.Builder aggregations) throws IOException {
340+
protected GroupConfig createGroupConfig(Map<String, SingleGroupSource> groups) throws IOException {
341+
return createGroupConfig(groups, xContentRegistry());
342+
}
343+
344+
/**
345+
* AggregationConfig has 2 internal representations - source and an
346+
* Aggregation Factory, both need to be present.
347+
* The fromXContent parser populates both so the trick here is
348+
* to JSON serialise {@code aggregations} and build the
349+
* AggregationConfig from JSON.
350+
*
351+
* @param aggregations Agg factory
352+
* @param xContentRegistry registry
353+
* @return AggregationConfig
354+
* @throws IOException on parsing
355+
*/
356+
public static AggregationConfig createAggConfig(AggregatorFactories.Builder aggregations, NamedXContentRegistry xContentRegistry)
357+
throws IOException {
315358

316359
try (XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
317360
aggregations.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
318361
try (
319362
XContentParser sourceParser = XContentType.JSON.xContent()
320363
.createParser(
321-
xContentRegistry(),
322-
LoggingDeprecationHandler.INSTANCE,
364+
XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
365+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
323366
BytesReference.bytes(xContentBuilder).streamInput()
324367
)
325368
) {
@@ -328,6 +371,10 @@ protected AggregationConfig createAggConfig(AggregatorFactories.Builder aggregat
328371
}
329372
}
330373

374+
protected AggregationConfig createAggConfig(AggregatorFactories.Builder aggregations) throws IOException {
375+
return createAggConfig(aggregations, xContentRegistry());
376+
}
377+
331378
protected PivotConfig createPivotConfig(Map<String, SingleGroupSource> groups, AggregatorFactories.Builder aggregations)
332379
throws Exception {
333380
return new PivotConfig(createGroupConfig(groups), createAggConfig(aggregations), null);

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformUsingSearchRuntimeFieldsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static org.hamcrest.Matchers.not;
4545

4646
@SuppressWarnings("removal")
47-
public class TransformUsingSearchRuntimeFieldsIT extends TransformIntegTestCase {
47+
public class TransformUsingSearchRuntimeFieldsIT extends TransformRestTestCase {
4848

4949
private static final String REVIEWS_INDEX_NAME = "basic-crud-reviews";
5050
private static final int NUM_USERS = 28;

x-pack/plugin/transform/qa/multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/continuous/ContinuousTestCase.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77

88
package org.elasticsearch.xpack.transform.integration.continuous;
99

10-
import org.elasticsearch.action.search.SearchRequest;
11-
import org.elasticsearch.action.search.SearchResponse;
12-
import org.elasticsearch.client.RequestOptions;
13-
import org.elasticsearch.client.RestHighLevelClient;
14-
import org.elasticsearch.client.transform.transforms.SettingsConfig;
15-
import org.elasticsearch.client.transform.transforms.SyncConfig;
16-
import org.elasticsearch.client.transform.transforms.TimeSyncConfig;
17-
import org.elasticsearch.client.transform.transforms.TransformConfig;
10+
import org.elasticsearch.client.Request;
11+
import org.elasticsearch.client.Response;
1812
import org.elasticsearch.common.settings.Settings;
1913
import org.elasticsearch.common.util.concurrent.ThreadContext;
2014
import org.elasticsearch.core.TimeValue;
@@ -23,15 +17,19 @@
2317
import org.elasticsearch.search.aggregations.AggregatorFactories;
2418
import org.elasticsearch.test.rest.ESRestTestCase;
2519
import org.elasticsearch.xcontent.NamedXContentRegistry;
20+
import org.elasticsearch.xpack.core.transform.transforms.SettingsConfig;
21+
import org.elasticsearch.xpack.core.transform.transforms.SyncConfig;
22+
import org.elasticsearch.xpack.core.transform.transforms.TimeSyncConfig;
23+
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
2624

2725
import java.io.IOException;
2826
import java.nio.charset.StandardCharsets;
2927
import java.time.format.DateTimeFormatter;
3028
import java.time.format.DateTimeFormatterBuilder;
3129
import java.util.Base64;
3230
import java.util.Collections;
33-
import java.util.List;
3431
import java.util.Locale;
32+
import java.util.Map;
3533
import java.util.Set;
3634
import java.util.concurrent.TimeUnit;
3735

@@ -80,7 +78,7 @@ public abstract class ContinuousTestCase extends ESRestTestCase {
8078
*
8179
* @return the transform configuration
8280
*/
83-
public abstract TransformConfig createConfig();
81+
public abstract TransformConfig createConfig() throws IOException;
8482

8583
/**
8684
* Test results after 1 iteration in the test runner.
@@ -92,7 +90,7 @@ public abstract class ContinuousTestCase extends ESRestTestCase {
9290

9391
protected TransformConfig.Builder addCommonBuilderParameters(TransformConfig.Builder builder) {
9492
return builder.setSyncConfig(getSyncConfig())
95-
.setSettings(addCommonSetings(new SettingsConfig.Builder()).build())
93+
.setSettings(addCommonSettings(new SettingsConfig.Builder()).build())
9694
.setFrequency(SYNC_DELAY);
9795
}
9896

@@ -103,38 +101,42 @@ protected AggregatorFactories.Builder addCommonAggregations(AggregatorFactories.
103101
return builder;
104102
}
105103

106-
protected SettingsConfig.Builder addCommonSetings(SettingsConfig.Builder builder) {
104+
protected SettingsConfig.Builder addCommonSettings(SettingsConfig.Builder builder) {
107105
// enforce paging, to see we run through all of the options
108106
builder.setMaxPageSearchSize(10);
109107
return builder;
110108
}
111109

112-
protected SearchResponse search(SearchRequest searchRequest) throws IOException {
113-
try (RestHighLevelClient restClient = new TestRestHighLevelClient()) {
114-
return restClient.search(searchRequest, RequestOptions.DEFAULT);
110+
protected Response search(String index, String query) throws IOException {
111+
return search(index, query, Collections.emptyMap());
112+
}
113+
114+
protected Response search(String index, String query, Map<String, String> queryParameters) throws IOException {
115+
try {
116+
Request searchRequest = new Request("GET", index + "/_search");
117+
searchRequest.setJsonEntity(query);
118+
searchRequest.addParameters(queryParameters);
119+
return client().performRequest(searchRequest);
115120
} catch (Exception e) {
116121
logger.error("Search failed with an exception.", e);
117122
throw e;
118123
}
119124
}
120125

126+
private SyncConfig getSyncConfig() {
127+
return new TimeSyncConfig("timestamp", SYNC_DELAY);
128+
}
129+
121130
@Override
122131
protected Settings restClientSettings() {
123132
final String token = "Basic "
124133
+ Base64.getEncoder().encodeToString(("x_pack_rest_user:x-pack-test-password").getBytes(StandardCharsets.UTF_8));
125134
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
126135
}
127136

128-
private static class TestRestHighLevelClient extends RestHighLevelClient {
129-
private static final List<NamedXContentRegistry.Entry> X_CONTENT_ENTRIES = new SearchModule(Settings.EMPTY, Collections.emptyList())
130-
.getNamedXContents();
131-
132-
TestRestHighLevelClient() {
133-
super(client(), restClient -> {}, X_CONTENT_ENTRIES);
134-
}
135-
}
136-
137-
private SyncConfig getSyncConfig() {
138-
return TimeSyncConfig.builder().setField("timestamp").setDelay(SYNC_DELAY).build();
137+
@Override
138+
protected NamedXContentRegistry xContentRegistry() {
139+
SearchModule searchModule = new SearchModule(Settings.EMPTY, Collections.emptyList());
140+
return new NamedXContentRegistry(searchModule.getNamedXContents());
139141
}
140142
}

0 commit comments

Comments
 (0)