【发布时间】:2020-04-21 05:31:09
【问题描述】:
我正在尝试使用存根调用 grpc 服务(原型存在于不同的 jar 文件中)。但是,当我尝试调用该服务时,我得到是由 io.grpc.statusruntimeexception 未找到未实现的方法引起的。在主类中也可以正常工作,但在测试用例中却不行。
DeviceGroupServiceImplBase deviceService = Mockito.mock(DeviceGroupServiceImplBase.class, AdditionalAnswers.delegatesTo(new DeviceGroupServiceImplBase() { }));
public void createInProcessServerAndChannel() throws IOException {
// Generate a unique in-process server name.
String serverName = InProcessServerBuilder.generateName();
// Create a server, add service, start, and register for automatic graceful
// shutdown.
grpcCleanup.register(
InProcessServerBuilder.forName(serverName).directExecutor().addService(deviceService).build().start());
// Create a client channel and register for automatic graceful shutdown.
ManagedChannel channel = grpcCleanup
.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
// Create a DeviceGroupServiceClient using the in-process channel;
groupStub = DeviceGroupServiceGrpc.newBlockingStub(channel);
}
// Test case code
When("user calls getDevice with valid deviceUUID {string}", (String deviceUUID) -> {
DeviceUuid request = DeviceUuid.newBuilder().setDeviceUuid(deviceUUID).build();
DeviceGroup groupData = groupStub.getDeviceGroupByDeviceUuid(request);
});
【问题讨论】:
标签: spring-boot junit grpc-java cucumber-junit