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
This commit is contained in:
Michael Basnight 2019-10-30 14:41:05 -05:00
parent eee4cfaa8b
commit ede1681c5a
4 changed files with 39 additions and 144 deletions

View File

@ -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<T extends ToXContent, H> extends AbstractXContentTestCase<T> {
/**
* 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);
}

View File

@ -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<String> getRandomFieldsExcludeFilter() {
return field -> field.contains("position");
protected void assertInstances(org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo serverTestInstance,
TransformCheckpointingInfo clientInstance) {
assertTransformCheckpointInfo(serverTestInstance, clientInstance);
}
}

View File

@ -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);
}
}

View File

@ -102,7 +102,7 @@ public class TransformStatsTests extends AbstractResponseTestCase<org.elasticsea
assertThat(serverTestInstance.getTransportAddress(), equalTo(clientInstance.getTransportAddress()));
}
private void assertTransformProgress(org.elasticsearch.xpack.core.transform.transforms.TransformProgress serverTestInstance,
public static void assertTransformProgress(org.elasticsearch.xpack.core.transform.transforms.TransformProgress serverTestInstance,
TransformProgress clientInstance) {
if (serverTestInstance == null || clientInstance == null) {
assertNull(serverTestInstance);
@ -115,16 +115,16 @@ public class TransformStatsTests extends AbstractResponseTestCase<org.elasticsea
assertThat(serverTestInstance.getDocumentsIndexed(), equalTo(clientInstance.getDocumentsIndexed()));
}
private void assertPosition(org.elasticsearch.xpack.core.transform.transforms.TransformIndexerPosition serverTestInstance,
public static void assertPosition(org.elasticsearch.xpack.core.transform.transforms.TransformIndexerPosition serverTestInstance,
TransformIndexerPosition clientInstance) {
assertThat(serverTestInstance.getIndexerPosition(), equalTo(clientInstance.getIndexerPosition()));
assertThat(serverTestInstance.getBucketsPosition(), equalTo(clientInstance.getBucketsPosition()));
}
private void assertTransformCheckpointStats(
org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointStats serverTestInstance,
TransformCheckpointStats clientInstance) {
public static void assertTransformCheckpointStats(
org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointStats serverTestInstance,
TransformCheckpointStats clientInstance) {
assertTransformProgress(serverTestInstance.getCheckpointProgress(), clientInstance.getCheckpointProgress());
assertThat(serverTestInstance.getCheckpoint(), equalTo(clientInstance.getCheckpoint()));
assertPosition(serverTestInstance.getPosition(), clientInstance.getPosition());
@ -132,17 +132,18 @@ public class TransformStatsTests extends AbstractResponseTestCase<org.elasticsea
assertThat(serverTestInstance.getTimeUpperBoundMillis(), equalTo(clientInstance.getTimeUpperBoundMillis()));
}
private void assertTransformCheckpointInfo(
org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo serverTestInstance,
TransformCheckpointingInfo clientInstance) {
public static void assertTransformCheckpointInfo(
org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo serverTestInstance,
TransformCheckpointingInfo clientInstance) {
assertTransformCheckpointStats(serverTestInstance.getNext(), clientInstance.getNext());
assertTransformCheckpointStats(serverTestInstance.getLast(), clientInstance.getLast());
assertThat(serverTestInstance.getChangesLastDetectedAt(), equalTo(clientInstance.getChangesLastDetectedAt()));
assertThat(serverTestInstance.getOperationsBehind(), equalTo(clientInstance.getOperationsBehind()));
}
private void assertTransformIndexerStats(org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats serverTestInstance,
TransformIndexerStats clientInstance) {
public static void assertTransformIndexerStats(
org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats serverTestInstance,
TransformIndexerStats clientInstance) {
assertThat(serverTestInstance.getExpAvgCheckpointDurationMs(), equalTo(clientInstance.getExpAvgCheckpointDurationMs()));
assertThat(serverTestInstance.getExpAvgDocumentsProcessed(), equalTo(clientInstance.getExpAvgDocumentsProcessed()));
assertThat(serverTestInstance.getExpAvgDocumentsIndexed(), equalTo(clientInstance.getExpAvgDocumentsIndexed()));