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:
parent
8f520f0a9c
commit
b939b47b77
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue