diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java index 5c15fb7bed7..d9dfcee4c69 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/transform/transforms/hlrc/TransformStatsTests.java @@ -19,123 +19,42 @@ package org.elasticsearch.client.transform.transforms.hlrc; -import org.elasticsearch.client.AbstractHlrcXContentTestCase; +import org.elasticsearch.client.AbstractResponseTestCase; +import org.elasticsearch.client.transform.transforms.NodeAttributes; +import org.elasticsearch.client.transform.transforms.TransformCheckpointStats; +import org.elasticsearch.client.transform.transforms.TransformCheckpointingInfo; +import org.elasticsearch.client.transform.transforms.TransformIndexerPosition; +import org.elasticsearch.client.transform.transforms.TransformIndexerStats; +import org.elasticsearch.client.transform.transforms.TransformProgress; +import org.elasticsearch.client.transform.transforms.TransformStats; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats; -import org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointStats; -import org.elasticsearch.xpack.core.transform.transforms.TransformCheckpointingInfo; -import org.elasticsearch.xpack.core.transform.transforms.TransformProgress; -import org.elasticsearch.xpack.core.transform.transforms.TransformStats; -import org.elasticsearch.xpack.core.transform.transforms.NodeAttributes; +import org.elasticsearch.common.xcontent.XContentType; import java.io.IOException; -import java.time.Instant; import java.util.HashMap; import java.util.Map; -import java.util.function.Predicate; -public class TransformStatsTests extends AbstractHlrcXContentTestCase { - public static NodeAttributes fromHlrc(org.elasticsearch.client.transform.transforms.NodeAttributes attributes) { - return attributes == null ? null : new NodeAttributes(attributes.getId(), - attributes.getName(), - attributes.getEphemeralId(), - attributes.getTransportAddress(), - attributes.getAttributes()); - } - - public static TransformStats - fromHlrc(org.elasticsearch.client.transform.transforms.TransformStats instance) { - - return new TransformStats(instance.getId(), - TransformStats.State.fromString(instance.getState().value()), - instance.getReason(), - fromHlrc(instance.getNode()), - TransformIndexerStatsTests.fromHlrc(instance.getIndexerStats()), - TransformCheckpointingInfoTests.fromHlrc(instance.getCheckpointingInfo())); - } - - @Override - public org.elasticsearch.client.transform.transforms.TransformStats doHlrcParseInstance(XContentParser parser) - throws IOException { - return org.elasticsearch.client.transform.transforms.TransformStats.fromXContent(parser); - } - - @Override - public TransformStats convertHlrcToInternal( - org.elasticsearch.client.transform.transforms.TransformStats instance) { - return new TransformStats(instance.getId(), - TransformStats.State.fromString(instance.getState().value()), - instance.getReason(), - fromHlrc(instance.getNode()), - TransformIndexerStatsTests.fromHlrc(instance.getIndexerStats()), - TransformCheckpointingInfoTests.fromHlrc(instance.getCheckpointingInfo())); - } - - public static TransformStats randomTransformStats() { - return new TransformStats(randomAlphaOfLength(10), - randomFrom(TransformStats.State.values()), - randomBoolean() ? null : randomAlphaOfLength(100), - randomBoolean() ? null : randomNodeAttributes(), - randomStats(), - TransformCheckpointingInfoTests.randomTransformCheckpointingInfo()); - } - - @Override - protected TransformStats createTestInstance() { - return randomTransformStats(); - } - - @Override - protected TransformStats doParseInstance(XContentParser parser) throws IOException { - return TransformStats.PARSER.apply(parser, null); - } - - @Override - protected Predicate getRandomFieldsExcludeFilter() { - return field -> field.contains("position") || field.equals("node.attributes"); - } - - public static TransformProgress randomTransformProgress() { - Long totalDocs = randomBoolean() ? null : randomNonNegativeLong(); - Long docsRemaining = totalDocs != null ? randomLongBetween(0, totalDocs) : null; - return new TransformProgress( - totalDocs, - docsRemaining, - totalDocs != null ? totalDocs - docsRemaining : randomNonNegativeLong(), - randomBoolean() ? null : randomNonNegativeLong()); - } - - public static TransformCheckpointingInfo randomTransformCheckpointingInfo() { - return new TransformCheckpointingInfo(randomTransformCheckpointStats(), - randomTransformCheckpointStats(), randomNonNegativeLong(), - randomBoolean() ? null : Instant.ofEpochMilli(randomNonNegativeLong())); - } - - public static TransformCheckpointStats randomTransformCheckpointStats() { - return new TransformCheckpointStats(randomLongBetween(1, 1_000_000), - TransformIndexerPositionTests.randomTransformIndexerPosition(), - randomBoolean() ? null : TransformProgressTests.randomTransformProgress(), - randomLongBetween(1, 1_000_000), randomLongBetween(0, 1_000_000)); - } - - public static NodeAttributes randomNodeAttributes() { + public static org.elasticsearch.xpack.core.transform.transforms.NodeAttributes randomNodeAttributes() { int numberOfAttributes = randomIntBetween(1, 10); Map attributes = new HashMap<>(numberOfAttributes); for(int i = 0; i < numberOfAttributes; i++) { String val = randomAlphaOfLength(10); attributes.put("key-"+i, val); } - return new NodeAttributes(randomAlphaOfLength(10), + return new org.elasticsearch.xpack.core.transform.transforms.NodeAttributes(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10), attributes); } - public static TransformIndexerStats randomStats() { - return new TransformIndexerStats(randomLongBetween(10L, 10000L), + public static org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats randomStats() { + return new org.elasticsearch.xpack.core.transform.transforms.TransformIndexerStats(randomLongBetween(10L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), randomLongBetween(0L, 10000L), @@ -143,14 +62,99 @@ public class TransformStatsTests extends AbstractHlrcXContentTestCase