Apply default timeout in StopDataFrameAnalyticsAction.Request (#55512) (#55517)

This commit is contained in:
Przemysław Witek 2020-04-21 13:05:48 +02:00 committed by GitHub
parent 9d05913c8a
commit 59d377462f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 2 deletions

View File

@ -36,12 +36,15 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
public class StartDataFrameAnalyticsAction extends ActionType<AcknowledgedResponse> { public class StartDataFrameAnalyticsAction extends ActionType<AcknowledgedResponse> {
public static final StartDataFrameAnalyticsAction INSTANCE = new StartDataFrameAnalyticsAction(); public static final StartDataFrameAnalyticsAction INSTANCE = new StartDataFrameAnalyticsAction();
public static final String NAME = "cluster:admin/xpack/ml/data_frame/analytics/start"; 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() { private StartDataFrameAnalyticsAction() {
super(NAME, AcknowledgedResponse::new); super(NAME, AcknowledgedResponse::new);
} }
@ -69,7 +72,7 @@ public class StartDataFrameAnalyticsAction extends ActionType<AcknowledgedRespon
} }
private String id; private String id;
private TimeValue timeout = TimeValue.timeValueSeconds(20); private TimeValue timeout = DEFAULT_TIMEOUT;
public Request(String id) { public Request(String id) {
setId(id); setId(id);

View File

@ -33,12 +33,15 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
public class StopDataFrameAnalyticsAction extends ActionType<StopDataFrameAnalyticsAction.Response> { public class StopDataFrameAnalyticsAction extends ActionType<StopDataFrameAnalyticsAction.Response> {
public static final StopDataFrameAnalyticsAction INSTANCE = new StopDataFrameAnalyticsAction(); public static final StopDataFrameAnalyticsAction INSTANCE = new StopDataFrameAnalyticsAction();
public static final String NAME = "cluster:admin/xpack/ml/data_frame/analytics/stop"; 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() { private StopDataFrameAnalyticsAction() {
super(NAME, StopDataFrameAnalyticsAction.Response::new); super(NAME, StopDataFrameAnalyticsAction.Response::new);
} }
@ -75,6 +78,7 @@ public class StopDataFrameAnalyticsAction extends ActionType<StopDataFrameAnalyt
private Set<String> expandedIds = Collections.emptySet(); private Set<String> expandedIds = Collections.emptySet();
public Request(String id) { public Request(String id) {
this();
setId(id); setId(id);
} }
@ -86,7 +90,9 @@ public class StopDataFrameAnalyticsAction extends ActionType<StopDataFrameAnalyt
expandedIds = new HashSet<>(Arrays.asList(in.readStringArray())); expandedIds = new HashSet<>(Arrays.asList(in.readStringArray()));
} }
public Request() {} public Request() {
setTimeout(DEFAULT_TIMEOUT);
}
public final void setId(String id) { public final void setId(String id) {
this.id = ExceptionsHelper.requireNonNull(id, DataFrameAnalyticsConfig.ID); this.id = ExceptionsHelper.requireNonNull(id, DataFrameAnalyticsConfig.ID);

View File

@ -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<Request> {
@Override
protected Request createTestInstance() {
Request request = new Request(randomAlphaOfLength(10));
request.setForce(randomBoolean());
return request;
}
@Override
protected Writeable.Reader<Request> instanceReader() {
return Request::new;
}
public void testDefaultTimeout() {
assertThat(createTestInstance().timeout(), is(notNullValue()));
}
}

View File

@ -109,4 +109,8 @@ public class PutDataFrameAnalyticsActionRequestTests extends AbstractSerializing
assertThat(e, is(nullValue())); assertThat(e, is(nullValue()));
} }
public void testDefaultTimeout() {
assertThat(createTestInstance().timeout(), is(notNullValue()));
}
} }

View File

@ -7,9 +7,16 @@ package org.elasticsearch.xpack.core.ml.action;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.TimeValue; 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.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction.Request; 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<Request> { public class StartDataFrameAnalyticsRequestTests extends AbstractWireSerializingTestCase<Request> {
@Override @Override
@ -25,4 +32,15 @@ public class StartDataFrameAnalyticsRequestTests extends AbstractWireSerializing
protected Writeable.Reader<Request> instanceReader() { protected Writeable.Reader<Request> instanceReader() {
return Request::new; 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()));
}
}
} }

View File

@ -7,12 +7,18 @@ package org.elasticsearch.xpack.core.ml.action;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.TimeValue; 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.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.ml.action.StopDataFrameAnalyticsAction.Request; import org.elasticsearch.xpack.core.ml.action.StopDataFrameAnalyticsAction.Request;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
public class StopDataFrameAnalyticsRequestTests extends AbstractWireSerializingTestCase<Request> { public class StopDataFrameAnalyticsRequestTests extends AbstractWireSerializingTestCase<Request> {
@Override @Override
@ -40,4 +46,15 @@ public class StopDataFrameAnalyticsRequestTests extends AbstractWireSerializingT
protected Writeable.Reader<Request> instanceReader() { protected Writeable.Reader<Request> instanceReader() {
return Request::new; 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()));
}
}
} }