diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformAction.java index 11d13d48b1dc..13e62da090c3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformAction.java @@ -49,7 +49,7 @@ public Request(String id) { this.id = ExceptionsHelper.requireNonNull(id, DataFrameField.ID.getPreferredName()); } - public Request() { + private Request() { } public Request(StreamInput in) throws IOException { @@ -113,7 +113,7 @@ protected RequestBuilder(ElasticsearchClient client, DeleteDataFrameTransformAct public static class Response extends BaseTasksResponse implements Writeable, ToXContentObject { private boolean acknowledged; public Response(StreamInput in) throws IOException { - super(Collections.emptyList(), Collections.emptyList()); + super(in); readFrom(in); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsAction.java index 2d48980d0724..7759e7d3f161 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsAction.java @@ -63,7 +63,7 @@ public Request(String id) { } } - public Request() {} + private Request() {} public Request(StreamInput in) throws IOException { super(in); @@ -149,7 +149,7 @@ public Response() { } public Response(StreamInput in) throws IOException { - super(Collections.emptyList(), Collections.emptyList()); + super(in); readFrom(in); } @@ -173,6 +173,7 @@ public void writeTo(StreamOutput out) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { List invalidTransforms = new ArrayList<>(); builder.startObject(); + toXContentCommon(builder, params); builder.field(DataFrameField.COUNT.getPreferredName(), transformConfigurations.size()); // XContentBuilder does not support passing the params object for Iterables builder.field(DataFrameField.TRANSFORMS.getPreferredName()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsAction.java index f24666d1a4a3..47e922033072 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsAction.java @@ -55,7 +55,7 @@ public Request(String id) { } } - public Request() {} + private Request() {} public Request(StreamInput in) throws IOException { super(in); @@ -138,7 +138,7 @@ public Response() { } public Response(StreamInput in) throws IOException { - super(Collections.emptyList(), Collections.emptyList()); + super(in); readFrom(in); } @@ -161,6 +161,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + toXContentCommon(builder, params); builder.field(DataFrameField.COUNT.getPreferredName(), transformsStateAndStats.size()); builder.field(DataFrameField.TRANSFORMS.getPreferredName(), transformsStateAndStats); builder.endObject(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformAction.java index c5820e7ea694..a9e9538288f8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformAction.java @@ -46,7 +46,7 @@ public Request(String id) { this.id = ExceptionsHelper.requireNonNull(id, DataFrameField.ID.getPreferredName()); } - public Request() { + private Request() { } public Request(StreamInput in) throws IOException { @@ -108,7 +108,7 @@ public Response() { } public Response(StreamInput in) throws IOException { - super(Collections.emptyList(), Collections.emptyList()); + super(in); readFrom(in); } @@ -136,6 +136,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + toXContentCommon(builder, params); builder.field("started", started); builder.endObject(); return builder; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformAction.java index 7a4317a85654..250442b69379 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformAction.java @@ -56,7 +56,7 @@ public Request(String id, boolean waitForCompletion, @Nullable TimeValue timeout this.setTimeout(timeout == null ? DEFAULT_TIMEOUT : timeout); } - public Request() { + private Request() { this(null, false, null); } @@ -149,7 +149,7 @@ public Response() { } public Response(StreamInput in) throws IOException { - super(Collections.emptyList(), Collections.emptyList()); + super(in); readFrom(in); } @@ -177,6 +177,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + toXContentCommon(builder, params); builder.field("stopped", stopped); builder.endObject(); return builder; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/AbstractWireSerializingDataFrameTestCase.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/AbstractWireSerializingDataFrameTestCase.java new file mode 100644 index 000000000000..e092bbbb768d --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/AbstractWireSerializingDataFrameTestCase.java @@ -0,0 +1,44 @@ +/* + * 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.core.dataframe.action; + +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.search.SearchModule; +import org.elasticsearch.test.AbstractWireSerializingTestCase; +import org.junit.Before; + +import static java.util.Collections.emptyList; + +public abstract class AbstractWireSerializingDataFrameTestCase extends AbstractWireSerializingTestCase { + /** + * Test case that ensures aggregation named objects are registered + */ + private NamedWriteableRegistry namedWriteableRegistry; + private NamedXContentRegistry namedXContentRegistry; + + @Before + public void registerAggregationNamedObjects() throws Exception { + // register aggregations as NamedWriteable + SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList()); + + namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables()); + namedXContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents()); + } + + @Override + protected NamedWriteableRegistry getNamedWriteableRegistry() { + return namedWriteableRegistry; + } + + @Override + protected NamedXContentRegistry xContentRegistry() { + return namedXContentRegistry; + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformActionResponseTests.java new file mode 100644 index 000000000000..54501fde5cfe --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/DeleteDataFrameTransformActionResponseTests.java @@ -0,0 +1,22 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.xpack.core.dataframe.action.DeleteDataFrameTransformAction.Response; + +public class DeleteDataFrameTransformActionResponseTests extends AbstractWireSerializingDataFrameTestCase { + @Override + protected Response createTestInstance() { + return new Response(randomBoolean()); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsActionResponseTests.java index 5f1c2c84d374..516b79159167 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsActionResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsActionResponseTests.java @@ -6,23 +6,23 @@ package org.elasticsearch.xpack.core.dataframe.action; +import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.XContentMapValues; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.watcher.watch.Payload.XContent; import org.elasticsearch.xpack.core.dataframe.action.GetDataFrameTransformsAction.Response; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfig; import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformConfigTests; +import org.elasticsearch.xpack.core.watcher.watch.Payload.XContent; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -public class GetDataFrameTransformsActionResponseTests extends ESTestCase { +public class GetDataFrameTransformsActionResponseTests extends AbstractWireSerializingDataFrameTestCase { public void testInvalidTransforms() throws IOException { List transforms = new ArrayList<>(); @@ -66,4 +66,19 @@ public void testNoHeaderInResponse() throws IOException { assertEquals(null, XContentMapValues.extractValue("headers", transformsResponse.get(i))); } } + + @Override + protected Response createTestInstance() { + List configs = new ArrayList<>(); + for (int i = 0; i < randomInt(10); ++i) { + configs.add(DataFrameTransformConfigTests.randomDataFrameTransformConfig()); + } + + return new Response(configs); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsActionResponseTests.java new file mode 100644 index 000000000000..4a293f42bb30 --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/GetDataFrameTransformsStatsActionResponseTests.java @@ -0,0 +1,32 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.xpack.core.dataframe.action.GetDataFrameTransformsStatsAction.Response; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStats; +import org.elasticsearch.xpack.core.dataframe.transforms.DataFrameTransformStateAndStatsTests; + +import java.util.ArrayList; +import java.util.List; + +public class GetDataFrameTransformsStatsActionResponseTests extends AbstractWireSerializingDataFrameTestCase { + @Override + protected Response createTestInstance() { + List stats = new ArrayList<>(); + for (int i = 0; i < randomInt(10); ++i) { + stats.add(DataFrameTransformStateAndStatsTests.randomDataFrameTransformStateAndStats()); + } + + return new Response(stats); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PreviewDataFrameTransformsActionResponseWireTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PreviewDataFrameTransformsActionResponseWireTests.java new file mode 100644 index 000000000000..df4fe1c14b9e --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PreviewDataFrameTransformsActionResponseWireTests.java @@ -0,0 +1,38 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.xpack.core.dataframe.action.PreviewDataFrameTransformAction.Response; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PreviewDataFrameTransformsActionResponseWireTests extends AbstractWireSerializingDataFrameTestCase { + + @Override + protected Response createTestInstance() { + int size = randomIntBetween(0, 10); + List> data = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + Map datum = new HashMap<>(); + Map entry = new HashMap<>(); + entry.put("value1", randomIntBetween(1, 100)); + datum.put(randomAlphaOfLength(10), entry); + data.add(datum); + } + return new Response(data); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } + +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PutDataFrameTransformActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PutDataFrameTransformActionResponseTests.java new file mode 100644 index 000000000000..d16b8fbf168f --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/PutDataFrameTransformActionResponseTests.java @@ -0,0 +1,24 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.xpack.core.dataframe.action.PutDataFrameTransformAction.Response; + +public class PutDataFrameTransformActionResponseTests extends AbstractStreamableTestCase { + + @Override + protected Response createBlankInstance() { + return new Response(); + } + + @Override + protected Response createTestInstance() { + return new Response(randomBoolean()); + } + +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionRequestTests.java similarity index 87% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionRequestTests.java index c54d795a5e4c..976db70c45f4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionRequestTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.core.dataframe.action.StartDataFrameTransformAction.Request; -public class StartDataFrameTransformActionTests extends AbstractWireSerializingTestCase { +public class StartDataFrameTransformActionRequestTests extends AbstractWireSerializingTestCase { @Override protected Request createTestInstance() { return new Request(randomAlphaOfLengthBetween(1, 20)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionResponseTests.java new file mode 100644 index 000000000000..d2cd377ffba0 --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StartDataFrameTransformActionResponseTests.java @@ -0,0 +1,24 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.xpack.core.dataframe.action.StartDataFrameTransformAction.Response; + +public class StartDataFrameTransformActionResponseTests extends AbstractWireSerializingDataFrameTestCase { + + @Override + protected Response createTestInstance() { + return new Response(randomBoolean()); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } + +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformActionResponseTests.java new file mode 100644 index 000000000000..afd5b6fa2dbc --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/dataframe/action/StopDataFrameTransformActionResponseTests.java @@ -0,0 +1,24 @@ +/* + * 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.core.dataframe.action; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.xpack.core.dataframe.action.StopDataFrameTransformAction.Response; + +public class StopDataFrameTransformActionResponseTests extends AbstractWireSerializingDataFrameTestCase { + + @Override + protected Response createTestInstance() { + return new Response(randomBoolean()); + } + + @Override + protected Reader instanceReader() { + return Response::new; + } + +}