Skip to content

Commit 1386a4f

Browse files
committed
feat: update comm
1 parent ce4767c commit 1386a4f

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/main/java/dev/openfga/sdk/api/BaseStreamingApi.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import java.util.stream.Stream;
3030

3131
/**
32-
* Base class for handling streaming API responses using NDJSON format.
32+
* Base class for handling streaming API responses.
3333
* This class provides generic streaming functionality that can be reused across
34-
* different streaming endpoints by handling the common NDJSON parsing and error handling logic.
34+
* different streaming endpoints by handling the common streaming parsing and error handling logic.
3535
*
3636
* @param <T> The type of response objects in the stream
3737
*/
@@ -57,7 +57,7 @@ protected BaseStreamingApi(
5757
}
5858

5959
/**
60-
* Process a streaming NDJSON response asynchronously.
60+
* Process a streaming response asynchronously.
6161
* Each line in the response is parsed and delivered to the consumer callback.
6262
*
6363
* @param request The HTTP request to execute
@@ -69,7 +69,7 @@ protected CompletableFuture<Void> processStreamingResponse(
6969
HttpRequest request, Consumer<T> consumer, Consumer<Throwable> errorConsumer) {
7070

7171
// Use async HTTP client with streaming body handler
72-
// ofLines() provides line-by-line streaming which is perfect for NDJSON
72+
// ofLines() provides line-by-line streaming
7373
return apiClient
7474
.getHttpClient()
7575
.sendAsync(request, HttpResponse.BodyHandlers.ofLines())
@@ -117,7 +117,7 @@ protected CompletableFuture<Void> processStreamingResponse(
117117
}
118118

119119
/**
120-
* Process a single line from the NDJSON stream
120+
* Process a single line from the stream
121121
*
122122
* @param line The JSON line to process
123123
* @param consumer Callback to handle the parsed result

src/main/java/dev/openfga/sdk/api/model/StreamResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/**
2121
* Generic wrapper for streaming results that can contain either a result or an error.
22-
* This class is used to deserialize NDJSON streaming responses where each line may contain
22+
* This class is used to deserialize streaming responses where each line may contain
2323
* either a successful result or an error status.
2424
*
2525
* @param <T> The type of the result object

src/test/java/dev/openfga/sdk/api/StreamingApiTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Test class demonstrating the generic streaming implementation.
3131
* This test shows how the BaseStreamingApi provides reusable functionality
32-
* for any streaming endpoint that returns NDJSON format.
32+
* for any streaming endpoint that returns line-delimited JSON format.
3333
*/
3434
class StreamingApiTest {
3535

@@ -66,12 +66,12 @@ void setUp() {
6666

6767
@Test
6868
void testStreamedListObjects_successfulStream() throws Exception {
69-
// Arrange: Create NDJSON response with multiple objects
70-
String ndjsonResponse = "{\"result\":{\"object\":\"document:1\"}}\n"
69+
// Arrange: Create response with multiple objects
70+
String Response = "{\"result\":{\"object\":\"document:1\"}}\n"
7171
+ "{\"result\":{\"object\":\"document:2\"}}\n"
7272
+ "{\"result\":{\"object\":\"document:3\"}}\n";
7373

74-
Stream<String> lineStream = ndjsonResponse.lines();
74+
Stream<String> lineStream = Response.lines();
7575
when(mockHttpResponse.body()).thenReturn(lineStream);
7676
when(mockHttpResponse.statusCode()).thenReturn(200);
7777

@@ -102,11 +102,11 @@ void testStreamedListObjects_successfulStream() throws Exception {
102102

103103
@Test
104104
void testStreamedListObjects_withErrorInStream() throws Exception {
105-
// Arrange: NDJSON with an error
106-
String ndjsonResponse = "{\"result\":{\"object\":\"document:1\"}}\n"
105+
// Arrange: Streaming response with an error
106+
String Response = "{\"result\":{\"object\":\"document:1\"}}\n"
107107
+ "{\"error\":{\"code\":400,\"message\":\"Something went wrong\"}}\n";
108108

109-
Stream<String> lineStream = ndjsonResponse.lines();
109+
Stream<String> lineStream = Response.lines();
110110
when(mockHttpResponse.body()).thenReturn(lineStream);
111111
when(mockHttpResponse.statusCode()).thenReturn(200);
112112

@@ -168,10 +168,10 @@ void testStreamedListObjects_httpError() throws Exception {
168168

169169
@Test
170170
void testStreamedListObjects_emptyStream() throws Exception {
171-
// Arrange: Empty NDJSON response
172-
String ndjsonResponse = "";
171+
// Arrange: Empty streaming response
172+
String streamResponse = "";
173173

174-
Stream<String> lineStream = ndjsonResponse.lines();
174+
Stream<String> lineStream = streamResponse.lines();
175175
when(mockHttpResponse.body()).thenReturn(lineStream);
176176
when(mockHttpResponse.statusCode()).thenReturn(200);
177177

@@ -194,17 +194,17 @@ void testStreamedListObjects_emptyStream() throws Exception {
194194

195195
@Test
196196
void testStreamedListObjects_largeStream() throws Exception {
197-
// Arrange: Large NDJSON response with many objects
198-
StringBuilder ndjsonBuilder = new StringBuilder();
197+
// Arrange: Large streaming response with many objects
198+
StringBuilder streamBuilder = new StringBuilder();
199199
int objectCount = 1000;
200200
for (int i = 0; i < objectCount; i++) {
201-
ndjsonBuilder
201+
streamBuilder
202202
.append("{\"result\":{\"object\":\"document:")
203203
.append(i)
204204
.append("\"}}\n");
205205
}
206206

207-
Stream<String> lineStream = ndjsonBuilder.toString().lines();
207+
Stream<String> lineStream = streamBuilder.toString().lines();
208208
when(mockHttpResponse.body()).thenReturn(lineStream);
209209
when(mockHttpResponse.statusCode()).thenReturn(200);
210210

0 commit comments

Comments
 (0)