From ede1681c5aae5fb6e7ac157daadf7eb6e318e91f Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Wed, 30 Oct 2019 14:41:05 -0500 Subject: [PATCH] Remove old HLRC base test case (#48714) This commit finishes cleaning up the AbstractHlrcXContentTestCase work and removes this class. All classes that were using this are now using the updated base class. Ref #39745 --- .../client/AbstractHlrcXContentTestCase.java | 54 ------------------ .../hlrc/TransformCheckpointingInfoTests.java | 51 +++++------------ .../hlrc/TransformIndexerStatsTests.java | 57 +++++-------------- .../transforms/hlrc/TransformStatsTests.java | 21 +++---- 4 files changed, 39 insertions(+), 144 deletions(-) delete mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java deleted file mode 100644 index 62e03e6934a..00000000000 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractHlrcXContentTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.client; - -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractXContentTestCase; - -import java.io.IOException; - -/** - * @deprecated Use {@link AbstractResponseTestCase} instead of this class. - */ -// TODO: Remove and change subclasses to use AbstractResponseTestCase instead -@Deprecated -public abstract class AbstractHlrcXContentTestCase extends AbstractXContentTestCase { - - /** - * Generic test that creates new instance of HLRC request/response from the test instance and checks - * both for equality and asserts equality on the two queries. - */ - public final void testHlrcFromXContent() throws IOException { - AbstractXContentTestCase.testFromXContent(NUMBER_OF_TEST_RUNS, this::createTestInstance, supportsUnknownFields(), - getShuffleFieldsExceptions(), getRandomFieldsExcludeFilter(), this::createParser, - p -> convertHlrcToInternal(doHlrcParseInstance(p)), - this::assertEqualInstances, assertToXContentEquivalence(), getToXContentParams()); - } - - /** - * Parses to a new HLRC instance using the provided {@link XContentParser} - */ - public abstract H doHlrcParseInstance(XContentParser parser) throws IOException; - - /** - * Converts a HLRC instance to a XPack instance - */ - public abstract T convertHlrcToInternal(H instance); -} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformCheckpointingInfoTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformCheckpointingInfoTests.java index 663d32ff3c4..ca1ca32ede9 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformCheckpointingInfoTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformCheckpointingInfoTests.java @@ -19,40 +19,22 @@ package org.elasticsearch.client.transform.transforms.hlrc; -import org.elasticsearch.client.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractResponseTestCase; +import org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; import java.time.Instant; -import java.util.function.Predicate; -public class TransformCheckpointingInfoTests extends AbstractHlrcXContentTestCase< - TransformCheckpointingInfo, - org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo> { +import static org.elasticsearch.client.transform.transforms.hlrc.TransformStatsTests.assertTransformCheckpointInfo; - public static TransformCheckpointingInfo fromHlrc( - org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo instance) { - return new TransformCheckpointingInfo( - TransformCheckpointStatsTests.fromHlrc(instance.getLast()), - TransformCheckpointStatsTests.fromHlrc(instance.getNext()), - instance.getOperationsBehind(), - instance.getChangesLastDetectedAt()); - } +public class TransformCheckpointingInfoTests extends AbstractResponseTestCase< + org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo, + TransformCheckpointingInfo> { - @Override - public org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo doHlrcParseInstance(XContentParser parser) { - return org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo.fromXContent(parser); - } - - @Override - public TransformCheckpointingInfo convertHlrcToInternal( - org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo instance) { - return fromHlrc(instance); - } - - public static TransformCheckpointingInfo randomTransformCheckpointingInfo() { - return new TransformCheckpointingInfo( + public static org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo randomTransformCheckpointingInfo() { + return new org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo( TransformCheckpointStatsTests.randomTransformCheckpointStats(), TransformCheckpointStatsTests.randomTransformCheckpointStats(), randomNonNegativeLong(), @@ -60,22 +42,19 @@ public class TransformCheckpointingInfoTests extends AbstractHlrcXContentTestCas } @Override - protected TransformCheckpointingInfo createTestInstance() { + protected org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo + createServerTestInstance(XContentType xContentType) { return randomTransformCheckpointingInfo(); } @Override - protected TransformCheckpointingInfo doParseInstance(XContentParser parser) throws IOException { + protected TransformCheckpointingInfo doParseToClientInstance(XContentParser parser) throws IOException { return TransformCheckpointingInfo.fromXContent(parser); } @Override - protected boolean supportsUnknownFields() { - return true; - } - - @Override - protected Predicate getRandomFieldsExcludeFilter() { - return field -> field.contains("position"); + protected void assertInstances(org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo serverTestInstance, + TransformCheckpointingInfo clientInstance) { + assertTransformCheckpointInfo(serverTestInstance, clientInstance); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformIndexerStatsTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformIndexerStatsTests.java index e4e22bf3611..50c98bcd8f0 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformIndexerStatsTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformIndexerStatsTests.java @@ -19,48 +19,22 @@ package org.elasticsearch.client.transform.transforms.hlrc; -import org.elasticsearch.client.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractResponseTestCase; +import org.elasticsearch.client.transform.transforms.TransformIndexerStats; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; -public class TransformIndexerStatsTests extends AbstractHlrcXContentTestCase< - TransformIndexerStats, - org.elasticsearch.client.transform.transforms.TransformIndexerStats> { +import static org.elasticsearch.client.transform.transforms.hlrc.TransformStatsTests.assertTransformIndexerStats; - public static TransformIndexerStats fromHlrc( - org.elasticsearch.client.transform.transforms.TransformIndexerStats instance) { - return new TransformIndexerStats( - instance.getNumPages(), - instance.getNumDocuments(), - instance.getOutputDocuments(), - instance.getNumInvocations(), - instance.getIndexTime(), - instance.getSearchTime(), - instance.getIndexTotal(), - instance.getSearchTotal(), - instance.getIndexFailures(), - instance.getSearchFailures(), - instance.getExpAvgCheckpointDurationMs(), - instance.getExpAvgDocumentsIndexed(), - instance.getExpAvgDocumentsProcessed()); - } +public class TransformIndexerStatsTests extends AbstractResponseTestCase< + org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats, + TransformIndexerStats> { @Override - public org.elasticsearch.client.transform.transforms.TransformIndexerStats doHlrcParseInstance(XContentParser parser) - throws IOException { - return org.elasticsearch.client.transform.transforms.TransformIndexerStats.fromXContent(parser); - } - - @Override - public TransformIndexerStats convertHlrcToInternal( - org.elasticsearch.client.transform.transforms.TransformIndexerStats instance) { - return fromHlrc(instance); - } - - public static TransformIndexerStats randomStats() { - return new TransformIndexerStats(randomLongBetween(10L, 10000L), + protected org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats createServerTestInstance(XContentType xContentType) { + return new org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats(randomLongBetween(10L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), @@ -70,18 +44,13 @@ public class TransformIndexerStatsTests extends AbstractHlrcXContentTestCase< } @Override - protected TransformIndexerStats createTestInstance() { - return randomStats(); - } - - @Override - protected TransformIndexerStats doParseInstance(XContentParser parser) throws IOException { + protected TransformIndexerStats doParseToClientInstance(XContentParser parser) throws IOException { return TransformIndexerStats.fromXContent(parser); } @Override - protected boolean supportsUnknownFields() { - return true; + protected void assertInstances(org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats serverTestInstance, + TransformIndexerStats clientInstance) { + assertTransformIndexerStats(serverTestInstance, clientInstance); } - } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java index d9dfcee4c69..63f6bffdf63 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java @@ -102,7 +102,7 @@ public class TransformStatsTests extends AbstractResponseTestCase