diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java index 2a95065b470..0a976259956 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java @@ -36,12 +36,15 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.concurrent.TimeUnit; public class StartDataFrameAnalyticsAction extends ActionType { public static final StartDataFrameAnalyticsAction INSTANCE = new StartDataFrameAnalyticsAction(); public static final String NAME = "cluster:admin/xpack/ml/data_frame/analytics/start"; + public static final TimeValue DEFAULT_TIMEOUT = new TimeValue(20, TimeUnit.SECONDS); + private StartDataFrameAnalyticsAction() { super(NAME, AcknowledgedResponse::new); } @@ -69,7 +72,7 @@ public class StartDataFrameAnalyticsAction extends ActionType { public static final StopDataFrameAnalyticsAction INSTANCE = new StopDataFrameAnalyticsAction(); public static final String NAME = "cluster:admin/xpack/ml/data_frame/analytics/stop"; + public static final TimeValue DEFAULT_TIMEOUT = new TimeValue(30, TimeUnit.SECONDS); + private StopDataFrameAnalyticsAction() { super(NAME, StopDataFrameAnalyticsAction.Response::new); } @@ -75,6 +78,7 @@ public class StopDataFrameAnalyticsAction extends ActionType expandedIds = Collections.emptySet(); public Request(String id) { + this(); setId(id); } @@ -86,7 +90,9 @@ public class StopDataFrameAnalyticsAction extends ActionType(Arrays.asList(in.readStringArray())); } - public Request() {} + public Request() { + setTimeout(DEFAULT_TIMEOUT); + } public final void setId(String id) { this.id = ExceptionsHelper.requireNonNull(id, DataFrameAnalyticsConfig.ID); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDataFrameAnalyticsActionRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDataFrameAnalyticsActionRequestTests.java new file mode 100644 index 00000000000..055b37e4dc3 --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DeleteDataFrameAnalyticsActionRequestTests.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.ml.action; + +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.test.AbstractWireSerializingTestCase; +import org.elasticsearch.xpack.core.ml.action.DeleteDataFrameAnalyticsAction.Request; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +public class DeleteDataFrameAnalyticsActionRequestTests extends AbstractWireSerializingTestCase { + + @Override + protected Request createTestInstance() { + Request request = new Request(randomAlphaOfLength(10)); + request.setForce(randomBoolean()); + return request; + } + + @Override + protected Writeable.Reader instanceReader() { + return Request::new; + } + + public void testDefaultTimeout() { + assertThat(createTestInstance().timeout(), is(notNullValue())); + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDataFrameAnalyticsActionRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDataFrameAnalyticsActionRequestTests.java index 6901b41bc5a..63bc77d4711 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDataFrameAnalyticsActionRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutDataFrameAnalyticsActionRequestTests.java @@ -109,4 +109,8 @@ public class PutDataFrameAnalyticsActionRequestTests extends AbstractSerializing assertThat(e, is(nullValue())); } + + public void testDefaultTimeout() { + assertThat(createTestInstance().timeout(), is(notNullValue())); + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsRequestTests.java index a3db5833b82..7fef1299da7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsRequestTests.java @@ -7,9 +7,16 @@ package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction.Request; +import java.io.IOException; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + public class StartDataFrameAnalyticsRequestTests extends AbstractWireSerializingTestCase { @Override @@ -25,4 +32,15 @@ public class StartDataFrameAnalyticsRequestTests extends AbstractWireSerializing protected Writeable.Reader instanceReader() { return Request::new; } + + public void testDefaultTimeout() throws IOException { + { + Request request = new Request("foo"); + assertThat(request.getTimeout(), is(notNullValue())); + } + try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{}")) { + Request request = Request.parseRequest("foo", parser); + assertThat(request.getTimeout(), is(notNullValue())); + } + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDataFrameAnalyticsRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDataFrameAnalyticsRequestTests.java index f2942905fad..2fdcebf7e86 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDataFrameAnalyticsRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/StopDataFrameAnalyticsRequestTests.java @@ -7,12 +7,18 @@ package org.elasticsearch.xpack.core.ml.action; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.core.ml.action.StopDataFrameAnalyticsAction.Request; +import java.io.IOException; import java.util.HashSet; import java.util.Set; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + public class StopDataFrameAnalyticsRequestTests extends AbstractWireSerializingTestCase { @Override @@ -40,4 +46,15 @@ public class StopDataFrameAnalyticsRequestTests extends AbstractWireSerializingT protected Writeable.Reader instanceReader() { return Request::new; } + + public void testDefaultTimeout() throws IOException { + { + Request request = new Request("foo"); + assertThat(request.getTimeout(), is(notNullValue())); + } + try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{}")) { + Request request = Request.parseRequest("foo", parser); + assertThat(request.getTimeout(), is(notNullValue())); + } + } }