瀏覽代碼

Remove aggregation test testing the high level rest client (#105294)

Removing those test and the actual HLRC classes. TheHLRC is not a thing any longer.
Ignacio Vera 1 年之前
父節點
當前提交
a129da23f0

+ 0 - 124
client/rest-high-level/src/main/java/org/elasticsearch/client/analytics/StringStatsAggregationBuilder.java

@@ -1,124 +0,0 @@
-/*
- * 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 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
-
-package org.elasticsearch.client.analytics;
-
-import org.elasticsearch.TransportVersion;
-import org.elasticsearch.TransportVersions;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.io.stream.Writeable;
-import org.elasticsearch.index.query.QueryRewriteContext;
-import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
-import org.elasticsearch.search.aggregations.AggregationBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
-import org.elasticsearch.search.aggregations.support.AggregationContext;
-import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
-import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
-import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
-import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.xcontent.ParseField;
-import org.elasticsearch.xcontent.XContentBuilder;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Builds the {@code string_stats} aggregation request.
- * <p>
- * NOTE: This extends {@linkplain AbstractAggregationBuilder} for compatibility
- * with {@link SearchSourceBuilder#aggregation(AggregationBuilder)} but it
- * doesn't support any "server" side things like
- * {@linkplain Writeable#writeTo(StreamOutput)},
- * {@linkplain AggregationBuilder#rewrite(QueryRewriteContext)}, or
- * {@linkplain AbstractAggregationBuilder#build(AggregationContext, AggregatorFactory)}.
- */
-public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilder<StringStatsAggregationBuilder> {
-    public static final String NAME = "string_stats";
-    private static final ParseField SHOW_DISTRIBUTION_FIELD = new ParseField("show_distribution");
-
-    private boolean showDistribution = false;
-
-    public StringStatsAggregationBuilder(String name) {
-        super(name);
-    }
-
-    /**
-     * Compute the distribution of each character. Disabled by default.
-     * @return this for chaining
-     */
-    public StringStatsAggregationBuilder showDistribution(boolean showDistribution) {
-        this.showDistribution = showDistribution;
-        return this;
-    }
-
-    @Override
-    protected ValuesSourceType defaultValueSourceType() {
-        return CoreValuesSourceType.KEYWORD;
-    }
-
-    @Override
-    public String getType() {
-        return NAME;
-    }
-
-    @Override
-    public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
-        return builder.field(StringStatsAggregationBuilder.SHOW_DISTRIBUTION_FIELD.getPreferredName(), showDistribution);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public BucketCardinality bucketCardinality() {
-        return BucketCardinality.NONE;
-    }
-
-    @Override
-    protected ValuesSourceAggregatorFactory innerBuild(
-        AggregationContext context,
-        ValuesSourceConfig config,
-        AggregatorFactory parent,
-        Builder subFactoriesBuilder
-    ) throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, Object> metadata) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(super.hashCode(), showDistribution);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null || getClass() != obj.getClass()) {
-            return false;
-        }
-        if (false == super.equals(obj)) {
-            return false;
-        }
-        StringStatsAggregationBuilder other = (StringStatsAggregationBuilder) obj;
-        return showDistribution == other.showDistribution;
-    }
-
-    @Override
-    public TransportVersion getMinimalSupportedVersion() {
-        return TransportVersions.ZERO;
-    }
-}

+ 0 - 108
client/rest-high-level/src/main/java/org/elasticsearch/client/analytics/TopMetricsAggregationBuilder.java

@@ -1,108 +0,0 @@
-/*
- * 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 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
-
-package org.elasticsearch.client.analytics;
-
-import org.elasticsearch.TransportVersion;
-import org.elasticsearch.TransportVersions;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.io.stream.Writeable;
-import org.elasticsearch.index.query.QueryRewriteContext;
-import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
-import org.elasticsearch.search.aggregations.AggregationBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
-import org.elasticsearch.search.aggregations.support.AggregationContext;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.search.sort.SortBuilder;
-import org.elasticsearch.xcontent.XContentBuilder;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Builds the Top Metrics aggregation request.
- * <p>
- * NOTE: This extends {@linkplain AbstractAggregationBuilder} for compatibility
- * with {@link SearchSourceBuilder#aggregation(AggregationBuilder)} but it
- * doesn't support any "server" side things like
- * {@linkplain Writeable#writeTo(StreamOutput)},
- * {@linkplain AggregationBuilder#rewrite(QueryRewriteContext)}, or
- * {@linkplain AbstractAggregationBuilder#build(AggregationContext, AggregatorFactory)}.
- */
-public class TopMetricsAggregationBuilder extends AbstractAggregationBuilder<TopMetricsAggregationBuilder> {
-    public static final String NAME = "top_metrics";
-
-    private final SortBuilder<?> sort;
-    private final int size;
-    private final List<String> metrics;
-
-    /**
-     * Build the request.
-     * @param name the name of the metric
-     * @param sort the sort key used to select the top metrics
-     * @param size number of results to return per bucket
-     * @param metrics the names of the fields to select
-     */
-    public TopMetricsAggregationBuilder(String name, SortBuilder<?> sort, int size, String... metrics) {
-        super(name);
-        this.sort = sort;
-        this.size = size;
-        this.metrics = Arrays.asList(metrics);
-    }
-
-    @Override
-    public String getType() {
-        return NAME;
-    }
-
-    @Override
-    protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.startObject();
-        {
-            builder.startArray("sort");
-            sort.toXContent(builder, params);
-            builder.endArray();
-            builder.field("size", size);
-            builder.startArray("metrics");
-            for (String metric : metrics) {
-                builder.startObject().field("field", metric).endObject();
-            }
-            builder.endArray();
-        }
-        return builder.endObject();
-    }
-
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public BucketCardinality bucketCardinality() {
-        return BucketCardinality.NONE;
-    }
-
-    @Override
-    protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subfactoriesBuilder)
-        throws IOException {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, Object> metadata) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public TransportVersion getMinimalSupportedVersion() {
-        return TransportVersions.V_7_7_0;
-    }
-}

+ 0 - 30
x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/stringstats/StringStatsAggregationBuilderTests.java

@@ -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
@@ -77,28 +71,4 @@ public class StringStatsAggregationBuilderTests extends AbstractXContentSerializ
         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());
-    }
 }

+ 0 - 33
x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregationBuilderTests.java

@@ -17,11 +17,8 @@ import org.elasticsearch.search.sort.FieldSortBuilder;
 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;
@@ -30,9 +27,7 @@ import java.util.List;
 
 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
@@ -92,16 +87,6 @@ public class TopMetricsAggregationBuilderTests extends AbstractXContentSerializi
         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(
@@ -121,22 +106,4 @@ public class TopMetricsAggregationBuilderTests extends AbstractXContentSerializi
         });
         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)
-        );
-    }
 }