[7.x] Fix serialization of evaluation response. (#47557) (#47566)

This commit is contained in:
Przemysław Witek 2019-10-04 15:12:18 +02:00 committed by GitHub
parent c1be7a802c
commit 8c180a77f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -217,7 +217,7 @@ public class EvaluateDataFrameAction extends ActionType<EvaluateDataFrameAction.
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(evaluationName);
out.writeList(metrics);
out.writeNamedWriteableList(metrics);
}
@Override

View File

@ -0,0 +1,42 @@
/*
* 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.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.ml.action.EvaluateDataFrameAction.Response;
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.EvaluationMetricResult;
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.MlEvaluationNamedXContentProvider;
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.regression.MeanSquaredError;
import org.elasticsearch.xpack.core.ml.dataframe.evaluation.regression.RSquared;
import java.util.Arrays;
import java.util.List;
public class EvaluateDataFrameActionResponseTests extends AbstractWireSerializingTestCase<Response> {
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(new MlEvaluationNamedXContentProvider().getNamedWriteables());
}
@Override
protected Response createTestInstance() {
String evaluationName = randomAlphaOfLength(10);
List<EvaluationMetricResult> metrics =
Arrays.asList(
new MeanSquaredError.Result(randomDouble()),
new RSquared.Result(randomDouble()));
int numMetrics = randomIntBetween(0, metrics.size());
return new Response(evaluationName, metrics.subList(0, numMetrics));
}
@Override
protected Writeable.Reader<Response> instanceReader() {
return Response::new;
}
}