Skip to content

Commit 4a9093d

Browse files
authored
[ML] Fix serialising the Inference API update request (#122278) (#122301)
1 parent 47f4971 commit 4a9093d

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

docs/changelog/122278.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 122278
2+
summary: Fix serialising the inference update request
3+
area: Machine Learning
4+
type: bug
5+
issues: []

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/UpdateInferenceModelAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public Request(String inferenceEntityId, BytesReference content, XContentType co
7070
public Request(StreamInput in) throws IOException {
7171
super(in);
7272
this.inferenceEntityId = in.readString();
73-
this.content = in.readBytesReference();
7473
this.taskType = TaskType.fromStream(in);
74+
this.content = in.readBytesReference();
7575
this.contentType = in.readEnum(XContentType.class);
7676
}
7777

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.action;
9+
10+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11+
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.inference.TaskType;
13+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
14+
import org.elasticsearch.xcontent.XContentType;
15+
import org.elasticsearch.xpack.core.inference.action.UpdateInferenceModelAction;
16+
import org.elasticsearch.xpack.inference.InferenceNamedWriteablesProvider;
17+
18+
import java.io.IOException;
19+
20+
public class UpdateInferenceModelActionRequestTests extends AbstractWireSerializingTestCase<UpdateInferenceModelAction.Request> {
21+
22+
@Override
23+
protected Writeable.Reader<UpdateInferenceModelAction.Request> instanceReader() {
24+
return UpdateInferenceModelAction.Request::new;
25+
}
26+
27+
@Override
28+
protected UpdateInferenceModelAction.Request createTestInstance() {
29+
return new UpdateInferenceModelAction.Request(
30+
randomAlphaOfLength(5),
31+
randomBytesReference(50),
32+
randomFrom(XContentType.values()),
33+
randomFrom(TaskType.values()),
34+
randomTimeValue()
35+
);
36+
}
37+
38+
@Override
39+
protected UpdateInferenceModelAction.Request mutateInstance(UpdateInferenceModelAction.Request instance) throws IOException {
40+
return randomValueOtherThan(instance, this::createTestInstance);
41+
}
42+
43+
@Override
44+
protected NamedWriteableRegistry getNamedWriteableRegistry() {
45+
return new NamedWriteableRegistry(InferenceNamedWriteablesProvider.getNamedWriteables());
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference.action;
9+
10+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11+
import org.elasticsearch.common.io.stream.Writeable;
12+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
13+
import org.elasticsearch.xpack.core.inference.action.UpdateInferenceModelAction;
14+
import org.elasticsearch.xpack.inference.InferenceNamedWriteablesProvider;
15+
import org.elasticsearch.xpack.inference.ModelConfigurationsTests;
16+
17+
import java.io.IOException;
18+
19+
public class UpdateInferenceModelActionResponseTests extends AbstractWireSerializingTestCase<UpdateInferenceModelAction.Response> {
20+
@Override
21+
protected Writeable.Reader<UpdateInferenceModelAction.Response> instanceReader() {
22+
return UpdateInferenceModelAction.Response::new;
23+
}
24+
25+
@Override
26+
protected UpdateInferenceModelAction.Response createTestInstance() {
27+
return new UpdateInferenceModelAction.Response(ModelConfigurationsTests.createRandomInstance());
28+
}
29+
30+
@Override
31+
protected UpdateInferenceModelAction.Response mutateInstance(UpdateInferenceModelAction.Response instance) throws IOException {
32+
return randomValueOtherThan(instance, this::createTestInstance);
33+
}
34+
35+
@Override
36+
protected NamedWriteableRegistry getNamedWriteableRegistry() {
37+
return new NamedWriteableRegistry(InferenceNamedWriteablesProvider.getNamedWriteables());
38+
}
39+
}

0 commit comments

Comments
 (0)