-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Unify Batch Map and Unary Map Operations Using a Shared gRPC Pr…
…otocol (#144)
- Loading branch information
Showing
7 changed files
with
201 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 21 additions & 19 deletions
40
src/test/java/io/numaproj/numaflow/batchmapper/BatchMapOutputStreamObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
package io.numaproj.numaflow.batchmapper; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import io.numaproj.numaflow.batchmap.v1.Batchmap; | ||
import lombok.extern.slf4j.Slf4j; | ||
import io.numaproj.numaflow.map.v1.MapOuterClass; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Slf4j | ||
public class BatchMapOutputStreamObserver implements StreamObserver<Batchmap.BatchMapResponse> { | ||
public AtomicReference<Boolean> completed = new AtomicReference<>(false); | ||
public AtomicReference<List<Batchmap.BatchMapResponse>> resultDatum = new AtomicReference<>( | ||
new ArrayList<>()); | ||
public Throwable t; | ||
public class BatchMapOutputStreamObserver implements StreamObserver<MapOuterClass.MapResponse> { | ||
List<MapOuterClass.MapResponse> mapResponses = new ArrayList<>(); | ||
CompletableFuture<Void> done = new CompletableFuture<>(); | ||
Integer responseCount; | ||
|
||
public BatchMapOutputStreamObserver(Integer responseCount) { | ||
this.responseCount = responseCount; | ||
} | ||
|
||
@Override | ||
public void onNext(Batchmap.BatchMapResponse batchMapResponse) { | ||
List<Batchmap.BatchMapResponse> receivedResponses = resultDatum.get(); | ||
receivedResponses.add(batchMapResponse); | ||
resultDatum.set(receivedResponses); | ||
log.info( | ||
"Received BatchMapResponse with id {} and message count {}", | ||
batchMapResponse.getId(), | ||
batchMapResponse.getResultsCount()); | ||
public void onNext(MapOuterClass.MapResponse mapResponse) { | ||
mapResponses.add(mapResponse); | ||
if (mapResponses.size() == responseCount) { | ||
done.complete(null); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
t = throwable; | ||
done.completeExceptionally(throwable); | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
this.completed.set(true); | ||
done.complete(null); | ||
} | ||
|
||
public List<MapOuterClass.MapResponse> getMapResponses() { | ||
return mapResponses; | ||
} | ||
} |
Oops, something went wrong.