Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept more ingest simulate params as ints or strings #66197

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
dataMap, Metadata.ROUTING.getFieldName());
Long version = null;
if (dataMap.containsKey(Metadata.VERSION.getFieldName())) {
version = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.VERSION.getFieldName());
String versionValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
dataMap, Metadata.VERSION.getFieldName());
if (versionValue != null) {
version = Long.valueOf(versionValue);
} else {
throw new IllegalArgumentException("[_version] cannot be null");
}
}
VersionType versionType = null;
if (dataMap.containsKey(Metadata.VERSION_TYPE.getFieldName())) {
Expand All @@ -196,12 +202,24 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
IngestDocument ingestDocument =
new IngestDocument(index, id, routing, version, versionType, document);
if (dataMap.containsKey(Metadata.IF_SEQ_NO.getFieldName())) {
Long ifSeqNo = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.IF_SEQ_NO.getFieldName());
ingestDocument.setFieldValue(Metadata.IF_SEQ_NO.getFieldName(), ifSeqNo);
String ifSeqNoValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
dataMap, Metadata.IF_SEQ_NO.getFieldName());
if (ifSeqNoValue != null) {
Long ifSeqNo = Long.valueOf(ifSeqNoValue);
ingestDocument.setFieldValue(Metadata.IF_SEQ_NO.getFieldName(), ifSeqNo);
} else {
throw new IllegalArgumentException("[_if_seq_no] cannot be null");
}
}
if (dataMap.containsKey(Metadata.IF_PRIMARY_TERM.getFieldName())) {
Long ifPrimaryTerm = (Long) ConfigurationUtils.readObject(null, null, dataMap, Metadata.IF_PRIMARY_TERM.getFieldName());
ingestDocument.setFieldValue(Metadata.IF_PRIMARY_TERM.getFieldName(), ifPrimaryTerm);
String ifPrimaryTermValue = ConfigurationUtils.readOptionalStringOrIntProperty(null, null,
dataMap, Metadata.IF_PRIMARY_TERM.getFieldName());
if (ifPrimaryTermValue != null) {
Long ifPrimaryTerm = Long.valueOf(ifPrimaryTermValue);
ingestDocument.setFieldValue(Metadata.IF_PRIMARY_TERM.getFieldName(), ifPrimaryTerm);
} else {
throw new IllegalArgumentException("[_if_primary_term] cannot be null");
}
}
ingestDocumentList.add(ingestDocument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,12 @@ public void innerTestParseWithProvidedPipeline() throws Exception {
Map<String, Object> expectedDoc = new HashMap<>();
List<IngestDocument.Metadata> fields = Arrays.asList(INDEX, ID, ROUTING, VERSION, VERSION_TYPE, IF_SEQ_NO, IF_PRIMARY_TERM);
for(IngestDocument.Metadata field : fields) {
if (field == VERSION) {
Long value = randomLong();
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == VERSION_TYPE) {
if (field == VERSION_TYPE) {
String value = VersionType.toString(
randomFrom(VersionType.INTERNAL, VersionType.EXTERNAL, VersionType.EXTERNAL_GTE)
);
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else if (field == IF_SEQ_NO || field == IF_PRIMARY_TERM) {
Long value = randomNonNegativeLong();
doc.put(field.getFieldName(), value);
expectedDoc.put(field.getFieldName(), value);
} else {
if (randomBoolean()) {
String value = randomAlphaOfLengthBetween(1, 10);
Expand Down