下面列出了怎么用io.grpc.testing.GrpcCleanupRule的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
@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);
}