Remove deprecated test from the HLRC tests (#48424)

The AbstractHlrcWriteableXContentTestCase was replaced by a better test
case a while ago, and this is the last two instances using it. They have
been converted and the test is now deleted.

Ref #39745
This commit is contained in:
Michael Basnight 2019-10-24 12:14:19 -05:00
parent b2974e3816
commit d49958cef3
4 changed files with 52 additions and 176 deletions

View File

@ -1,70 +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.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException;
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
/**
* @deprecated Use {@link AbstractResponseTestCase} instead of this class.
*/
// TODO: Remove and change subclasses to use AbstractResponseTestCase instead
@Deprecated
public abstract class AbstractHlrcWriteableXContentTestCase<T extends ToXContent & Writeable, H>
extends AbstractSerializingTestCase<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 {
xContentTester(this::createParser, this::createTestInstance, getToXContentParams(),
p -> convertHlrcToInternal(doHlrcParseInstance(p)))
.numberOfTestRuns(NUMBER_OF_TEST_RUNS)
.supportsUnknownFields(supportsUnknownFields())
.shuffleFieldsExceptions(getShuffleFieldsExceptions())
.randomFieldsExcludeFilter(getRandomFieldsExcludeFilter())
.assertEqualsConsumer(this::assertEqualInstances)
.assertToXContentEquivalence(true)
.test();
}
/**
* 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);
//TODO this would be final ideally: why do both responses need to parse from xcontent, only one (H) should? I think that T#fromXContent
//are only there for testing and could go away? Then the additional testHlrcFromXContent is also no longer needed.
@Override
protected T doParseInstance(XContentParser parser) throws IOException {
return convertHlrcToInternal(doHlrcParseInstance(parser));
}
}

View File

@ -18,48 +18,23 @@
*/
package org.elasticsearch.client.license;
import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
public class PutLicenseResponseTests extends AbstractHlrcWriteableXContentTestCase<
import static org.hamcrest.Matchers.equalTo;
public class PutLicenseResponseTests extends AbstractResponseTestCase<
org.elasticsearch.protocol.xpack.license.PutLicenseResponse, PutLicenseResponse> {
@Override
public org.elasticsearch.client.license.PutLicenseResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.PutLicenseResponse.fromXContent(parser);
}
@Override
public org.elasticsearch.protocol.xpack.license.PutLicenseResponse convertHlrcToInternal(
org.elasticsearch.client.license.PutLicenseResponse instance) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(instance.isAcknowledged(),
org.elasticsearch.protocol.xpack.license.LicensesStatus.valueOf(instance.status().name()),
instance.acknowledgeHeader(), instance.acknowledgeMessages());
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
// are treated as messages from new services
return p -> p.startsWith("acknowledge");
}
@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createTestInstance() {
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse createServerTestInstance(XContentType xContentType) {
boolean acknowledged = randomBoolean();
org.elasticsearch.protocol.xpack.license.LicensesStatus status =
randomFrom(org.elasticsearch.protocol.xpack.license.LicensesStatus.VALID,
@ -97,45 +72,18 @@ public class PutLicenseResponseTests extends AbstractHlrcWriteableXContentTestCa
}
@Override
protected Writeable.Reader<org.elasticsearch.protocol.xpack.license.PutLicenseResponse> instanceReader() {
return org.elasticsearch.protocol.xpack.license.PutLicenseResponse::new;
protected PutLicenseResponse doParseToClientInstance(XContentParser parser) throws IOException {
return PutLicenseResponse.fromXContent(parser);
}
@Override
protected org.elasticsearch.protocol.xpack.license.PutLicenseResponse mutateInstance(
org.elasticsearch.protocol.xpack.license.PutLicenseResponse response) {
@SuppressWarnings("unchecked")
Function<org.elasticsearch.protocol.xpack.license.PutLicenseResponse,
org.elasticsearch.protocol.xpack.license.PutLicenseResponse> mutator = randomFrom(
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged() == false,
r.status(),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
mutateStatus(r.status()),
r.acknowledgeHeader(),
r.acknowledgeMessages()),
r -> {
if (r.acknowledgeMessages().isEmpty()) {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(
r.isAcknowledged(),
r.status(),
randomAlphaOfLength(10),
randomAckMessages()
);
} else {
return new org.elasticsearch.protocol.xpack.license.PutLicenseResponse(r.isAcknowledged(), r.status());
}
}
);
return mutator.apply(response);
}
private org.elasticsearch.protocol.xpack.license.LicensesStatus mutateStatus(
org.elasticsearch.protocol.xpack.license.LicensesStatus status) {
return randomValueOtherThan(status, () -> randomFrom(LicensesStatus.values()));
protected void assertInstances(org.elasticsearch.protocol.xpack.license.PutLicenseResponse serverTestInstance,
PutLicenseResponse clientInstance) {
assertThat(serverTestInstance.status().name(), equalTo(clientInstance.status().name()));
assertThat(serverTestInstance.acknowledgeHeader(), equalTo(clientInstance.acknowledgeHeader()));
assertThat(serverTestInstance.acknowledgeMessages().keySet(), equalTo(clientInstance.acknowledgeMessages().keySet()));
for(Map.Entry<String, String[]> entry: serverTestInstance.acknowledgeMessages().entrySet()) {
assertTrue(Arrays.equals(entry.getValue(), clientInstance.acknowledgeMessages().get(entry.getKey())));
}
}
}

View File

@ -18,51 +18,24 @@
*/
package org.elasticsearch.client.license;
import org.elasticsearch.client.AbstractHlrcWriteableXContentTestCase;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.client.AbstractResponseTestCase;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.license.PostStartBasicResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
public class StartBasicResponseTests extends AbstractHlrcWriteableXContentTestCase<
import static org.hamcrest.Matchers.equalTo;
public class StartBasicResponseTests extends AbstractResponseTestCase<
PostStartBasicResponse, StartBasicResponse> {
@Override
public org.elasticsearch.client.license.StartBasicResponse doHlrcParseInstance(XContentParser parser) throws IOException {
return org.elasticsearch.client.license.StartBasicResponse.fromXContent(parser);
}
@Override
public PostStartBasicResponse convertHlrcToInternal(org.elasticsearch.client.license.StartBasicResponse instance) {
return new PostStartBasicResponse(PostStartBasicResponse.Status.valueOf(instance.getStatus().name()),
instance.getAcknowledgeMessages(), instance.getAcknowledgeMessage());
}
@Override
protected Writeable.Reader<PostStartBasicResponse> instanceReader() {
return PostStartBasicResponse::new;
}
@Override
protected boolean supportsUnknownFields() {
return true;
}
@Override
protected Predicate<String> getRandomFieldsExcludeFilter() {
// The structure of the response is such that unknown fields inside acknowledge cannot be supported since they
// are treated as messages from new services
return p -> p.startsWith("acknowledge");
}
@Override
protected PostStartBasicResponse createTestInstance() {
protected PostStartBasicResponse createServerTestInstance(XContentType xContentType) {
PostStartBasicResponse.Status status = randomFrom(PostStartBasicResponse.Status.values());
String acknowledgeMessage = null;
Map<String, String[]> ackMessages = Collections.emptyMap();
@ -71,7 +44,6 @@ public class StartBasicResponseTests extends AbstractHlrcWriteableXContentTestCa
ackMessages = randomAckMessages();
}
final PostStartBasicResponse postStartBasicResponse = new PostStartBasicResponse(status, ackMessages, acknowledgeMessage);
logger.info("{}", Strings.toString(postStartBasicResponse));
return postStartBasicResponse;
}
@ -92,4 +64,22 @@ public class StartBasicResponseTests extends AbstractHlrcWriteableXContentTestCa
return ackMessages;
}
@Override
protected StartBasicResponse doParseToClientInstance(XContentParser parser) throws IOException {
return StartBasicResponse.fromXContent(parser);
}
@Override
protected void assertInstances(PostStartBasicResponse serverTestInstance, StartBasicResponse clientInstance) {
assertThat(serverTestInstance.getStatus().name(), equalTo(clientInstance.getStatus().name()));
assertThat(serverTestInstance.getStatus().isBasicStarted(), equalTo(clientInstance.isBasicStarted()));
assertThat(serverTestInstance.isAcknowledged(), equalTo(clientInstance.isAcknowledged()));
assertThat(serverTestInstance.getStatus().getErrorMessage(), equalTo(clientInstance.getErrorMessage()));
assertThat(serverTestInstance.getAcknowledgeMessage(), equalTo(clientInstance.getAcknowledgeMessage()));
assertThat(serverTestInstance.getAcknowledgeMessages().keySet(), equalTo(clientInstance.getAcknowledgeMessages().keySet()));
for(Map.Entry<String, String[]> entry: serverTestInstance.getAcknowledgeMessages().entrySet()) {
assertTrue(Arrays.equals(entry.getValue(), clientInstance.getAcknowledgeMessages().get(entry.getKey())));
}
}
}

View File

@ -44,11 +44,11 @@ public class PostStartBasicResponse extends AcknowledgedResponse implements Stat
this.restStatus = restStatus;
}
boolean isBasicStarted() {
public boolean isBasicStarted() {
return isBasicStarted;
}
String getErrorMessage() {
public String getErrorMessage() {
return errorMessage;
}
@ -134,6 +134,14 @@ public class PostStartBasicResponse extends AcknowledgedResponse implements Stat
return status.restStatus;
}
public String getAcknowledgeMessage() {
return acknowledgeMessage;
}
public Map<String, String[]> getAcknowledgeMessages() {
return acknowledgeMessages;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;