Skip to content
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 @@ -203,15 +203,7 @@ public final void testFromXContent() throws IOException {
assumeTrue("This test does not support the aggregation type yet",
getNamedXContents().stream().filter(entry -> entry.name.match(aggregation.getType())).count() > 0);

final ToXContent.Params params = new ToXContent.MapParams(singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
final boolean humanReadable = randomBoolean();
final XContentType xContentType = randomFrom(XContentType.values());
final BytesReference originalBytes = toShuffledXContent(aggregation, xContentType, params, humanReadable);

final Aggregation parsedAggregation = parse(aggregation, xContentType, humanReadable, randomBoolean());

final BytesReference parsedBytes = toXContent((ToXContent) parsedAggregation, xContentType, params, humanReadable);
assertToXContentEquivalent(originalBytes, parsedBytes, xContentType);
final Aggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean());
assertFromXContent(aggregation, (ParsedAggregation) parsedAggregation);
}

Expand All @@ -220,12 +212,13 @@ protected void assertFromXContent(T aggregation, ParsedAggregation parsedAggrega
}

@SuppressWarnings("unchecked")
protected <P extends ParsedAggregation> P parse(final InternalAggregation aggregation,
final XContentType xContentType,
final boolean humanReadable,
final boolean shuffled) throws IOException {
protected <P extends ParsedAggregation> P parseAndAssert(final InternalAggregation aggregation,
final boolean shuffled) throws IOException {

final ToXContent.Params params = new ToXContent.MapParams(singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
final XContentType xContentType = randomFrom(XContentType.values());
final boolean humanReadable = randomBoolean();

final BytesReference originalBytes;
if (shuffled) {
originalBytes = toShuffledXContent(aggregation, xContentType, params, humanReadable);
Expand Down Expand Up @@ -255,6 +248,10 @@ protected <P extends ParsedAggregation> P parse(final InternalAggregation aggreg
assertTrue(parsedAggregation instanceof ParsedAggregation);
assertEquals(aggregation.getType(), ((ParsedAggregation) parsedAggregation).getType());
}

BytesReference parsedBytes = toXContent((ToXContent) parsedAggregation, xContentType, params, humanReadable);
assertToXContentEquivalent(originalBytes, parsedBytes, xContentType);

return (P) parsedAggregation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected abstract T createTestInstance(String name, List<PipelineAggregator> pi

public void testPercentilesIterators() throws IOException {
final T aggregation = createTestInstance();
final Iterable<Percentile> parsedAggregation = parse(aggregation, randomFrom(XContentType.values()), randomBoolean(), false);
final Iterable<Percentile> parsedAggregation = parseAndAssert(aggregation, false);

Iterator<Percentile> it = aggregation.iterator();
Iterator<Percentile> parsedIt = parsedAggregation.iterator();
Expand Down