From 3bd23735456107cf6541022680f56f95b42f69a2 Mon Sep 17 00:00:00 2001
From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com>
Date: Thu, 1 Feb 2024 12:06:59 +0100
Subject: [PATCH 1/4] Add tests for inference response deserialization
---
build.gradle.kts | 1 +
.../bakdata/kserve/predictv2/Parameters.java | 4 +-
.../predictv2/InferenceResponseTest.java | 62 +++++++++++++++++++
.../parameters_empty.json | 19 ++++++
.../parameters_null.json | 19 ++++++
5 files changed, 103 insertions(+), 2 deletions(-)
create mode 100644 src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
create mode 100644 src/test/resources/json_inference_responses/parameters_empty.json
create mode 100644 src/test/resources/json_inference_responses/parameters_null.json
diff --git a/build.gradle.kts b/build.gradle.kts
index 41f5bc9..853aa0e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -37,6 +37,7 @@ dependencies {
val junitVersion: String by project
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = junitVersion)
+ testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-params", version = junitVersion)
testRuntimeOnly(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = junitVersion)
testImplementation(group = "org.assertj", name = "assertj-core", version = "3.25.1")
testImplementation(group = "com.squareup.okhttp3", name = "mockwebserver", version = okHttpVersion)
diff --git a/src/main/java/com/bakdata/kserve/predictv2/Parameters.java b/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
index c1f2b39..112c5b6 100644
--- a/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
+++ b/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
@@ -28,8 +28,8 @@
import lombok.Data;
/**
- * A class to represent
- * parameters as defined in the v2 prediction protocol.
+ * A class to represent parameters as
+ * defined in the v2 prediction protocol.
*/
@Data
@Builder
diff --git a/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java b/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
new file mode 100644
index 0000000..47ffe1a
--- /dev/null
+++ b/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.objectMapper.readValue(jsonInferenceResponse, InferenceResponse.class);
+ }
+}
diff --git a/src/test/resources/json_inference_responses/parameters_empty.json b/src/test/resources/json_inference_responses/parameters_empty.json
new file mode 100644
index 0000000..7180f5b
--- /dev/null
+++ b/src/test/resources/json_inference_responses/parameters_empty.json
@@ -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"
+ }
+ }
+ ]
+}
diff --git a/src/test/resources/json_inference_responses/parameters_null.json b/src/test/resources/json_inference_responses/parameters_null.json
new file mode 100644
index 0000000..96639c6
--- /dev/null
+++ b/src/test/resources/json_inference_responses/parameters_null.json
@@ -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"
+ }
+ }
+ ]
+}
From 2ccf739e72b3557e0f107052a3cb9b4233b549a5 Mon Sep 17 00:00:00 2001
From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com>
Date: Thu, 1 Feb 2024 14:30:53 +0100
Subject: [PATCH 2/4] Allow deserialization of empty parameters field
---
src/main/java/com/bakdata/kserve/predictv2/Parameters.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/bakdata/kserve/predictv2/Parameters.java b/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
index 112c5b6..e53d8d4 100644
--- a/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
+++ b/src/main/java/com/bakdata/kserve/predictv2/Parameters.java
@@ -1,7 +1,7 @@
/*
* MIT License
*
- * Copyright (c) 2022 bakdata
+ * 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
@@ -24,8 +24,10 @@
package com.bakdata.kserve.predictv2;
+import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
+import lombok.NoArgsConstructor;
/**
* A class to represent parameters as
@@ -33,6 +35,8 @@
*/
@Data
@Builder
+@NoArgsConstructor
+@AllArgsConstructor
public class Parameters {
private String contentType;
private Object extra;
From 7c9d8f79d47b8a7e8d32ec07a439c85330010651 Mon Sep 17 00:00:00 2001
From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com>
Date: Thu, 1 Feb 2024 15:27:52 +0100
Subject: [PATCH 3/4] Upload snapshot
---
azure-pipelines.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 48cd11a..4cdef85 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -15,6 +15,8 @@ resources:
- repository: templates
type: github
name: bakdata/bakdata-project-templates
+ # TODO:
+ ref: tmp/upload-snapshot
endpoint: bot
jobs:
From 61dc2cd0fb0d66003e6d6b8f5cc17161148d21d1 Mon Sep 17 00:00:00 2001
From: Jakob Edding <15202881+JakobEdding@users.noreply.github.com>
Date: Wed, 7 Feb 2024 14:56:27 +0100
Subject: [PATCH 4/4] Add assertion for deserializing various parameter objects
without throw
---
.../com/bakdata/kserve/predictv2/InferenceResponseTest.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java b/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
index 47ffe1a..22a7200 100644
--- a/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
+++ b/src/test/java/com/bakdata/kserve/predictv2/InferenceResponseTest.java
@@ -57,6 +57,8 @@ void shouldDeserialize(String jsonFilePath) throws IOException {
byte[] resourceFileBytes = getClass().getClassLoader().getResourceAsStream(jsonFilePath).readAllBytes();
String jsonInferenceResponse = new String(resourceFileBytes);
- this.objectMapper.readValue(jsonInferenceResponse, InferenceResponse.class);
+ this.softly.assertThatCode(() -> {
+ this.objectMapper.readValue(jsonInferenceResponse, InferenceResponse.class);
+ }).doesNotThrowAnyException();
}
}