-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow non-null but empty Parameters object in inference response (#11)
So far, kserve-client can only deserialize `parameters: null` or a `parameters: { ... }` object (with all its fields filled) from an inference response. However, some KServe InferenceServices return `parameters: {}` as part of an inference response. This case should also be accepted as a valid response.
- Loading branch information
1 parent
e6b19b5
commit f602a96
Showing
5 changed files
with
110 additions
and
3 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
64 changes: 64 additions & 0 deletions
64
src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.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,64 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 bakdata GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.bakdata.kserve.predictv2; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import java.io.IOException; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; | ||
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
@ExtendWith(SoftAssertionsExtension.class) | ||
public class InferenceResponseTest { | ||
private ObjectMapper objectMapper; | ||
|
||
@InjectSoftAssertions | ||
private SoftAssertions softly; | ||
|
||
@BeforeEach | ||
void setUpObjectMapper() { | ||
this.objectMapper = new ObjectMapper() | ||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"json_inference_responses/parameters_null.json", | ||
"json_inference_responses/parameters_empty.json" | ||
}) | ||
void shouldDeserialize(String jsonFilePath) throws IOException { | ||
byte[] resourceFileBytes = getClass().getClassLoader().getResourceAsStream(jsonFilePath).readAllBytes(); | ||
String jsonInferenceResponse = new String(resourceFileBytes); | ||
|
||
this.softly.assertThatCode(() -> { | ||
this.objectMapper.readValue(jsonInferenceResponse, InferenceResponse.class); | ||
}).doesNotThrowAnyException(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/resources/json_inference_responses/parameters_empty.json
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,19 @@ | ||
{ | ||
"model_name": "fake-model-name", | ||
"model_version": "1.0.0", | ||
"id": "d26ad6e7-0cd7-4f37-b463-0409d9246b43", | ||
"parameters": {}, | ||
"outputs": [ | ||
{ | ||
"name": "fake-output-name", | ||
"shape": [ | ||
1 | ||
], | ||
"datatype": "object", | ||
"parameters": null, | ||
"data": { | ||
"output": "fake output" | ||
} | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/resources/json_inference_responses/parameters_null.json
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,19 @@ | ||
{ | ||
"model_name": "fake-model-name", | ||
"model_version": "1.0.0", | ||
"id": "d26ad6e7-0cd7-4f37-b463-0409d9246b43", | ||
"parameters": null, | ||
"outputs": [ | ||
{ | ||
"name": "fake-output-name", | ||
"shape": [ | ||
1 | ||
], | ||
"datatype": "object", | ||
"parameters": null, | ||
"data": { | ||
"output": "fake output" | ||
} | ||
} | ||
] | ||
} |