Skip to content

Commit

Permalink
Update grpc-java to 1.25.0 apple#877
Browse files Browse the repository at this point in the history
Motivation:

Update grpc-java to 1.25.0

Modifications:

added fallbackStatus to StatusSupplier

Result:

Fixes apple#877
  • Loading branch information
volyx committed Nov 27, 2019
1 parent 62cab87 commit f3161c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Expand Up @@ -201,8 +201,9 @@ private static GrpcStatusException extractGrpcExceptionFromHeaders(final HttpHea
if (statusCode != null) {
final GrpcStatusCode grpcStatusCode = GrpcStatusCode.fromCodeValue(statusCode);
if (grpcStatusCode.value() != GrpcStatusCode.OK.value()) {
return new GrpcStatus(grpcStatusCode, null, headers.get(GRPC_STATUS_MESSAGE_TRAILER))
.asException(new StatusSupplier(headers));
final GrpcStatus grpcStatus =
new GrpcStatus(grpcStatusCode, null, headers.get(GRPC_STATUS_MESSAGE_TRAILER));
return grpcStatus.asException(new StatusSupplier(headers, grpcStatus));
}
}
return null;
Expand Down Expand Up @@ -234,11 +235,13 @@ static <T> T uncheckedCast(Object o) {
private static final class StatusSupplier implements Supplier<Status> {

private final HttpHeaders headers;
private final GrpcStatus fallbackStatus;
@Nullable
private volatile StatusHolder statusHolder;

StatusSupplier(HttpHeaders headers) {
StatusSupplier(HttpHeaders headers, final GrpcStatus fallbackStatus) {
this.headers = headers;
this.fallbackStatus = fallbackStatus;
}

@Nullable
Expand All @@ -248,7 +251,16 @@ public Status get() {
if (statusHolder == null) {
// Cache the status (we don't bother caching any errors tho). Also its fine to only use a volatile here
// as at worse this will just update to the "same" status again.
this.statusHolder = statusHolder = new StatusHolder(getStatusDetails(headers));
final Status statusFromHeaders = getStatusDetails(headers);
if (statusFromHeaders == null) {
final Status.Builder builder = Status.newBuilder().setCode(fallbackStatus.code().value());
if (fallbackStatus.description() != null) {
builder.setMessage(fallbackStatus.description());
}
this.statusHolder = statusHolder = new StatusHolder(builder.build());
} else {
this.statusHolder = statusHolder = new StatusHolder(statusFromHeaders);
}
}
return statusHolder.status;
}
Expand Down
Expand Up @@ -95,7 +95,6 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

@RunWith(Theories.class)
Expand Down Expand Up @@ -542,11 +541,11 @@ private static void assertGrpcStatusException(final GrpcStatusException statusEx
final GrpcStatus grpcStatus = statusException.status();
assertEquals(CUSTOM_ERROR_MESSAGE, grpcStatus.description());
final com.google.rpc.Status status = statusException.applicationStatus();
assertNotNull(status);
if (withStatus) {
assertNotNull(status);
assertStatus(status, grpcStatus.code().value(), grpcStatus.description());
} else {
assertNull(status);
assertFallbackStatus(status, grpcStatus.code().value(), grpcStatus.description());
}
}

Expand Down

0 comments on commit f3161c2

Please sign in to comment.