Skip to content

Remove aggregation test testing the high level rest client #105294

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

Merged
merged 1 commit into from
Feb 12, 2024
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@
package org.elasticsearch.xpack.analytics.stringstats;

import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.BaseAggregationBuilder;
import org.elasticsearch.test.AbstractXContentSerializingTestCase;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Arrays;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;

public class StringStatsAggregationBuilderTests extends AbstractXContentSerializingTestCase<StringStatsAggregationBuilder> {
@Override
Expand Down Expand Up @@ -77,28 +71,4 @@ protected StringStatsAggregationBuilder mutateInstance(StringStatsAggregationBui
mutant.showDistribution(instance.showDistribution());
return mutant;
}

public void testClientBuilder() throws IOException {
AbstractXContentTestCase.xContentTester(this::createParser, this::createTestInstance, this::toXContentThroughClientBuilder, p -> {
p.nextToken();
AggregatorFactories.Builder b = AggregatorFactories.parseAggregators(p);
assertThat(b.getAggregatorFactories(), hasSize(1));
assertThat(b.getPipelineAggregatorFactories(), empty());
return (StringStatsAggregationBuilder) b.getAggregatorFactories().iterator().next();
}).test();
}

private void toXContentThroughClientBuilder(StringStatsAggregationBuilder serverBuilder, XContentBuilder builder) throws IOException {
builder.startObject();
createClientBuilder(serverBuilder).toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
}

private org.elasticsearch.client.analytics.StringStatsAggregationBuilder createClientBuilder(
StringStatsAggregationBuilder serverBuilder
) {
org.elasticsearch.client.analytics.StringStatsAggregationBuilder builder =
new org.elasticsearch.client.analytics.StringStatsAggregationBuilder(serverBuilder.getName());
return builder.showDistribution(serverBuilder.showDistribution()).field(serverBuilder.field());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.AbstractXContentSerializingTestCase;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
Expand All @@ -30,9 +27,7 @@

import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;

public class TopMetricsAggregationBuilderTests extends AbstractXContentSerializingTestCase<TopMetricsAggregationBuilder> {
@Override
Expand Down Expand Up @@ -92,16 +87,6 @@ protected TopMetricsAggregationBuilder mutateInstance(TopMetricsAggregationBuild
return null;// TODO implement https://github.com/elastic/elasticsearch/issues/25929
}

public void testClientBuilder() throws IOException {
AbstractXContentTestCase.xContentTester(this::createParser, this::createTestInstance, this::toXContentThroughClientBuilder, p -> {
p.nextToken();
AggregatorFactories.Builder b = AggregatorFactories.parseAggregators(p);
assertThat(b.getAggregatorFactories(), hasSize(1));
assertThat(b.getPipelineAggregatorFactories(), empty());
return (TopMetricsAggregationBuilder) b.getAggregatorFactories().iterator().next();
}).test();
}

public void testValidation() {
AggregationInitializationException e = expectThrows(AggregationInitializationException.class, () -> {
List<SortBuilder<?>> sortBuilders = singletonList(
Expand All @@ -121,22 +106,4 @@ public void testValidation() {
});
assertEquals("Aggregator [tm] of type [top_metrics] cannot accept sub-aggregations", e.getMessage());
}

private void toXContentThroughClientBuilder(TopMetricsAggregationBuilder serverBuilder, XContentBuilder builder) throws IOException {
builder.startObject();
createClientBuilder(serverBuilder).toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
}

private org.elasticsearch.client.analytics.TopMetricsAggregationBuilder createClientBuilder(
TopMetricsAggregationBuilder serverBuilder
) {
assertThat(serverBuilder.getSortBuilders(), hasSize(1));
return new org.elasticsearch.client.analytics.TopMetricsAggregationBuilder(
serverBuilder.getName(),
serverBuilder.getSortBuilders().get(0),
serverBuilder.getSize(),
serverBuilder.getMetricFields().stream().map(MultiValuesSourceFieldConfig::getFieldName).toArray(String[]::new)
);
}
}