Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public void clientCompressedUnary(boolean probe) throws Exception {
blockingStub.unaryCall(expectCompressedRequest);
fail("expected INVALID_ARGUMENT");
} catch (StatusRuntimeException e) {
assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatus().getCode());
assertCodeEquals(Status.Code.INVALID_ARGUMENT, e.getStatus());
}
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.INVALID_ARGUMENT);
}
Expand Down Expand Up @@ -652,7 +652,7 @@ public void clientCompressedStreaming(boolean probe) throws Exception {
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
Throwable e = responseObserver.getError();
assertNotNull("expected INVALID_ARGUMENT", e);
assertEquals(Status.INVALID_ARGUMENT.getCode(), Status.fromThrowable(e).getCode());
assertCodeEquals(Status.Code.INVALID_ARGUMENT, Status.fromThrowable(e));
}

// Start a new stream
Expand Down Expand Up @@ -801,8 +801,7 @@ public void cancelAfterBegin() throws Exception {
requestObserver.onError(new RuntimeException());
responseObserver.awaitCompletion();
assertEquals(Arrays.<StreamingInputCallResponse>asList(), responseObserver.getValues());
assertEquals(Status.Code.CANCELLED,
Status.fromThrowable(responseObserver.getError()).getCode());
assertCodeEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()));

if (metricsExpected()) {
MetricsRecord clientStartRecord = clientStatsRecorder.pollRecord(5, TimeUnit.SECONDS);
Expand Down Expand Up @@ -839,8 +838,7 @@ public void cancelAfterFirstResponse() throws Exception {
requestObserver.onError(new RuntimeException());
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
assertEquals(1, responseObserver.getValues().size());
assertEquals(Status.Code.CANCELLED,
Status.fromThrowable(responseObserver.getError()).getCode());
assertCodeEquals(Status.Code.CANCELLED, Status.fromThrowable(responseObserver.getError()));

assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.CANCELLED);
}
Expand Down Expand Up @@ -1107,7 +1105,7 @@ public void deadlineExceeded() throws Exception {
stub.streamingOutputCall(request).next();
fail("Expected deadline to be exceeded");
} catch (StatusRuntimeException ex) {
assertEquals(Status.DEADLINE_EXCEEDED.getCode(), ex.getStatus().getCode());
assertCodeEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus());
String desc = ex.getStatus().getDescription();
assertTrue(desc,
// There is a race between client and server-side deadline expiration.
Expand Down Expand Up @@ -1153,8 +1151,7 @@ public void deadlineExceededServerStreaming() throws Exception {
.withDeadlineAfter(30, TimeUnit.MILLISECONDS)
.streamingOutputCall(request, recorder);
recorder.awaitCompletion();
assertEquals(Status.DEADLINE_EXCEEDED.getCode(),
Status.fromThrowable(recorder.getError()).getCode());
assertCodeEquals(Status.Code.DEADLINE_EXCEEDED, Status.fromThrowable(recorder.getError()));
if (metricsExpected()) {
// Stream may not have been created when deadline is exceeded, thus we don't check tracer
// stats.
Expand All @@ -1179,7 +1176,7 @@ public void deadlineInPast() throws Exception {
.emptyCall(Empty.getDefaultInstance());
fail("Should have thrown");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
assertCodeEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus());
assertThat(ex.getStatus().getDescription())
.startsWith("ClientCall started after CallOptions deadline was exceeded");
}
Expand Down Expand Up @@ -1212,7 +1209,7 @@ public void deadlineInPast() throws Exception {
.emptyCall(Empty.getDefaultInstance());
fail("Should have thrown");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus().getCode());
assertCodeEquals(Status.Code.DEADLINE_EXCEEDED, ex.getStatus());
assertThat(ex.getStatus().getDescription())
.startsWith("ClientCall started after CallOptions deadline was exceeded");
}
Expand Down Expand Up @@ -1278,8 +1275,7 @@ public void maxInboundSize_tooBig() {
stub.streamingOutputCall(request).next();
fail();
} catch (StatusRuntimeException ex) {
Status s = ex.getStatus();
assertWithMessage(s.toString()).that(s.getCode()).isEqualTo(Status.Code.RESOURCE_EXHAUSTED);
assertCodeEquals(Status.Code.RESOURCE_EXHAUSTED, ex.getStatus());
assertThat(Throwables.getStackTraceAsString(ex)).contains("exceeds maximum");
}
}
Expand Down Expand Up @@ -1334,8 +1330,7 @@ public void maxOutboundSize_tooBig() {
stub.streamingOutputCall(request).next();
fail();
} catch (StatusRuntimeException ex) {
Status s = ex.getStatus();
assertWithMessage(s.toString()).that(s.getCode()).isEqualTo(Status.Code.CANCELLED);
assertCodeEquals(Status.Code.CANCELLED, ex.getStatus());
assertThat(Throwables.getStackTraceAsString(ex)).contains("message too large");
}
}
Expand Down Expand Up @@ -1557,7 +1552,7 @@ public void statusCodeAndMessage() throws Exception {
blockingStub.unaryCall(simpleRequest);
fail();
} catch (StatusRuntimeException e) {
assertEquals(Status.UNKNOWN.getCode(), e.getStatus().getCode());
assertCodeEquals(Status.Code.UNKNOWN, e.getStatus());
assertEquals(errorMessage, e.getStatus().getDescription());
}
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
Expand All @@ -1573,7 +1568,7 @@ public void statusCodeAndMessage() throws Exception {
.isTrue();
assertThat(responseObserver.getError()).isNotNull();
Status status = Status.fromThrowable(responseObserver.getError());
assertEquals(Status.UNKNOWN.getCode(), status.getCode());
assertCodeEquals(Status.Code.UNKNOWN, status);
assertEquals(errorMessage, status.getDescription());
assertStatsTrace("grpc.testing.TestService/FullDuplexCall", Status.Code.UNKNOWN);
}
Expand All @@ -1593,7 +1588,7 @@ public void specialStatusMessage() throws Exception {
blockingStub.unaryCall(simpleRequest);
fail();
} catch (StatusRuntimeException e) {
assertEquals(Status.UNKNOWN.getCode(), e.getStatus().getCode());
assertCodeEquals(Status.Code.UNKNOWN, e.getStatus());
assertEquals(errorMessage, e.getStatus().getDescription());
}
assertStatsTrace("grpc.testing.TestService/UnaryCall", Status.Code.UNKNOWN);
Expand All @@ -1606,7 +1601,7 @@ public void unimplementedMethod() {
blockingStub.unimplementedCall(Empty.getDefaultInstance());
fail();
} catch (StatusRuntimeException e) {
assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode());
assertCodeEquals(Status.Code.UNIMPLEMENTED, e.getStatus());
}

assertClientStatsTrace("grpc.testing.TestService/UnimplementedCall",
Expand All @@ -1622,7 +1617,7 @@ public void unimplementedService() {
stub.unimplementedCall(Empty.getDefaultInstance());
fail();
} catch (StatusRuntimeException e) {
assertEquals(Status.UNIMPLEMENTED.getCode(), e.getStatus().getCode());
assertCodeEquals(Status.Code.UNIMPLEMENTED, e.getStatus());
}

assertStatsTrace("grpc.testing.UnimplementedService/UnimplementedCall",
Expand Down Expand Up @@ -1652,8 +1647,8 @@ public void timeoutOnSleepingServer() throws Exception {

assertTrue(responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS));
assertEquals(0, responseObserver.getValues().size());
assertEquals(Status.DEADLINE_EXCEEDED.getCode(),
Status.fromThrowable(responseObserver.getError()).getCode());
assertCodeEquals(
Status.Code.DEADLINE_EXCEEDED, Status.fromThrowable(responseObserver.getError()));

if (metricsExpected()) {
// CensusStreamTracerModule record final status in the interceptor, thus is guaranteed to be
Expand Down Expand Up @@ -2035,6 +2030,10 @@ private void assertPayload(Payload expected, Payload actual) {
}
}

private static void assertCodeEquals(Status.Code expected, Status actual) {
assertWithMessage("Unexpected status: %s", actual).that(actual.getCode()).isEqualTo(expected);
}

/**
* Captures the request attributes. Useful for testing ServerCalls.
* {@link ServerCall#getAttributes()}
Expand Down