-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leniently parse ml persistent task parameters (#33950)
- Loading branch information
Showing
6 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/DatafeedParamsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class DatafeedParamsTests extends AbstractSerializingTestCase<StartDatafeedAction.DatafeedParams> { | ||
@Override | ||
protected StartDatafeedAction.DatafeedParams doParseInstance(XContentParser parser) throws IOException { | ||
return StartDatafeedAction.DatafeedParams.parseRequest(null, parser); | ||
} | ||
|
||
public static StartDatafeedAction.DatafeedParams createDatafeedParams() { | ||
StartDatafeedAction.DatafeedParams params = | ||
new StartDatafeedAction.DatafeedParams(randomAlphaOfLength(10), randomNonNegativeLong()); | ||
if (randomBoolean()) { | ||
params.setEndTime(randomNonNegativeLong()); | ||
} | ||
if (randomBoolean()) { | ||
params.setTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); | ||
} | ||
return params; | ||
} | ||
|
||
@Override | ||
protected StartDatafeedAction.DatafeedParams createTestInstance() { | ||
return createDatafeedParams(); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<StartDatafeedAction.DatafeedParams> instanceReader() { | ||
return StartDatafeedAction.DatafeedParams::new; | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return true; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/JobParamsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class JobParamsTests extends AbstractSerializingTestCase<OpenJobAction.JobParams> { | ||
|
||
@Override | ||
protected OpenJobAction.JobParams doParseInstance(XContentParser parser) throws IOException { | ||
return OpenJobAction.JobParams.parseRequest(null, parser); | ||
} | ||
|
||
public static OpenJobAction.JobParams createJobParams() { | ||
OpenJobAction.JobParams params = new OpenJobAction.JobParams(randomAlphaOfLengthBetween(1, 20)); | ||
if (randomBoolean()) { | ||
params.setTimeout(TimeValue.timeValueMillis(randomNonNegativeLong())); | ||
} | ||
return params; | ||
} | ||
|
||
@Override | ||
protected OpenJobAction.JobParams createTestInstance() { | ||
return createJobParams(); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<OpenJobAction.JobParams> instanceReader() { | ||
return OpenJobAction.JobParams::new; | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters