-
Notifications
You must be signed in to change notification settings - Fork 300
Fix NPE when Vertex AI listSessions omits sessions #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentMap; | ||
| import okhttp3.MediaType; | ||
| import okhttp3.ResponseBody; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
@@ -37,6 +39,20 @@ | |
| public class VertexAiSessionServiceTest { | ||
|
|
||
| private static final ObjectMapper mapper = JsonBaseModel.getMapper(); | ||
| private static final MediaType JSON_MEDIA_TYPE = | ||
| MediaType.parse("application/json; charset=utf-8"); | ||
|
|
||
| private static ApiResponse apiResponseJson(String json) { | ||
| return new ApiResponse() { | ||
| @Override | ||
| public ResponseBody getResponseBody() { | ||
| return ResponseBody.create(JSON_MEDIA_TYPE, json); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() {} | ||
| }; | ||
| } | ||
|
|
||
| private static final String MOCK_SESSION_STRING_1 = | ||
| """ | ||
|
|
@@ -319,6 +335,24 @@ public void listSessions_empty() { | |
| .isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void listSessions_missingSessionsField_returnsEmpty() { | ||
| when(mockApiClient.request("GET", "reasoningEngines/123/sessions?filter=user_id=userX", "")) | ||
| .thenReturn(apiResponseJson("{}")); | ||
|
|
||
| assertThat(vertexAiSessionService.listSessions("123", "userX").blockingGet().sessions()) | ||
| .isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void listSessions_nullSessionsField_returnsEmpty() { | ||
| when(mockApiClient.request("GET", "reasoningEngines/123/sessions?filter=user_id=userY", "")) | ||
| .thenReturn(apiResponseJson("{\"sessions\": null}")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about updating this to something like: This way we could avoid importing a new lib (and using a non-trivial, realistic media type to mock ApiResponse) for the purpose of those tests |
||
|
|
||
| assertThat(vertexAiSessionService.listSessions("123", "userY").blockingGet().sessions()) | ||
| .isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| public void listEvents_empty() { | ||
| assertThat(vertexAiSessionService.listEvents("789", "user1", "3").blockingGet().events()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
builder()already initializes the session with an empty list so we can probably skip this here and in line 138.