类io.grpc.testing.GrpcCleanupRule源码实例Demo

下面列出了怎么用io.grpc.testing.GrpcCleanupRule的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: gcp-token-broker   文件: TestingTools.java
/**
 * Starts a live instance of a mock implementation of the broker server.
 */
static void startServer(FakeBrokerImpl fakeServer, GrpcCleanupRule grpcCleanup) {
    String serverName = InProcessServerBuilder.generateName();
    try {
        grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor()
            .addService(ServerInterceptors.intercept(fakeServer, new AuthorizationHeaderServerInterceptor()))
            .build().start());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ManagedChannel channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
    BrokerGrpc.BrokerBlockingStub stub = BrokerGrpc.newBlockingStub(channel);

    mockStatic(GrpcUtils.class);
    when(GrpcUtils.newManagedChannel(BROKER_HOST, 1234, false, null)).thenReturn(channel);
    when(GrpcUtils.newStub(channel)).thenReturn(stub);
}
 
源代码2 项目: feast   文件: FeastClientTest.java
@Before
public void setup() throws Exception {
  this.grpcRule = new GrpcCleanupRule();
  // setup fake serving service
  String serverName = InProcessServerBuilder.generateName();
  this.grpcRule.register(
      InProcessServerBuilder.forName(serverName)
          .directExecutor()
          .addService(this.servingMock)
          .build()
          .start());

  // setup test feast client target
  ManagedChannel channel =
      this.grpcRule.register(
          InProcessChannelBuilder.forName(serverName).directExecutor().build());
  this.client = new FeastClient(channel);
}
 
 类所在包
 同包方法