-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] Cover custom sorting and routing in randomized testing (#120584)
* Cover custom sorting and routing in randomized testing * [CI] Auto commit changes from spotless * fix reindex tests * fix reindex tests * refactor classes * comment * more refactoring * more refactoring * restore tests with static mappings * reduce diff * reduce diff * Restore single-element array removal in synthetic source * Revert "Restore single-element array removal in synthetic source" This reverts commit e8e99e1. * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
- Loading branch information
1 parent
2ca2bbf
commit 695bf75
Showing
8 changed files
with
279 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...n/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/qa/BulkChallengeRestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.logsdb.qa; | ||
|
||
import org.elasticsearch.common.CheckedSupplier; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Challenge test that uses bulk indexing for both baseline and contender sides. | ||
* We index same documents into an index with standard index mode and an index with logsdb index mode. | ||
* Then we verify that results of common operations are the same modulo knows differences like synthetic source | ||
* modifications. | ||
*/ | ||
public class BulkChallengeRestIT extends StandardVersusLogsIndexModeChallengeRestIT { | ||
|
||
public BulkChallengeRestIT() {} | ||
|
||
protected BulkChallengeRestIT(DataGenerationHelper dataGenerationHelper) { | ||
super(dataGenerationHelper); | ||
} | ||
|
||
@Override | ||
public void indexDocuments( | ||
final CheckedSupplier<List<XContentBuilder>, IOException> baselineSupplier, | ||
final CheckedSupplier<List<XContentBuilder>, IOException> contenderSupplier | ||
) throws IOException { | ||
var contenderResponseEntity = indexContenderDocuments(contenderSupplier); | ||
indexBaselineDocuments(baselineSupplier, contenderResponseEntity); | ||
} | ||
|
||
private Map<String, Object> indexContenderDocuments(final CheckedSupplier<List<XContentBuilder>, IOException> documentsSupplier) | ||
throws IOException { | ||
final StringBuilder sb = new StringBuilder(); | ||
int id = 0; | ||
for (var document : documentsSupplier.get()) { | ||
if (autoGenerateId()) { | ||
sb.append("{ \"create\": { } }\n"); | ||
} else { | ||
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id)); | ||
} | ||
sb.append(Strings.toString(document)).append("\n"); | ||
id++; | ||
} | ||
return performBulkRequest(sb.toString(), false); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void indexBaselineDocuments( | ||
final CheckedSupplier<List<XContentBuilder>, IOException> documentsSupplier, | ||
final Map<String, Object> contenderResponseEntity | ||
) throws IOException { | ||
final StringBuilder sb = new StringBuilder(); | ||
int id = 0; | ||
final List<Map<String, Object>> items = (List<Map<String, Object>>) contenderResponseEntity.get("items"); | ||
for (var document : documentsSupplier.get()) { | ||
if (autoGenerateId()) { | ||
var contenderId = ((Map<String, Object>) items.get(id).get("create")).get("_id"); | ||
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%s\" } }\n", contenderId)); | ||
} else { | ||
sb.append(Strings.format("{ \"create\": { \"_id\" : \"%d\" } }\n", id)); | ||
} | ||
sb.append(Strings.toString(document)).append("\n"); | ||
id++; | ||
} | ||
performBulkRequest(sb.toString(), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...javaRestTest/java/org/elasticsearch/xpack/logsdb/qa/BulkStaticMappingChallengeRestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.logsdb.qa; | ||
|
||
import org.elasticsearch.common.time.DateFormatter; | ||
import org.elasticsearch.common.time.FormatNames; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xcontent.XContentFactory; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
|
||
/** | ||
* This test uses simple mapping and document structure in order to allow easier debugging of the test itself. | ||
*/ | ||
public class BulkStaticMappingChallengeRestIT extends BulkChallengeRestIT { | ||
public BulkStaticMappingChallengeRestIT() {} | ||
|
||
@Override | ||
public void baselineMappings(XContentBuilder builder) throws IOException { | ||
if (fullyDynamicMapping == false) { | ||
builder.startObject() | ||
.startObject("properties") | ||
|
||
.startObject("@timestamp") | ||
.field("type", "date") | ||
.endObject() | ||
|
||
.startObject("host.name") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("message") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("method") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("memory_usage_bytes") | ||
.field("type", "long") | ||
.field("ignore_malformed", randomBoolean()) | ||
.endObject() | ||
|
||
.endObject() | ||
|
||
.endObject(); | ||
} else { | ||
// We want dynamic mapping, but we need host.name to be a keyword instead of text to support aggregations. | ||
builder.startObject() | ||
.startObject("properties") | ||
|
||
.startObject("host.name") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.endObject() | ||
.endObject(); | ||
} | ||
} | ||
|
||
@Override | ||
public void contenderMappings(XContentBuilder builder) throws IOException { | ||
builder.startObject(); | ||
builder.field("subobjects", false); | ||
|
||
if (fullyDynamicMapping == false) { | ||
builder.startObject("properties") | ||
|
||
.startObject("@timestamp") | ||
.field("type", "date") | ||
.endObject() | ||
|
||
.startObject("host.name") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("message") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("method") | ||
.field("type", "keyword") | ||
.field("ignore_above", randomIntBetween(1000, 1200)) | ||
.endObject() | ||
|
||
.startObject("memory_usage_bytes") | ||
.field("type", "long") | ||
.field("ignore_malformed", randomBoolean()) | ||
.endObject() | ||
|
||
.endObject(); | ||
} | ||
|
||
builder.endObject(); | ||
} | ||
|
||
@Override | ||
protected XContentBuilder generateDocument(final Instant timestamp) throws IOException { | ||
return XContentFactory.jsonBuilder() | ||
.startObject() | ||
.field("@timestamp", DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(timestamp)) | ||
.field("host.name", randomFrom("foo", "bar", "baz")) | ||
.field("message", randomFrom("a message", "another message", "still another message", "one more message")) | ||
.field("method", randomFrom("put", "post", "get")) | ||
.field("memory_usage_bytes", randomLongBetween(1000, 2000)) | ||
.endObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.