當前位置: 首頁>>代碼示例>>Java>>正文


Java StatusRuntimeException.getStatus方法代碼示例

本文整理匯總了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");
    }
  }
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:30,代碼來源:CascadingTest.java

示例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);
        }
    }
}
 
開發者ID:opennetworkinglab,項目名稱:onos,代碼行數:16,代碼來源:GrpcControllerImpl.java

示例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");
  }
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:32,代碼來源:AbstractInteropTest.java

示例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");
  }
}
 
開發者ID:grpc,項目名稱:grpc-java,代碼行數:31,代碼來源:AbstractInteropTest.java


注:本文中的io.grpc.StatusRuntimeException.getStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。