Add wire tests for get autoscaling decision objects

This commit adds wire serializing tests for the get autoscaling decision
request and response objects.
This commit is contained in:
Jason Tedor 2020-04-05 21:26:36 -04:00
parent 8f520f0a9c
commit b939b47b77
No known key found for this signature in database
GPG Key ID: 8CF9C19984731E85
4 changed files with 91 additions and 0 deletions

View File

@ -51,6 +51,18 @@ public class GetAutoscalingDecisionAction extends ActionType<GetAutoscalingDecis
return null;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return true;
}
@Override
public int hashCode() {
return 0;
}
}
public static class Response extends ActionResponse implements ToXContentObject {
@ -91,6 +103,19 @@ public class GetAutoscalingDecisionAction extends ActionType<GetAutoscalingDecis
return builder;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Response response = (Response) o;
return decisions.equals(response.decisions);
}
@Override
public int hashCode() {
return Objects.hash(decisions);
}
}
}

View File

@ -23,6 +23,10 @@ public class AutoscalingDecisions implements ToXContent, Writeable {
private final Collection<AutoscalingDecision> decisions;
public Collection<AutoscalingDecision> decisions() {
return decisions;
}
public AutoscalingDecisions(final Collection<AutoscalingDecision> decisions) {
Objects.requireNonNull(decisions);
if (decisions.isEmpty()) {

View File

@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.autoscaling.action;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
public class GetAutoscalingDecisionActionRequestWireSerializingTests extends AbstractWireSerializingTestCase<
GetAutoscalingDecisionAction.Request> {
@Override
protected Writeable.Reader<GetAutoscalingDecisionAction.Request> instanceReader() {
return GetAutoscalingDecisionAction.Request::new;
}
@Override
protected GetAutoscalingDecisionAction.Request createTestInstance() {
return new GetAutoscalingDecisionAction.Request();
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.autoscaling.action;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecisions;
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingDecisions;
public class GetAutoscalingDecisionActionResponseWireSerializingTests extends AbstractWireSerializingTestCase<
GetAutoscalingDecisionAction.Response> {
@Override
protected Writeable.Reader<GetAutoscalingDecisionAction.Response> instanceReader() {
return GetAutoscalingDecisionAction.Response::new;
}
@Override
protected GetAutoscalingDecisionAction.Response createTestInstance() {
final int numberOfPolicies = randomIntBetween(1, 8);
final SortedMap<String, AutoscalingDecisions> decisions = new TreeMap<>();
for (int i = 0; i < numberOfPolicies; i++) {
decisions.put(randomAlphaOfLength(8), randomAutoscalingDecisions());
}
return new GetAutoscalingDecisionAction.Response(Collections.unmodifiableSortedMap(decisions));
}
}