Migrate common autoscaling test code to base class

This commit moves some code repeated in a few autoscaling tests related
to writeable and x-content registries to the autoscaling tests base
class.
This commit is contained in:
Jason Tedor 2020-04-04 09:55:55 -04:00
parent dd99e6d951
commit 79c72cd398
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
4 changed files with 19 additions and 11 deletions

View File

@ -10,7 +10,6 @@ import org.elasticsearch.cluster.Diff;
import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractDiffableSerializationTestCase; import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
@ -29,12 +28,12 @@ public class AutoscalingMetadataDiffableSerializationTests extends AbstractDiffa
@Override @Override
protected NamedWriteableRegistry getNamedWriteableRegistry() { protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(new Autoscaling(Settings.EMPTY).getNamedWriteables()); return AutoscalingTestCase.getAutoscalingNamedWriteableRegistry();
} }
@Override @Override
protected NamedXContentRegistry xContentRegistry() { protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(new Autoscaling(Settings.EMPTY).getNamedXContent()); return AutoscalingTestCase.getAutoscalingXContentRegistry();
} }
@Override @Override

View File

@ -7,6 +7,9 @@
package org.elasticsearch.xpack.autoscaling; package org.elasticsearch.xpack.autoscaling;
import org.elasticsearch.common.Randomness; import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.autoscaling.decision.AlwaysAutoscalingDecider; import org.elasticsearch.xpack.autoscaling.decision.AlwaysAutoscalingDecider;
import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecider; import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecider;
@ -118,4 +121,12 @@ public abstract class AutoscalingTestCase extends ESTestCase {
return new AutoscalingMetadata(policies); return new AutoscalingMetadata(policies);
} }
public static NamedWriteableRegistry getAutoscalingNamedWriteableRegistry() {
return new NamedWriteableRegistry(new Autoscaling(Settings.EMPTY).getNamedWriteables());
}
public static NamedXContentRegistry getAutoscalingXContentRegistry() {
return new NamedXContentRegistry(new Autoscaling(Settings.EMPTY).getNamedXContent());
}
} }

View File

@ -10,11 +10,10 @@ import org.elasticsearch.cluster.AbstractDiffable;
import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diff;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractDiffableSerializationTestCase; import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
import org.elasticsearch.xpack.autoscaling.Autoscaling; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase;
import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.mutateAutoscalingPolicy; import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.mutateAutoscalingPolicy;
import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicyOfName; import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicyOfName;
@ -25,12 +24,12 @@ public class AutoscalingPolicyMetadataDiffableSerializationTests extends Abstrac
@Override @Override
protected NamedWriteableRegistry getNamedWriteableRegistry() { protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(new Autoscaling(Settings.EMPTY).getNamedWriteables()); return AutoscalingTestCase.getAutoscalingNamedWriteableRegistry();
} }
@Override @Override
protected NamedXContentRegistry xContentRegistry() { protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(new Autoscaling(Settings.EMPTY).getNamedXContent()); return AutoscalingTestCase.getAutoscalingXContentRegistry();
} }
@Override @Override

View File

@ -8,11 +8,10 @@ package org.elasticsearch.xpack.autoscaling.policy;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.test.AbstractSerializingTestCase;
import org.elasticsearch.xpack.autoscaling.Autoscaling; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase;
import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.mutateAutoscalingPolicy; import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.mutateAutoscalingPolicy;
import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicyOfName; import static org.elasticsearch.xpack.autoscaling.AutoscalingTestCase.randomAutoscalingPolicyOfName;
@ -23,12 +22,12 @@ public class AutoscalingPolicySerializingTests extends AbstractSerializingTestCa
@Override @Override
protected NamedWriteableRegistry getNamedWriteableRegistry() { protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(new Autoscaling(Settings.EMPTY).getNamedWriteables()); return AutoscalingTestCase.getAutoscalingNamedWriteableRegistry();
} }
@Override @Override
protected NamedXContentRegistry xContentRegistry() { protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(new Autoscaling(Settings.EMPTY).getNamedXContent()); return AutoscalingTestCase.getAutoscalingXContentRegistry();
} }
@Override @Override