-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: udsink bidirectional streaming #141
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 |
---|---|---|
|
@@ -113,11 +113,13 @@ public Client(String host, int port) { | |
* @return response from the server as a ResponseList | ||
*/ | ||
public ResponseList sendRequest(DatumIterator datumIterator) { | ||
CompletableFuture<SinkOuterClass.SinkResponse> future = new CompletableFuture<>(); | ||
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. just curious, as to why SinkerTestKit lives in this package? 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. this is for enabling users do "Component testing". |
||
List<SinkOuterClass.SinkResponse> responses = new ArrayList<>(); | ||
CompletableFuture<List<SinkOuterClass.SinkResponse>> future = new CompletableFuture<>(); | ||
|
||
StreamObserver<SinkOuterClass.SinkResponse> responseObserver = new StreamObserver<>() { | ||
@Override | ||
public void onNext(SinkOuterClass.SinkResponse response) { | ||
future.complete(response); | ||
responses.add(response); | ||
} | ||
|
||
@Override | ||
|
@@ -127,16 +129,19 @@ public void onError(Throwable t) { | |
|
||
@Override | ||
public void onCompleted() { | ||
if (!future.isDone()) { | ||
future.completeExceptionally(new RuntimeException( | ||
"Server completed without a response")); | ||
} | ||
future.complete(responses); | ||
} | ||
}; | ||
|
||
StreamObserver<SinkOuterClass.SinkRequest> requestObserver = sinkStub.sinkFn( | ||
responseObserver); | ||
|
||
// send handshake request | ||
requestObserver.onNext(SinkOuterClass.SinkRequest.newBuilder() | ||
.setHandshake(SinkOuterClass.Handshake.newBuilder().setSot(true).build()) | ||
.build()); | ||
|
||
// send actual requests | ||
while (true) { | ||
Datum datum = null; | ||
try { | ||
|
@@ -148,7 +153,8 @@ public void onCompleted() { | |
if (datum == null) { | ||
break; | ||
} | ||
SinkOuterClass.SinkRequest request = SinkOuterClass.SinkRequest.newBuilder() | ||
SinkOuterClass.SinkRequest.Request request = SinkOuterClass.SinkRequest.Request | ||
.newBuilder() | ||
.addAllKeys( | ||
datum.getKeys() | ||
== null ? new ArrayList<>() : List.of(datum.getKeys())) | ||
|
@@ -168,28 +174,39 @@ public void onCompleted() { | |
.putAllHeaders( | ||
datum.getHeaders() == null ? new HashMap<>() : datum.getHeaders()) | ||
.build(); | ||
requestObserver.onNext(request); | ||
requestObserver.onNext(SinkOuterClass.SinkRequest | ||
.newBuilder() | ||
.setRequest(request) | ||
.build()); | ||
} | ||
// send end of transmission message | ||
requestObserver.onNext(SinkOuterClass.SinkRequest.newBuilder().setStatus( | ||
SinkOuterClass.SinkRequest.Status.newBuilder().setEot(true)).build()); | ||
|
||
requestObserver.onCompleted(); | ||
|
||
SinkOuterClass.SinkResponse response; | ||
List<SinkOuterClass.SinkResponse> outputResponses; | ||
try { | ||
response = future.get(); | ||
outputResponses = future.get(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
ResponseList.ResponseListBuilder responseListBuilder = ResponseList.newBuilder(); | ||
for (SinkOuterClass.SinkResponse.Result result : response.getResultsList()) { | ||
if (result.getStatus() == SinkOuterClass.Status.SUCCESS) { | ||
responseListBuilder.addResponse(Response.responseOK(result.getId())); | ||
} else if (result.getStatus() == SinkOuterClass.Status.FALLBACK) { | ||
for (SinkOuterClass.SinkResponse result : outputResponses) { | ||
if (result.getHandshake().getSot()) { | ||
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. what does getSot do? 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. sot means start of the transmission. when set to true, it means the handshake is successful. |
||
continue; | ||
} | ||
if (result.getResult().getStatus() == SinkOuterClass.Status.SUCCESS) { | ||
responseListBuilder.addResponse(Response.responseOK(result | ||
.getResult() | ||
.getId())); | ||
} else if (result.getResult().getStatus() == SinkOuterClass.Status.FALLBACK) { | ||
responseListBuilder.addResponse(Response.responseFallback( | ||
result.getId())); | ||
result.getResult().getId())); | ||
} else { | ||
responseListBuilder.addResponse(Response.responseFailure( | ||
result.getId(), result.getErrMsg())); | ||
result.getResult().getId(), result.getResult().getErrMsg())); | ||
} | ||
} | ||
|
||
|
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.
In go sdk, we also set result status to success.
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.
we don't need to, I will change that in go sdk.