本文整理匯總了Java中io.grpc.StatusRuntimeException.getStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusRuntimeException.getStatus方法的具體用法?Java StatusRuntimeException.getStatus怎麽用?Java StatusRuntimeException.getStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.grpc.StatusRuntimeException
的用法示例。
在下文中一共展示了StatusRuntimeException.getStatus方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCascadingCancellationViaLeafFailure
import io.grpc.StatusRuntimeException; //導入方法依賴的package包/類
/**
* Test that when RPC cancellation propagates up a call chain, the cancellation of the parent
* RPC triggers cancellation of all of its children.
*/
@Test
public void testCascadingCancellationViaLeafFailure() throws Exception {
// All nodes (15) except one edge of the tree (4) will be cancelled.
observedCancellations = new CountDownLatch(11);
receivedCancellations = new CountDownLatch(11);
startCallTreeServer(3);
try {
// Use response size limit to control tree nodeCount.
blockingStub.unaryCall(Messages.SimpleRequest.newBuilder().setResponseSize(3).build());
fail("Expected abort");
} catch (StatusRuntimeException sre) {
// Wait for the workers to finish
Status status = sre.getStatus();
// Outermost caller observes ABORTED propagating up from the failing leaf,
// The descendant RPCs are cancelled so they receive CANCELLED.
assertEquals(Status.Code.ABORTED, status.getCode());
if (!observedCancellations.await(5, TimeUnit.SECONDS)) {
fail("Expected number of cancellations not observed by clients");
}
if (!receivedCancellations.await(5, TimeUnit.SECONDS)) {
fail("Expected number of cancellations to be received by servers not observed");
}
}
}
示例2: doDummyMessage
import io.grpc.StatusRuntimeException; //導入方法依賴的package包/類
private void doDummyMessage(ManagedChannel channel) throws IOException {
DummyServiceGrpc.DummyServiceBlockingStub dummyStub = DummyServiceGrpc
.newBlockingStub(channel)
.withDeadlineAfter(CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
try {
dummyStub.sayHello(Dummy.DummyMessageThatNoOneWouldReallyUse
.getDefaultInstance());
} catch (StatusRuntimeException e) {
if (e.getStatus() != Status.UNIMPLEMENTED) {
// UNIMPLEMENTED means that the server received our message but
// doesn't know how to handle it. Hence, channel is open.
throw new IOException(e);
}
}
}
示例3: maxInboundSize_tooBig
import io.grpc.StatusRuntimeException; //導入方法依賴的package包/類
@Test
public void maxInboundSize_tooBig() {
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.addResponseParameters(ResponseParameters.newBuilder().setSize(1))
.build();
MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
TestServiceGrpc.getStreamingOutputCallMethod();
ByteSizeMarshaller<StreamingOutputCallRequest> mar =
new ByteSizeMarshaller<StreamingOutputCallRequest>(md.getRequestMarshaller());
blockingServerStreamingCall(
blockingStub.getChannel(),
md.toBuilder(mar, md.getResponseMarshaller()).build(),
blockingStub.getCallOptions(),
request)
.next();
int size = mar.lastOutSize;
TestServiceGrpc.TestServiceBlockingStub stub =
blockingStub.withMaxInboundMessageSize(size - 1);
try {
stub.streamingOutputCall(request).next();
fail();
} catch (StatusRuntimeException ex) {
Status s = ex.getStatus();
assertThat(s.getCode()).named(s.toString()).isEqualTo(Status.Code.RESOURCE_EXHAUSTED);
assertThat(Throwables.getStackTraceAsString(ex)).contains("exceeds maximum");
}
}
示例4: maxOutboundSize_tooBig
import io.grpc.StatusRuntimeException; //導入方法依賴的package包/類
@Test
public void maxOutboundSize_tooBig() {
// set at least one field to ensure the size is non-zero.
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.addResponseParameters(ResponseParameters.newBuilder().setSize(1))
.build();
MethodDescriptor<StreamingOutputCallRequest, StreamingOutputCallResponse> md =
TestServiceGrpc.getStreamingOutputCallMethod();
ByteSizeMarshaller<StreamingOutputCallRequest> mar =
new ByteSizeMarshaller<StreamingOutputCallRequest>(md.getRequestMarshaller());
blockingServerStreamingCall(
blockingStub.getChannel(),
md.toBuilder(mar, md.getResponseMarshaller()).build(),
blockingStub.getCallOptions(),
request)
.next();
TestServiceGrpc.TestServiceBlockingStub stub =
blockingStub.withMaxOutboundMessageSize(mar.lastOutSize - 1);
try {
stub.streamingOutputCall(request).next();
fail();
} catch (StatusRuntimeException ex) {
Status s = ex.getStatus();
assertThat(s.getCode()).named(s.toString()).isEqualTo(Status.Code.CANCELLED);
assertThat(Throwables.getStackTraceAsString(ex)).contains("message too large");
}
}