浏览代码

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.
Jason Tedor 5 年之前
父节点
当前提交
b390b7c3eb

+ 2 - 3
x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingMetadataDiffableSerializationTests.java

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

+ 11 - 0
x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/AutoscalingTestCase.java

@@ -7,6 +7,9 @@
 package org.elasticsearch.xpack.autoscaling;
 
 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.xpack.autoscaling.decision.AlwaysAutoscalingDecider;
 import org.elasticsearch.xpack.autoscaling.decision.AutoscalingDecider;
@@ -116,4 +119,12 @@ public abstract class AutoscalingTestCase extends ESTestCase {
         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());
+    }
+
 }

+ 3 - 4
x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/policy/AutoscalingPolicyMetadataDiffableSerializationTests.java

@@ -10,11 +10,10 @@ import org.elasticsearch.cluster.AbstractDiffable;
 import org.elasticsearch.cluster.Diff;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
 import org.elasticsearch.common.io.stream.Writeable;
-import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.NamedXContentRegistry;
 import org.elasticsearch.common.xcontent.XContentParser;
 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.randomAutoscalingPolicyOfName;
@@ -25,12 +24,12 @@ public class AutoscalingPolicyMetadataDiffableSerializationTests extends Abstrac
 
     @Override
     protected NamedWriteableRegistry getNamedWriteableRegistry() {
-        return new NamedWriteableRegistry(new Autoscaling(Settings.EMPTY).getNamedWriteables());
+        return AutoscalingTestCase.getAutoscalingNamedWriteableRegistry();
     }
 
     @Override
     protected NamedXContentRegistry xContentRegistry() {
-        return new NamedXContentRegistry(new Autoscaling(Settings.EMPTY).getNamedXContent());
+        return AutoscalingTestCase.getAutoscalingXContentRegistry();
     }
 
     @Override

+ 3 - 4
x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/policy/AutoscalingPolicySerializingTests.java

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