Skip to content

Commit

Permalink
Adds test for GrpcHelper.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
  • Loading branch information
spericas committed Jun 17, 2024
1 parent 091c3a4 commit bbcbcf2
Show file tree
Hide file tree
Showing 4 changed files with 671 additions and 10 deletions.
9 changes: 3 additions & 6 deletions grpc/core/src/main/java/io/helidon/grpc/core/GrpcHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ public static io.helidon.http.Status toHttpResponseStatus(StatusRuntimeException
* @return the gRPC {@link Status} converted to a {@link io.helidon.http.Status}
*/
public static io.helidon.http.Status toHttpResponseStatus(Status status) {
io.helidon.http.Status httpStatus = switch (status.getCode()) {
return switch (status.getCode()) {
case OK -> io.helidon.http.Status.create(200, status.getDescription());
case INVALID_ARGUMENT -> io.helidon.http.Status.create(400, status.getDescription());
case INVALID_ARGUMENT, OUT_OF_RANGE -> io.helidon.http.Status.create(400, status.getDescription());
case DEADLINE_EXCEEDED -> io.helidon.http.Status.create(408, status.getDescription());
case NOT_FOUND -> io.helidon.http.Status.create(404, status.getDescription());
case ALREADY_EXISTS -> io.helidon.http.Status.create(412, status.getDescription());
case PERMISSION_DENIED -> io.helidon.http.Status.create(403, status.getDescription());
case FAILED_PRECONDITION -> io.helidon.http.Status.create(412, status.getDescription());
case OUT_OF_RANGE -> io.helidon.http.Status.create(400, status.getDescription());
case UNIMPLEMENTED -> io.helidon.http.Status.create(501, status.getDescription());
case UNAVAILABLE -> io.helidon.http.Status.create(503, status.getDescription());
case UNAUTHENTICATED -> io.helidon.http.Status.create(401, status.getDescription());
default -> io.helidon.http.Status.create(500, status.getDescription());
};
return httpStatus;
}

/**
Expand Down Expand Up @@ -147,8 +145,7 @@ public static Throwable ensureStatusException(Throwable thrown, Status status) {
public static StatusRuntimeException ensureStatusRuntimeException(Throwable thrown, Status status) {
if (thrown instanceof StatusRuntimeException) {
return (StatusRuntimeException) thrown;
} else if (thrown instanceof StatusException) {
StatusException ex = (StatusException) thrown;
} else if (thrown instanceof StatusException ex) {
return new StatusRuntimeException(ex.getStatus(), ex.getTrailers());
} else {
return status.withCause(thrown).asRuntimeException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ public static <T> Supplier<T> createSupplier(Callable<T> callable) {
* @param <U> the type of result expected by the {@link StreamObserver}
*/
private static class CompletionAction<T, U> implements BiConsumer<T, Throwable> {
private StreamObserver<U> observer;
private boolean sendResult;
private final StreamObserver<U> observer;
private final boolean sendResult;

CompletionAction(StreamObserver<U> observer, boolean sendResult) {
this.observer = observer;
Expand All @@ -438,7 +438,7 @@ public void accept(T result, Throwable error) {
* @param <T> the type of result returned from the callable
*/
private static class CallableSupplier<T> implements Supplier<T> {
private Callable<T> callable;
private final Callable<T> callable;

CallableSupplier(Callable<T> callable) {
this.callable = callable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static <T> StreamObserver<T> ensureSafeObserver(StreamObserver<T> observe
/**
* The actual StreamObserver.
*/
private StreamObserver<? super T> delegate;
private final StreamObserver<? super T> delegate;

/**
* Indicates a terminal state.
Expand Down
Loading

0 comments on commit bbcbcf2

Please sign in to comment.