Skip to content

Add SSE support to MockClient#573

Open
codingkiddo wants to merge 1 commit into
Kong:mainfrom
codingkiddo:add-mockclient-sse-support
Open

Add SSE support to MockClient#573
codingkiddo wants to merge 1 commit into
Kong:mainfrom
codingkiddo:add-mockclient-sse-support

Conversation

@codingkiddo

Copy link
Copy Markdown
Contributor

Summary

Adds basic Server-Sent Events support to MockClient.

Motivation

MockClient previously did not support SSE requests. The SSE methods returned null or an empty stream, so Unirest.sse(...).connect(...) could not be tested with mock expectations.

Fixes #570.

Changes

  • Treats mocked SSE requests as GET requests for expectation matching.
  • Supports SSE responses through the existing expect(...).thenReturn(...) API.
  • Parses text/event-stream response bodies into Event objects.
  • Supports both stream-based and handler-based SSE consumption.
  • Adds regression coverage for mocked SSE events.

Testing

mvn -pl unirest-modules-mocks -am test

@ryber ryber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I think we want to do a few things here:

  1. Its not obvious from the outside that Unrest::sseends up doing a GET on the URL, so I expect the MockClient to have a method that explicitly is for SSE. It's fine if internally it sets up the GET, but from the outside the MockClient should have the same convenience as the real client.

  2. Users should not be expected to understand the raw formal of SSE streams. They should not expect to set delimitation or other formatting things about SSE. So the .thenReturns should accept an object or list of objects that define objects and the bodies.

Something like (and this is sudo code). In this example "EventStream" is an object that the user can feed more events to and it will stream out. I would look at how WebSockets are done. I would expect something similar.:

    client.expectSSE("http://events")
              .thenReturn(EventStream.of(
                   new Event("greeting", "hello"),
                   new Event("greeting", "world")
               ));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for SSE in the MockClient

2 participants